Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/concerns/participable_spec.rb')
-rw-r--r--spec/models/concerns/participable_spec.rb26
1 files changed, 24 insertions, 2 deletions
diff --git a/spec/models/concerns/participable_spec.rb b/spec/models/concerns/participable_spec.rb
index b92c7c52f0b..f7f68cb38d8 100644
--- a/spec/models/concerns/participable_spec.rb
+++ b/spec/models/concerns/participable_spec.rb
@@ -124,6 +124,7 @@ RSpec.describe Participable do
end
let(:readable) { true }
+ let(:project) { build(:project, :public) }
it 'returns the list of participants' do
model.participant(:foo)
@@ -132,7 +133,6 @@ RSpec.describe Participable do
user1 = build(:user)
user2 = build(:user)
user3 = build(:user)
- project = build(:project, :public)
instance = model.new
allow(instance).to receive_message_chain(:model_name, :element) { 'class' }
@@ -155,7 +155,6 @@ RSpec.describe Participable do
instance = model.new
user1 = build(:user)
user2 = build(:user)
- project = build(:project, :public)
allow(instance).to receive_message_chain(:model_name, :element) { 'class' }
allow(instance).to receive(:bar).and_return(user2)
@@ -164,6 +163,29 @@ RSpec.describe Participable do
expect(instance.visible_participants(user1)).to be_empty
end
end
+
+ context 'with multiple system notes from the same author and mentioned_users' do
+ let!(:user1) { create(:user) }
+ let!(:user2) { create(:user) }
+
+ it 'skips expensive checks if the author is aleady in participants list' do
+ model.participant(:notes)
+
+ instance = model.new
+ note1 = create(:system_note, author: user1)
+ note2 = create(:system_note, author: user1) # only skip system notes with no mentioned users
+ note3 = create(:system_note, author: user1, note: "assigned to #{user2.to_reference}")
+ note4 = create(:note, author: user2)
+
+ allow(instance).to receive(:project).and_return(project)
+ allow(instance).to receive_message_chain(:model_name, :element) { 'class' }
+ allow(instance).to receive(:notes).and_return([note1, note2, note3, note4])
+
+ allow(Ability).to receive(:allowed?).with(anything, :read_project, anything).and_return(true)
+ allow(Ability).to receive(:allowed?).with(anything, :read_note, anything).exactly(3).times.and_return(true)
+ expect(instance.visible_participants(user1)).to match_array [user1, user2]
+ end
+ end
end
describe '#participant?' do