Commit e3a619f1 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch '211887-dedup-notes-specs' into 'master'

De-duplicate note model EE specs

Closes #211887

See merge request gitlab-org/gitlab!28216
parents 705a352d 9488990f
...@@ -217,7 +217,6 @@ Gitlab/DuplicateSpecLocation: ...@@ -217,7 +217,6 @@ Gitlab/DuplicateSpecLocation:
- ee/spec/helpers/auth_helper_spec.rb - ee/spec/helpers/auth_helper_spec.rb
- ee/spec/lib/gitlab/gl_repository_spec.rb - ee/spec/lib/gitlab/gl_repository_spec.rb
- ee/spec/models/namespace_spec.rb - ee/spec/models/namespace_spec.rb
- ee/spec/models/note_spec.rb
- ee/spec/serializers/environment_entity_spec.rb - ee/spec/serializers/environment_entity_spec.rb
- ee/spec/services/issues/create_service_spec.rb - ee/spec/services/issues/create_service_spec.rb
- ee/spec/services/merge_requests/create_service_spec.rb - ee/spec/services/merge_requests/create_service_spec.rb
...@@ -226,7 +225,6 @@ Gitlab/DuplicateSpecLocation: ...@@ -226,7 +225,6 @@ Gitlab/DuplicateSpecLocation:
- ee/spec/services/system_hooks_service_spec.rb - ee/spec/services/system_hooks_service_spec.rb
- ee/spec/helpers/ee/auth_helper_spec.rb - ee/spec/helpers/ee/auth_helper_spec.rb
- ee/spec/models/ee/namespace_spec.rb - ee/spec/models/ee/namespace_spec.rb
- ee/spec/models/ee/note_spec.rb
- ee/spec/serializers/ee/environment_entity_spec.rb - ee/spec/serializers/ee/environment_entity_spec.rb
- ee/spec/services/ee/issues/create_service_spec.rb - ee/spec/services/ee/issues/create_service_spec.rb
- ee/spec/services/ee/merge_requests/create_service_spec.rb - ee/spec/services/ee/merge_requests/create_service_spec.rb
......
# frozen_string_literal: true
require 'spec_helper'
describe Note do
include ::EE::GeoHelpers
describe 'associations' do
it { is_expected.to belong_to(:review).inverse_of(:notes) }
end
describe 'scopes' do
describe '.with_suggestions' do
it 'returns the correct note' do
note_with_suggestion = create(:note, suggestions: [create(:suggestion)])
note_without_suggestion = create(:note)
expect(described_class.with_suggestions).to include(note_with_suggestion)
expect(described_class.with_suggestions).not_to include(note_without_suggestion)
end
end
end
describe 'callbacks' do
describe '#notify_after_create' do
it 'calls #after_note_created on the noteable' do
note = build(:note)
expect(note).to receive(:notify_after_create).and_call_original
expect(note.noteable).to receive(:after_note_created).with(note)
note.save!
end
end
describe '#notify_after_destroy' do
it 'calls #after_note_destroyed on the noteable' do
note = create(:note)
expect(note).to receive(:notify_after_destroy).and_call_original
expect(note.noteable).to receive(:after_note_destroyed).with(note)
note.destroy
end
it 'does not error if noteable is nil' do
note = create(:note)
expect(note).to receive(:notify_after_destroy).and_call_original
expect(note).to receive(:noteable).at_least(:once).and_return(nil)
expect { note.destroy }.not_to raise_error
end
end
end
context 'object storage with background upload' do
before do
stub_uploads_object_storage(AttachmentUploader, background_upload: true)
end
context 'when running in a Geo primary node' do
let_it_be(:primary) { create(:geo_node, :primary) }
let_it_be(:secondary) { create(:geo_node) }
before do
stub_current_geo_node(primary)
end
it 'creates a Geo deleted log event for attachment' do
Sidekiq::Testing.inline! do
expect do
create(:note, :with_attachment)
end.to change(Geo::UploadDeletedEvent, :count).by(1)
end
end
end
end
describe '#resource_parent' do
it 'returns group for epic notes' do
group = create(:group)
note = create(:note_on_epic, noteable: create(:epic, group: group))
expect(note.resource_parent).to eq(group)
end
end
describe '#for_design' do
it 'is true when the noteable is a design' do
note = build(:note, noteable: build(:design))
expect(note).to be_for_design
end
end
describe '.by_humans' do
it 'excludes notes by bots and service users' do
user_note = create(:note)
create(:system_note)
create(:note, author: create(:user, :bot))
create(:note, author: create(:user, :service_user))
expect(described_class.by_humans).to match_array([user_note])
end
end
end
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
describe Note do describe Note do
include ::EE::GeoHelpers
it_behaves_like 'an editable mentionable with EE-specific mentions' do it_behaves_like 'an editable mentionable with EE-specific mentions' do
subject { create :note, noteable: issue, project: issue.project } subject { create :note, noteable: issue, project: issue.project }
...@@ -88,4 +90,103 @@ describe Note do ...@@ -88,4 +90,103 @@ describe Note do
end end
end end
end end
describe 'associations' do
it { is_expected.to belong_to(:review).inverse_of(:notes) }
end
describe 'scopes' do
describe '.with_suggestions' do
it 'returns the correct note' do
note_with_suggestion = create(:note, suggestions: [create(:suggestion)])
note_without_suggestion = create(:note)
expect(described_class.with_suggestions).to include(note_with_suggestion)
expect(described_class.with_suggestions).not_to include(note_without_suggestion)
end
end
end
describe 'callbacks' do
describe '#notify_after_create' do
it 'calls #after_note_created on the noteable' do
note = build(:note)
expect(note).to receive(:notify_after_create).and_call_original
expect(note.noteable).to receive(:after_note_created).with(note)
note.save!
end
end
describe '#notify_after_destroy' do
it 'calls #after_note_destroyed on the noteable' do
note = create(:note)
expect(note).to receive(:notify_after_destroy).and_call_original
expect(note.noteable).to receive(:after_note_destroyed).with(note)
note.destroy
end
it 'does not error if noteable is nil' do
note = create(:note)
expect(note).to receive(:notify_after_destroy).and_call_original
expect(note).to receive(:noteable).at_least(:once).and_return(nil)
expect { note.destroy }.not_to raise_error
end
end
end
context 'object storage with background upload' do
before do
stub_uploads_object_storage(AttachmentUploader, background_upload: true)
end
context 'when running in a Geo primary node' do
let_it_be(:primary) { create(:geo_node, :primary) }
let_it_be(:secondary) { create(:geo_node) }
before do
stub_current_geo_node(primary)
end
it 'creates a Geo deleted log event for attachment' do
Sidekiq::Testing.inline! do
expect do
create(:note, :with_attachment)
end.to change(Geo::UploadDeletedEvent, :count).by(1)
end
end
end
end
describe '#resource_parent' do
it 'returns group for epic notes' do
group = create(:group)
note = create(:note_on_epic, noteable: create(:epic, group: group))
expect(note.resource_parent).to eq(group)
end
end
describe '#for_design' do
it 'is true when the noteable is a design' do
note = build(:note, noteable: build(:design))
expect(note).to be_for_design
end
end
describe '.by_humans' do
it 'excludes notes by bots and service users' do
user_note = create(:note)
create(:system_note)
create(:note, author: create(:user, :bot))
create(:note, author: create(:user, :service_user))
expect(described_class.by_humans).to match_array([user_note])
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment