diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-05-07 22:55:00 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-05-07 22:55:00 +0300 |
commit | 94099f2dd6e4b468886e1de787d4888cfc3114f7 (patch) | |
tree | 3ac846c8d21a145223150b4b844fe25b753d9acd /spec | |
parent | 797a080681233e97ccc0c9ba72431e4b450fff7b (diff) | |
parent | 02741ca4c58c625070d06c248125b2f510ac2c0b (diff) |
Merge branch '5480-epic-notifications-ce' into 'master'
Backport 5480-epic-notifications from EE
See merge request gitlab-org/gitlab-ce!18724
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/email/handler/create_issue_handler_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/email/handler/create_note_handler_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/email/handler/unsubscribe_handler_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/email/receiver_spec.rb | 1 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 32 | ||||
-rw-r--r-- | spec/services/notification_service_spec.rb | 31 | ||||
-rw-r--r-- | spec/support/helpers/notification_helpers.rb | 33 | ||||
-rw-r--r-- | spec/support/shared_contexts/email_shared_blocks.rb (renamed from spec/lib/gitlab/email/email_shared_blocks.rb) | 0 | ||||
-rw-r--r-- | spec/support/shared_examples/notify_shared_examples.rb | 32 |
10 files changed, 66 insertions, 67 deletions
diff --git a/spec/lib/gitlab/email/handler/create_issue_handler_spec.rb b/spec/lib/gitlab/email/handler/create_issue_handler_spec.rb index 6568a0b1bb0..452249210b0 100644 --- a/spec/lib/gitlab/email/handler/create_issue_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_issue_handler_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require_relative '../email_shared_blocks' describe Gitlab::Email::Handler::CreateIssueHandler do include_context :email_shared_context diff --git a/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb b/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb index dc1a93367a4..43c6280f251 100644 --- a/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require_relative '../email_shared_blocks' describe Gitlab::Email::Handler::CreateMergeRequestHandler do include_context :email_shared_context diff --git a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb index 53899e00b53..950a7dd7d6c 100644 --- a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require_relative '../email_shared_blocks' describe Gitlab::Email::Handler::CreateNoteHandler do include_context :email_shared_context diff --git a/spec/lib/gitlab/email/handler/unsubscribe_handler_spec.rb b/spec/lib/gitlab/email/handler/unsubscribe_handler_spec.rb index 21796694f26..ce160e11de2 100644 --- a/spec/lib/gitlab/email/handler/unsubscribe_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/unsubscribe_handler_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require_relative '../email_shared_blocks' describe Gitlab::Email::Handler::UnsubscribeHandler do include_context :email_shared_context diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 59f43abf26d..0af978eced3 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require_relative 'email_shared_blocks' describe Gitlab::Email::Receiver do include_context :email_shared_context diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 43e419cd7de..84ddbbbf2ee 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -654,38 +654,6 @@ describe Notify do allow(Note).to receive(:find).with(note.id).and_return(note) end - shared_examples 'a note email' do - it_behaves_like 'it should have Gmail Actions links' - - it 'is sent to the given recipient as the author' do - sender = subject.header[:from].addrs[0] - - aggregate_failures do - expect(sender.display_name).to eq(note_author.name) - expect(sender.address).to eq(gitlab_sender) - expect(subject).to deliver_to(recipient.notification_email) - end - end - - it 'contains the message from the note' do - is_expected.to have_html_escaped_body_text note.note - end - - it 'does not contain note author' do - is_expected.not_to have_body_text note.author_name - end - - context 'when enabled email_author_in_body' do - before do - stub_application_setting(email_author_in_body: true) - end - - it 'contains a link to note author' do - is_expected.to have_html_escaped_body_text note.author_name - end - end - end - describe 'on a commit' do let(:commit) { project.commit } diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 48ef5f3c115..5f28bc123f3 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe NotificationService, :mailer do include EmailSpec::Matchers + include NotificationHelpers let(:notification) { described_class.new } let(:assignee) { create(:user) } @@ -13,12 +14,6 @@ describe NotificationService, :mailer do end shared_examples 'notifications for new mentions' do - def send_notifications(*new_mentions) - mentionable.description = new_mentions.map(&:to_reference).join(' ') - - notification.send(notification_method, mentionable, new_mentions, @u_disabled) - end - it 'sends no emails when no new mentions are present' do send_notifications should_not_email_anyone @@ -1914,30 +1909,6 @@ describe NotificationService, :mailer do group end - def create_global_setting_for(user, level) - setting = user.global_notification_setting - setting.level = level - setting.save - - user - end - - def create_user_with_notification(level, username, resource = project) - user = create(:user, username: username) - setting = user.notification_settings_for(resource) - setting.level = level - setting.save - - user - end - - # Create custom notifications - # When resource is nil it means global notification - def update_custom_notification(event, user, resource: nil, value: true) - setting = user.notification_settings_for(resource) - setting.update!(event => value) - end - def add_users_with_subscription(project, issuable) @subscriber = create :user @unsubscriber = create :user diff --git a/spec/support/helpers/notification_helpers.rb b/spec/support/helpers/notification_helpers.rb new file mode 100644 index 00000000000..8d84510fb73 --- /dev/null +++ b/spec/support/helpers/notification_helpers.rb @@ -0,0 +1,33 @@ +module NotificationHelpers + extend self + + def send_notifications(*new_mentions) + mentionable.description = new_mentions.map(&:to_reference).join(' ') + + notification.send(notification_method, mentionable, new_mentions, @u_disabled) + end + + def create_global_setting_for(user, level) + setting = user.global_notification_setting + setting.level = level + setting.save + + user + end + + def create_user_with_notification(level, username, resource = project) + user = create(:user, username: username) + setting = user.notification_settings_for(resource) + setting.level = level + setting.save + + user + end + + # Create custom notifications + # When resource is nil it means global notification + def update_custom_notification(event, user, resource: nil, value: true) + setting = user.notification_settings_for(resource) + setting.update!(event => value) + end +end diff --git a/spec/lib/gitlab/email/email_shared_blocks.rb b/spec/support/shared_contexts/email_shared_blocks.rb index 9d806fc524d..9d806fc524d 100644 --- a/spec/lib/gitlab/email/email_shared_blocks.rb +++ b/spec/support/shared_contexts/email_shared_blocks.rb diff --git a/spec/support/shared_examples/notify_shared_examples.rb b/spec/support/shared_examples/notify_shared_examples.rb index e2c23607406..43fdaddf545 100644 --- a/spec/support/shared_examples/notify_shared_examples.rb +++ b/spec/support/shared_examples/notify_shared_examples.rb @@ -197,3 +197,35 @@ end shared_examples 'an email with a labels subscriptions link in its footer' do it { is_expected.to have_body_text('label subscriptions') } end + +shared_examples 'a note email' do + it_behaves_like 'it should have Gmail Actions links' + + it 'is sent to the given recipient as the author' do + sender = subject.header[:from].addrs[0] + + aggregate_failures do + expect(sender.display_name).to eq(note_author.name) + expect(sender.address).to eq(gitlab_sender) + expect(subject).to deliver_to(recipient.notification_email) + end + end + + it 'contains the message from the note' do + is_expected.to have_html_escaped_body_text note.note + end + + it 'does not contain note author' do + is_expected.not_to have_body_text note.author_name + end + + context 'when enabled email_author_in_body' do + before do + stub_application_setting(email_author_in_body: true) + end + + it 'contains a link to note author' do + is_expected.to have_html_escaped_body_text note.author_name + end + end +end |