| ... | ... | @@ -285,6 +285,70 @@ describe Note do |
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#visible_for?" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let_it_be(:note) { create(:note) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
where(:cross_reference_visible, :system_note_viewable, :result) do
|
|
|
|
true | true | false
|
|
|
|
false | true | true
|
|
|
|
false | false | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it "returns expected result" do
|
|
|
|
expect(note).to receive(:cross_reference_not_visible_for?).and_return(cross_reference_visible)
|
|
|
|
|
|
|
|
unless cross_reference_visible
|
|
|
|
expect(note).to receive(:system_note_viewable_by?)
|
|
|
|
.with(user).and_return(system_note_viewable)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(note.visible_for?(user)).to eq result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#system_note_viewable_by?(user)" do
|
|
|
|
let_it_be(:note) { create(:note) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let!(:metadata) { create(:system_note_metadata, note: note, action: "branch") }
|
|
|
|
|
|
|
|
context "when system_note_metadata is not present" do
|
|
|
|
it "returns true" do
|
|
|
|
expect(note).to receive(:system_note_metadata).and_return(nil)
|
|
|
|
|
|
|
|
expect(note.send(:system_note_viewable_by?, user)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "system_note_metadata isn't of type 'branch'" do
|
|
|
|
before do
|
|
|
|
metadata.action = "not_a_branch"
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
describe "cross_reference_not_visible_for?" do
|
|
|
|
let(:private_user) { create(:user) }
|
|
|
|
let(:private_project) { create(:project, namespace: private_user.namespace) { |p| p.add_maintainer(private_user) } }
|
| ... | ... | |
| ... | ... | |