diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/models/note_spec.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-3cc9186904540cc13152bba687400d46ea51d15d.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r-- | spec/models/note_spec.rb | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 9d9cca0678a..34ce0031bd2 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -445,7 +445,7 @@ RSpec.describe Note do end end - describe "#system_note_with_references_visible_for?" do + describe "#system_note_visible_for?" do let(:project) { create(:project, :public) } let(:user) { create(:user) } let(:guest) { create(:project_member, :guest, project: project, user: create(:user)).user } @@ -469,22 +469,25 @@ RSpec.describe Note do end it 'returns visible but not readable for non-member user' do - expect(note.system_note_with_references_visible_for?(non_member)).to be_truthy + expect(note.system_note_visible_for?(non_member)).to be_truthy expect(note.readable_by?(non_member)).to be_falsy end it 'returns visible but not readable for a nil user' do - expect(note.system_note_with_references_visible_for?(nil)).to be_truthy + expect(note.system_note_visible_for?(nil)).to be_truthy expect(note.readable_by?(nil)).to be_falsy end end end describe "#system_note_viewable_by?(user)" do - let_it_be(:note) { create(:note) } + let_it_be(:group) { create(:group, :private) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:note) { create(:note, project: project) } let_it_be(:user) { create(:user) } - let!(:metadata) { create(:system_note_metadata, note: note, action: "branch") } + let(:action) { "commit" } + let!(:metadata) { create(:system_note_metadata, note: note, action: action) } context "when system_note_metadata is not present" do it "returns true" do @@ -494,32 +497,50 @@ RSpec.describe Note do end end - context "system_note_metadata isn't of type 'branch'" do - before do - metadata.action = "not_a_branch" - end - + context "system_note_metadata isn't of type 'branch' or 'contact'" do it "returns true" do expect(note.send(:system_note_viewable_by?, user)).to be_truthy end end - context "user doesn't have :download_code ability" do - it "returns false" do - expect(note.send(:system_note_viewable_by?, user)).to be_falsey + context "system_note_metadata is of type 'branch'" do + let(:action) { "branch" } + + context "user doesn't have :download_code ability" do + it "returns false" do + expect(note.send(:system_note_viewable_by?, user)).to be_falsey + end + end + + context "user has the :download_code ability" do + it "returns true" do + expect(Ability).to receive(:allowed?).with(user, :download_code, note.project).and_return(true) + + expect(note.send(:system_note_viewable_by?, user)).to be_truthy + end end end - context "user has the :download_code ability" do - it "returns true" do - expect(Ability).to receive(:allowed?).with(user, :download_code, note.project).and_return(true) + context "system_note_metadata is of type 'contact'" do + let(:action) { "contact" } - expect(note.send(:system_note_viewable_by?, user)).to be_truthy + context "user doesn't have :read_crm_contact ability" do + it "returns false" do + expect(note.send(:system_note_viewable_by?, user)).to be_falsey + end + end + + context "user has the :read_crm_contact ability" do + it "returns true" do + expect(Ability).to receive(:allowed?).with(user, :read_crm_contact, note.project.group).and_return(true) + + expect(note.send(:system_note_viewable_by?, user)).to be_truthy + end end end end - describe "system_note_with_references_visible_for?" do + describe "system_note_visible_for?" do let_it_be(:private_user) { create(:user) } let_it_be(:private_project) { create(:project, namespace: private_user.namespace) { |p| p.add_maintainer(private_user) } } let_it_be(:private_issue) { create(:issue, project: private_project) } @@ -529,11 +550,11 @@ RSpec.describe Note do shared_examples "checks references" do it "returns false" do - expect(note.system_note_with_references_visible_for?(ext_issue.author)).to be_falsy + expect(note.system_note_visible_for?(ext_issue.author)).to be_falsy end it "returns true" do - expect(note.system_note_with_references_visible_for?(private_user)).to be_truthy + expect(note.system_note_visible_for?(private_user)).to be_truthy end it "returns true if user visible reference count set" do @@ -541,7 +562,7 @@ RSpec.describe Note do note.total_reference_count = 1 expect(note).not_to receive(:reference_mentionables) - expect(note.system_note_with_references_visible_for?(ext_issue.author)).to be_truthy + expect(note.system_note_visible_for?(ext_issue.author)).to be_truthy end it "returns false if user visible reference count set but does not match total reference count" do @@ -549,14 +570,14 @@ RSpec.describe Note do note.total_reference_count = 2 expect(note).not_to receive(:reference_mentionables) - expect(note.system_note_with_references_visible_for?(ext_issue.author)).to be_falsy + expect(note.system_note_visible_for?(ext_issue.author)).to be_falsy end it "returns false if ref count is 0" do note.user_visible_reference_count = 0 expect(note).not_to receive(:reference_mentionables) - expect(note.system_note_with_references_visible_for?(ext_issue.author)).to be_falsy + expect(note.system_note_visible_for?(ext_issue.author)).to be_falsy end end @@ -617,16 +638,16 @@ RSpec.describe Note do let(:note) do create :note, noteable: ext_issue, project: ext_proj, - note: "mentioned in #{ext_proj.owner.to_reference}", + note: "mentioned in #{ext_proj.first_owner.to_reference}", system: true end it "returns true for other users" do - expect(note.system_note_with_references_visible_for?(ext_issue.author)).to be_truthy + expect(note.system_note_visible_for?(ext_issue.author)).to be_truthy end it "returns true for anonymous users" do - expect(note.system_note_with_references_visible_for?(nil)).to be_truthy + expect(note.system_note_visible_for?(nil)).to be_truthy end end end |