1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# frozen_string_literal: true
RSpec.shared_examples 'does not exceed the issuable size limit' do
let(:user1) { create(:user) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
before do
project.add_maintainer(user)
project.add_maintainer(user1)
project.add_maintainer(user2)
project.add_maintainer(user3)
end
context "when the number of users of issuable does exceed the limit" do
before do
stub_const("Issuable::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS", 2)
end
it 'will not add more than the allowed number of users' do
allow_next_instance_of(update_service) do |service|
expect(service).not_to receive(:execute)
end
note = described_class.new(project, user, opts.merge(
note: note_text,
noteable_type: noteable_type,
noteable_id: issuable.id,
confidential: false
)).execute
expect(note.errors[:validation]).to match_array([validation_message])
end
end
context "when the number of users does not exceed the limit" do
before do
stub_const("Issuable::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS", 6)
end
it 'calls execute and does not return an error' do
allow_next_instance_of(update_service) do |service|
expect(service).to receive(:execute).and_call_original
end
note = described_class.new(project, user, opts.merge(
note: note_text,
noteable_type: noteable_type,
noteable_id: issuable.id,
confidential: false
)).execute
expect(note.errors[:validation]).to be_empty
end
end
end
RSpec.shared_examples 'does not exceed the issuable size limit with ff off' do
let(:user1) { create(:user) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
before do
project.add_maintainer(user)
project.add_maintainer(user1)
project.add_maintainer(user2)
project.add_maintainer(user3)
end
context 'when feature flag is off' do
before do
stub_feature_flags(feature_flag_hash)
end
context "when the number of users of issuable does exceed the limit" do
before do
stub_const("Issuable::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS", 2)
end
it 'will not add more than the allowed number of users' do
allow_next_instance_of(MergeRequests::UpdateService) do |service|
expect(service).to receive(:execute).and_call_original
end
note = described_class.new(project, user, opts.merge(
note: note_text,
noteable_type: 'MergeRequest',
noteable_id: issuable.id,
confidential: false
)).execute
expect(note.errors[:validation]).to be_empty
end
end
end
end
|