diff options
author | Nick Thomas <nick@gitlab.com> | 2016-08-16 19:40:04 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2016-08-16 19:40:04 +0300 |
commit | ffd7311d03485f146cef4b915d1f7d71f70d30bb (patch) | |
tree | f034aa2b9830f8f6d041a27359fcd9033b8e203b | |
parent | 0e9c4a902d7985d917fac1f833c9544133f83a95 (diff) |
DRY up the additions to notification_service_spec.rb
-rw-r--r-- | spec/services/notification_service_spec.rb | 74 |
1 files changed, 28 insertions, 46 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 1cf644e1331..62c97e09288 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -9,6 +9,28 @@ describe NotificationService, services: true do end end + shared_examples 'notifications for new mentions' do + def send_notifications(*new_mentions) + reset_delivered_emails! + notification.send(notification_method, mentionable, new_mentions, @u_disabled) + end + + it 'sends no emails when no new mentions are present' do + send_notifications + expect(ActionMailer::Base.deliveries).to be_empty + end + + it 'emails new mentions with a watch level higher than participant' do + send_notifications(@u_watcher, @u_participant_mentioned, @u_custom_global) + should_only_email(@u_watcher, @u_participant_mentioned, @u_custom_global) + end + + it 'does not email new mentions with a watch level equal to or less than participant' do + send_notifications(@u_participating, @u_mentioned) + expect(ActionMailer::Base.deliveries).to be_empty + end + end + describe 'Keys' do describe '#new_key' do let!(:key) { create(:personal_key) } @@ -400,30 +422,10 @@ describe NotificationService, services: true do end describe '#new_mentions_in_issue' do - def send_notifications(*new_mentions) - ActionMailer::Base.deliveries.clear - notification.new_mentions_in_issue(issue, new_mentions, @u_disabled) - end - - it 'sends no emails when no new mentions are present' do - send_notifications - expect(ActionMailer::Base.deliveries).to be_empty - end + let(:notification_method) { :new_mentions_in_issue } + let(:mentionable) { issue } - it 'emails new mentions with a watch level higher than participant' do - send_notifications(@u_watcher, @u_participant_mentioned, @u_custom_global) - - should_email(@u_watcher) - should_email(@u_participant_mentioned) - should_email(@u_custom_global) - - expect(ActionMailer::Base.deliveries.count).to eq 3 - end - - it 'does not email new mentions with a watch level equal to or less than participant' do - send_notifications(@u_participating, @u_mentioned) - expect(ActionMailer::Base.deliveries).to be_empty - end + include_examples 'notifications for new mentions' end describe '#reassigned_issue' do @@ -793,30 +795,10 @@ describe NotificationService, services: true do end describe '#new_mentions_in_merge_request' do - def send_notifications(*new_mentions) - ActionMailer::Base.deliveries.clear - notification.new_mentions_in_merge_request(merge_request, new_mentions, @u_disabled) - end - - it 'sends no emails when there are no new mentions' do - send_notifications - expect(ActionMailer::Base.deliveries).to be_empty - end + let(:notification_method) { :new_mentions_in_merge_request } + let(:mentionable) { merge_request } - it 'emails new mentions with a watch level higher than participant' do - send_notifications(@u_watcher, @u_participant_mentioned, @u_custom_global) - - should_email(@u_watcher) - should_email(@u_participant_mentioned) - should_email(@u_custom_global) - - expect(ActionMailer::Base.deliveries.count).to eq 3 - end - - it 'does not email new mentions with a watch level equal to or less than participant' do - send_notifications(@u_participating, @u_mentioned) - expect(ActionMailer::Base.deliveries).to be_empty - end + include_examples 'notifications for new mentions' end describe '#reassigned_merge_request' do |