diff options
Diffstat (limited to 'spec/support/shared_examples/notify_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/notify_shared_examples.rb | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/spec/support/shared_examples/notify_shared_examples.rb b/spec/support/shared_examples/notify_shared_examples.rb index 4fff1c4e228..897c9106d77 100644 --- a/spec/support/shared_examples/notify_shared_examples.rb +++ b/spec/support/shared_examples/notify_shared_examples.rb @@ -1,5 +1,7 @@ shared_context 'gitlab email notification' do - set(:project) { create(:project, :repository, name: 'a-known-name') } + set(:group) { create(:group) } + set(:subgroup) { create(:group, parent: group) } + set(:project) { create(:project, :repository, name: 'a-known-name', group: group) } set(:recipient) { create(:user, email: 'recipient@example.com') } let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name } @@ -39,6 +41,47 @@ shared_examples 'an email sent from GitLab' do end end +shared_examples 'an email sent to a user' do + let(:group_notification_email) { 'user+group@example.com' } + + it 'is sent to user\'s global notification email address' do + expect(subject).to deliver_to(test_recipient.notification_email) + end + + context 'that is part of a project\'s group' do + it 'is sent to user\'s group notification email address when set' do + create(:notification_setting, user: test_recipient, source: project.group, notification_email: group_notification_email) + expect(subject).to deliver_to(group_notification_email) + end + + it 'is sent to user\'s global notification email address when no group email set' do + create(:notification_setting, user: test_recipient, source: project.group, notification_email: '') + expect(subject).to deliver_to(test_recipient.notification_email) + end + end + + context 'when project is in a sub-group', :nested_groups do + before do + project.update!(group: subgroup) + end + + it 'is sent to user\'s subgroup notification email address when set' do + # Set top-level group notification email address to make sure it doesn't get selected + create(:notification_setting, user: test_recipient, source: group, notification_email: group_notification_email) + + subgroup_notification_email = 'user+subgroup@example.com' + create(:notification_setting, user: test_recipient, source: subgroup, notification_email: subgroup_notification_email) + + expect(subject).to deliver_to(subgroup_notification_email) + end + + it 'is sent to user\'s group notification email address when set and subgroup email address not set' do + create(:notification_setting, user: test_recipient, source: subgroup, notification_email: '') + expect(subject).to deliver_to(test_recipient.notification_email) + end + end +end + shared_examples 'an email that contains a header with author username' do it 'has X-GitLab-Author header containing author\'s username' do is_expected.to have_header 'X-GitLab-Author', user.username |