|
29 | 29 | require 'spec_helper' |
30 | 30 |
|
31 | 31 | describe Groups::UpdateRolesService, 'integration', type: :model do |
32 | | - subject(:service_call) { instance.call(member:, message:) } |
| 32 | + subject(:service_call) { instance.call(member:, message:, send_notifications:) } |
33 | 33 |
|
34 | 34 | let(:project) { create :project } |
35 | 35 | let(:role) { create :role } |
|
46 | 46 |
|
47 | 47 | ::Groups::CreateInheritedRolesService |
48 | 48 | .new(group, current_user: User.system, contract_class: EmptyContract) |
49 | | - .call(user_ids: users.map(&:id)) |
| 49 | + .call(user_ids: users.map(&:id), send_notifications: false) |
50 | 50 | end |
51 | 51 | end |
52 | 52 | let(:users) { create_list :user, 2 } |
53 | 53 | let(:member) { Member.find_by(principal: group) } |
54 | 54 | let(:message) { "Some message" } |
| 55 | + let(:send_notifications) { true } |
55 | 56 |
|
56 | 57 | let(:instance) do |
57 | 58 | described_class.new(group, current_user:) |
|
89 | 90 | end |
90 | 91 | end |
91 | 92 |
|
| 93 | + shared_examples_for 'sends no notification' do |
| 94 | + it 'on the updated membership' do |
| 95 | + service_call |
| 96 | + |
| 97 | + expect(Notifications::GroupMemberAlteredJob) |
| 98 | + .not_to have_received(:perform_later) |
| 99 | + end |
| 100 | + end |
| 101 | + |
92 | 102 | context 'when adding a role' do |
93 | 103 | let(:added_role) { create(:role) } |
94 | 104 |
|
|
113 | 123 | it_behaves_like 'sends notification' do |
114 | 124 | let(:user) { users } |
115 | 125 | end |
| 126 | + |
| 127 | + context 'when notifications are suppressed' do |
| 128 | + let(:send_notifications) { false } |
| 129 | + |
| 130 | + it_behaves_like 'sends no notification' |
| 131 | + end |
116 | 132 | end |
117 | 133 |
|
118 | 134 | context 'with global membership' do |
|
154 | 170 | it_behaves_like 'sends notification' do |
155 | 171 | let(:user) { users } |
156 | 172 | end |
| 173 | + |
| 174 | + context 'when notifications are suppressed' do |
| 175 | + let(:send_notifications) { false } |
| 176 | + |
| 177 | + it_behaves_like 'sends no notification' |
| 178 | + end |
157 | 179 | end |
158 | 180 |
|
159 | 181 | context 'when removing a global role' do |
|
180 | 202 | it_behaves_like 'sends notification' do |
181 | 203 | let(:user) { users } |
182 | 204 | end |
| 205 | + |
| 206 | + context 'when notifications are suppressed' do |
| 207 | + let(:send_notifications) { false } |
| 208 | + |
| 209 | + it_behaves_like 'sends no notification' |
| 210 | + end |
183 | 211 | end |
184 | 212 | end |
185 | 213 |
|
|
222 | 250 | it_behaves_like 'sends notification' do |
223 | 251 | let(:user) { users.last } |
224 | 252 | end |
| 253 | + |
| 254 | + context 'when notifications are suppressed' do |
| 255 | + let(:send_notifications) { false } |
| 256 | + |
| 257 | + it_behaves_like 'sends no notification' |
| 258 | + end |
225 | 259 | end |
226 | 260 |
|
227 | 261 | context 'when removing a role' do |
|
248 | 282 | it_behaves_like 'sends notification' do |
249 | 283 | let(:user) { users } |
250 | 284 | end |
| 285 | + |
| 286 | + context 'when notifications are suppressed' do |
| 287 | + let(:send_notifications) { false } |
| 288 | + |
| 289 | + it_behaves_like 'sends no notification' |
| 290 | + end |
251 | 291 | end |
252 | 292 |
|
253 | 293 | context 'when removing a role but with a user having had the role before (no inherited_from)' do |
|
290 | 330 | it_behaves_like 'sends notification' do |
291 | 331 | let(:user) { users.last } |
292 | 332 | end |
| 333 | + |
| 334 | + context 'when notifications are suppressed' do |
| 335 | + let(:send_notifications) { false } |
| 336 | + |
| 337 | + it_behaves_like 'sends no notification' |
| 338 | + end |
293 | 339 | end |
294 | 340 |
|
295 | 341 | context 'when replacing roles' do |
|
316 | 362 | it_behaves_like 'sends notification' do |
317 | 363 | let(:user) { users } |
318 | 364 | end |
| 365 | + |
| 366 | + context 'when notifications are suppressed' do |
| 367 | + let(:send_notifications) { false } |
| 368 | + |
| 369 | + it_behaves_like 'sends no notification' |
| 370 | + end |
319 | 371 | end |
320 | 372 |
|
321 | 373 | context 'when replacing a role but with a user having had the replaced role before (no inherited_from)' do |
|
358 | 410 | it_behaves_like 'sends notification' do |
359 | 411 | let(:user) { users } |
360 | 412 | end |
| 413 | + |
| 414 | + context 'when notifications are suppressed' do |
| 415 | + let(:send_notifications) { false } |
| 416 | + |
| 417 | + it_behaves_like 'sends no notification' |
| 418 | + end |
361 | 419 | end |
362 | 420 |
|
363 | 421 | context 'when adding a role and the user has a role already granted by a different group' do |
|
373 | 431 |
|
374 | 432 | ::Groups::CreateInheritedRolesService |
375 | 433 | .new(group, current_user: User.system, contract_class: EmptyContract) |
376 | | - .call(user_ids: users.map(&:id)) |
| 434 | + .call(user_ids: users.map(&:id), send_notifications: false) |
377 | 435 | end |
378 | 436 | end |
379 | 437 |
|
|
399 | 457 | it_behaves_like 'sends notification' do |
400 | 458 | let(:user) { users } |
401 | 459 | end |
| 460 | + |
| 461 | + context 'when notifications are suppressed' do |
| 462 | + let(:send_notifications) { false } |
| 463 | + |
| 464 | + it_behaves_like 'sends no notification' |
| 465 | + end |
402 | 466 | end |
403 | 467 |
|
404 | 468 | context 'when not allowed' do |
|
0 commit comments