diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 03:09:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 03:09:12 +0300 |
commit | d43aaf286fe6b8e8383e73ea580274d8841608d7 (patch) | |
tree | ca03542a55583538a1ec13023dffed20457407b5 /spec/models/note_spec.rb | |
parent | 87af6f2e0590af0ed1bb3e5de1bb5d21855a94d2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r-- | spec/models/note_spec.rb | 99 |
1 files changed, 90 insertions, 9 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 4da23c79944..74ec74e0def 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -270,18 +270,35 @@ describe Note do end end - describe "confidential?" do - it "delegates to noteable" do - issue_note = build(:note, :on_issue) - confidential_note = build(:note, noteable: create(:issue, confidential: true)) + describe '#confidential?' do + context 'when note is not confidential' do + it 'is true when a noteable is confidential' do + issue = create(:issue, :confidential) + note = build(:note, noteable: issue, project: issue.project) - expect(issue_note.confidential?).to be_falsy - expect(confidential_note.confidential?).to be_truthy + expect(note.confidential?).to be_truthy + end + + it 'is false when a noteable is not confidential' do + issue = create(:issue, confidential: false) + note = build(:note, noteable: issue, project: issue.project) + + expect(note.confidential?).to be_falsy + end + + it "is falsey when noteable can't be confidential" do + commit_note = build(:note_on_commit) + + expect(commit_note.confidential?).to be_falsy + end end + context 'when note is confidential' do + it 'is true even when a noteable is not confidential' do + issue = create(:issue, confidential: false) + note = build(:note, :confidential, noteable: issue, project: issue.project) - it "is falsey when noteable can't be confidential" do - commit_note = build(:note_on_commit) - expect(commit_note.confidential?).to be_falsy + expect(note.confidential?).to be_truthy + end end end @@ -1230,5 +1247,69 @@ describe Note do expect(notes.second.id).to eq(note2.id) end end + + describe '#noteable_assignee_or_author' do + let(:user) { create(:user) } + let(:noteable) { create(:issue) } + let(:note) { create(:note, project: noteable.project, noteable: noteable) } + + subject { note.noteable_assignee_or_author?(user) } + + shared_examples 'assignee check' do + context 'when the provided user is one of the assignees' do + before do + note.noteable.update(assignees: [user, create(:user)]) + end + + it 'returns true' do + expect(subject).to be_truthy + end + end + end + + shared_examples 'author check' do + context 'when the provided user is the author' do + before do + note.noteable.update(author: user) + end + + it 'returns true' do + expect(subject).to be_truthy + end + end + + context 'when the provided user is neither author nor assignee' do + it 'returns true' do + expect(subject).to be_falsey + end + end + end + + context 'when user is nil' do + let(:user) { nil } + + it 'returns false' do + expect(subject).to be_falsey + end + end + + context 'when noteable is an issue' do + it_behaves_like 'author check' + it_behaves_like 'assignee check' + end + + context 'when noteable is a merge request' do + let(:noteable) { create(:merge_request) } + + it_behaves_like 'author check' + it_behaves_like 'assignee check' + end + + context 'when noteable is a snippet' do + let(:noteable) { create(:personal_snippet) } + + it_behaves_like 'author check' + end + end end end |