diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/models/note_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r-- | spec/models/note_spec.rb | 100 |
1 files changed, 77 insertions, 23 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 7edd7849bbe..a3417ee5fc7 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -67,7 +67,7 @@ RSpec.describe Note do end context 'when noteable is a personal snippet' do - subject { build(:note_on_personal_snippet) } + subject { build(:note_on_personal_snippet, noteable: create(:personal_snippet)) } it 'is valid without project' do is_expected.to be_valid @@ -109,7 +109,8 @@ RSpec.describe Note do describe 'callbacks' do describe '#notify_after_create' do it 'calls #after_note_created on the noteable' do - note = build(:note) + noteable = create(:issue) + note = build(:note, project: noteable.project, noteable: noteable) expect(note).to receive(:notify_after_create).and_call_original expect(note.noteable).to receive(:after_note_created).with(note) @@ -285,6 +286,56 @@ RSpec.describe Note do end end + describe "noteable_author?" do + let(:user1) { create(:user) } + let(:user2) { create(:user) } + let(:project) { create(:project, :public, :repository) } + + context 'when note is on commit' do + let(:noteable) { create(:commit, project: project, author: user1) } + + context 'if user is the noteable author' do + let(:note) { create(:discussion_note_on_commit, commit_id: noteable.id, project: project, author: user1) } + let(:diff_note) { create(:diff_note_on_commit, commit_id: noteable.id, project: project, author: user1) } + + it 'returns true' do + expect(note.noteable_author?(noteable)).to be true + expect(diff_note.noteable_author?(noteable)).to be true + end + end + + context 'if user is not the noteable author' do + let(:note) { create(:discussion_note_on_commit, commit_id: noteable.id, project: project, author: user2) } + let(:diff_note) { create(:diff_note_on_commit, commit_id: noteable.id, project: project, author: user2) } + + it 'returns false' do + expect(note.noteable_author?(noteable)).to be false + expect(diff_note.noteable_author?(noteable)).to be false + end + end + end + + context 'when note is on issue' do + let(:noteable) { create(:issue, project: project, author: user1) } + + context 'if user is the noteable author' do + let(:note) { create(:note, noteable: noteable, author: user1, project: project) } + + it 'returns true' do + expect(note.noteable_author?(noteable)).to be true + end + end + + context 'if user is not the noteable author' do + let(:note) { create(:note, noteable: noteable, author: user2, project: project) } + + it 'returns false' do + expect(note.noteable_author?(noteable)).to be false + end + end + end + end + describe "edited?" do let(:note) { build(:note, updated_by_id: nil, created_at: Time.current, updated_at: Time.current + 5.hours) } @@ -840,7 +891,8 @@ RSpec.describe Note do let(:html) { '<p>some html</p>'} context 'note for a project snippet' do - let(:note) { build(:note_on_project_snippet) } + let(:snippet) { create(:project_snippet) } + let(:note) { build(:note_on_project_snippet, project: snippet.project, noteable: snippet) } before do expect(Banzai::Renderer).to receive(:cacheless_render_field) @@ -855,7 +907,8 @@ RSpec.describe Note do end context 'note for a personal snippet' do - let(:note) { build(:note_on_personal_snippet) } + let(:snippet) { create(:personal_snippet) } + let(:note) { build(:note_on_personal_snippet, noteable: snippet) } before do expect(Banzai::Renderer).to receive(:cacheless_render_field) @@ -889,7 +942,7 @@ RSpec.describe Note do context 'for a note on a commit' do it 'returns true' do - note = build(:note_on_commit) + note = build(:note_on_commit, project: create(:project, :repository)) expect(note.can_be_discussion_note?).to be_truthy end @@ -913,7 +966,7 @@ RSpec.describe Note do context 'for a diff note on commit' do it 'returns false' do - note = build(:diff_note_on_commit) + note = build(:diff_note_on_commit, project: create(:project, :repository)) expect(note.can_be_discussion_note?).to be_falsey end @@ -1143,7 +1196,8 @@ RSpec.describe Note do end describe 'expiring ETag cache' do - let(:note) { build(:note_on_issue) } + let_it_be(:issue) { create(:issue) } + let(:note) { build(:note, project: issue.project, noteable: issue) } def expect_expiration(noteable) expect_any_instance_of(Gitlab::EtagCaching::Store) @@ -1224,22 +1278,6 @@ RSpec.describe Note do end end - describe '#special_role=' do - let(:role) { Note::SpecialRole::FIRST_TIME_CONTRIBUTOR } - - it 'assigns role' do - subject.special_role = role - - expect(subject.special_role).to eq(role) - end - - it 'does not assign unknown role' do - expect { subject.special_role = :bogus }.to raise_error(/Role is undefined/) - - expect(subject.special_role).to be_nil - end - end - describe '#parent' do it 'returns project for project notes' do project = create(:project) @@ -1416,4 +1454,20 @@ RSpec.describe Note do expect(note.parent_user).to be_nil end end + + describe '#skip_notification?' do + subject(:skip_notification?) { note.skip_notification? } + + context 'when there is no review' do + let(:note) { build(:note) } + + it { is_expected.to be_falsey } + end + + context 'when the review exists' do + let(:note) { build(:note, :with_review) } + + it { is_expected.to be_truthy } + end + end end |