diff options
author | Alexandru Croitor <acroitor@gitlab.com> | 2019-02-20 17:18:15 +0200 |
---|---|---|
committer | Alexandru Croitor <acroitor@gitlab.com> | 2019-02-27 22:07:50 +0200 |
commit | 77985826d94454514c40b8da926e13b3b3791841 (patch) | |
tree | 00da4c2f5b72001e38b56e9d994cabc278ec0d7c /spec/mailers | |
parent | 177f9ca88b4d080e91b6c4ce2bba04d2fba95c07 (diff) | |
download | gitlab-ce-77985826d94454514c40b8da926e13b3b3791841.tar.gz |
Show header and footer system messages in email
* Add email_header_and_footer_enabled flag to appearances table
* Set email_header_and_footer_enabled default value to false
* Add checkbox to appearance to toggle show header and footer in emails
* Add email_header_and_footer_enabled to allowed params in controller
* Add header and footer messages to the html and text email layouts
* Remove the color styling for emails header and footer
* Add empty_mailer layout for emails without layout,
to have the header and footer applied
Diffstat (limited to 'spec/mailers')
-rw-r--r-- | spec/mailers/abuse_report_mailer_spec.rb | 25 | ||||
-rw-r--r-- | spec/mailers/email_rejection_mailer_spec.rb | 16 | ||||
-rw-r--r-- | spec/mailers/emails/auto_devops_spec.rb | 3 | ||||
-rw-r--r-- | spec/mailers/emails/issues_spec.rb | 9 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 108 | ||||
-rw-r--r-- | spec/mailers/repository_check_mailer_spec.rb | 7 |
6 files changed, 155 insertions, 13 deletions
diff --git a/spec/mailers/abuse_report_mailer_spec.rb b/spec/mailers/abuse_report_mailer_spec.rb index bda892083b3..f96870cc112 100644 --- a/spec/mailers/abuse_report_mailer_spec.rb +++ b/spec/mailers/abuse_report_mailer_spec.rb @@ -4,25 +4,24 @@ describe AbuseReportMailer do include EmailSpec::Matchers describe '.notify' do - context 'with admin_notification_email set' do - before do - stub_application_setting(admin_notification_email: 'admin@example.com') - end + before do + stub_application_setting(admin_notification_email: 'admin@example.com') + end - it 'sends to the admin_notification_email' do - report = create(:abuse_report) + let(:report) { create(:abuse_report) } + + subject { described_class.notify(report.id) } - mail = described_class.notify(report.id) + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' - expect(mail).to deliver_to 'admin@example.com' + context 'with admin_notification_email set' do + it 'sends to the admin_notification_email' do + is_expected.to deliver_to 'admin@example.com' end it 'includes the user in the subject' do - report = create(:abuse_report) - - mail = described_class.notify(report.id) - - expect(mail).to have_subject "#{report.user.name} (#{report.user.username}) was reported for abuse" + is_expected.to have_subject "#{report.user.name} (#{report.user.username}) was reported for abuse" end end diff --git a/spec/mailers/email_rejection_mailer_spec.rb b/spec/mailers/email_rejection_mailer_spec.rb new file mode 100644 index 00000000000..bbe0a50ae8e --- /dev/null +++ b/spec/mailers/email_rejection_mailer_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe EmailRejectionMailer do + include EmailSpec::Matchers + + describe '#rejection' do + let(:raw_email) { 'From: someone@example.com\nraw email here' } + + subject { described_class.rejection('some rejection reason', raw_email) } + + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + end +end diff --git a/spec/mailers/emails/auto_devops_spec.rb b/spec/mailers/emails/auto_devops_spec.rb index 839caf3f50e..dd7c12c3143 100644 --- a/spec/mailers/emails/auto_devops_spec.rb +++ b/spec/mailers/emails/auto_devops_spec.rb @@ -13,6 +13,9 @@ describe Emails::AutoDevops do subject { Notify.autodevops_disabled_email(pipeline, owner.email) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it 'sents email with correct subject' do is_expected.to have_subject("#{project.name} | Auto DevOps pipeline was disabled for #{project.name}") end diff --git a/spec/mailers/emails/issues_spec.rb b/spec/mailers/emails/issues_spec.rb index 09253cf8003..5b5bd6f4308 100644 --- a/spec/mailers/emails/issues_spec.rb +++ b/spec/mailers/emails/issues_spec.rb @@ -29,5 +29,14 @@ describe Emails::Issues do expect(subject).to have_body_text "23, 34, 58" end + + context 'with header and footer' do + let(:results) { { success: 165, error_lines: [], parse_error: false } } + + subject { Notify.import_issues_csv_email(user.id, project.id, results) } + + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + end end end diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 4f578c48d5b..15b04c9d066 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -53,6 +53,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject and body' do aggregate_failures do @@ -72,6 +74,9 @@ describe Notify do context 'when sent with a reason' do subject { described_class.new_issue_email(issue.assignees.first.id, issue.id, NotificationReason::ASSIGNED) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it 'includes the reason in a header' do is_expected.to have_header('X-GitLab-NotificationReason', NotificationReason::ASSIGNED) end @@ -99,6 +104,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -118,6 +125,9 @@ describe Notify do context 'when sent with a reason' do subject { described_class.reassigned_issue_email(recipient.id, issue.id, [previous_assignee.id], current_user.id, NotificationReason::ASSIGNED) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it 'includes the reason in a header' do is_expected.to have_header('X-GitLab-NotificationReason', NotificationReason::ASSIGNED) end @@ -134,6 +144,8 @@ describe Notify do it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'an email with a labels subscriptions link in its footer' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -173,6 +185,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -199,6 +213,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains description about action taken' do is_expected.to have_body_text 'Issue was moved to another project' @@ -226,6 +242,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject and body' do aggregate_failures do @@ -243,6 +261,9 @@ describe Notify do context 'when sent with a reason' do subject { described_class.new_merge_request_email(merge_request.assignee_id, merge_request.id, NotificationReason::ASSIGNED) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it 'includes the reason in a header' do is_expected.to have_header('X-GitLab-NotificationReason', NotificationReason::ASSIGNED) end @@ -270,6 +291,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like "an unsubscribeable thread" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -289,6 +312,9 @@ describe Notify do context 'when sent with a reason' do subject { described_class.reassigned_merge_request_email(recipient.id, merge_request.id, previous_assignee.id, current_user.id, NotificationReason::ASSIGNED) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it 'includes the reason in a header' do is_expected.to have_header('X-GitLab-NotificationReason', NotificationReason::ASSIGNED) end @@ -313,6 +339,8 @@ describe Notify do it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like "an unsubscribeable thread" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains the description' do is_expected.to have_body_text(merge_request.description) @@ -329,6 +357,8 @@ describe Notify do it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'an email with a labels subscriptions link in its footer' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -352,6 +382,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -379,6 +411,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the merge author' do sender = subject.header[:from].addrs[0] @@ -413,6 +447,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the merge request author' do sender = subject.header[:from].addrs[0] @@ -442,6 +478,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the push user' do sender = subject.header[:from].addrs[0] @@ -482,6 +520,9 @@ describe Notify do subject { described_class.note_issue_email(recipient.id, third_note.id) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it 'has In-Reply-To header pointing to previous note in discussion' do expect(subject.header['In-Reply-To'].message_ids).to eq(["note_#{second_note.id}@#{host}"]) end @@ -502,6 +543,9 @@ describe Notify do subject { described_class.note_issue_email(recipient.id, note.id) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it 'has In-Reply-To header pointing to the issue' do expect(subject.header['In-Reply-To'].message_ids).to eq(["issue_#{note.noteable.id}@#{host}"]) end @@ -518,6 +562,9 @@ describe Notify do subject { described_class.note_project_snippet_email(project_snippet_note.author_id, project_snippet_note.id) } + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do let(:model) { project_snippet } end @@ -535,6 +582,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject and body' do is_expected.to have_subject("#{project.name} | Project was moved") @@ -559,6 +608,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do to_emails = subject.header[:to].addrs.map(&:address) @@ -582,6 +633,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject "Access to the #{project.full_name} project was denied" @@ -599,6 +652,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject "Access to the #{project.full_name} project was granted" @@ -629,6 +684,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject "Invitation to join the #{project.full_name} project" @@ -653,6 +710,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject 'Invitation accepted' @@ -676,6 +735,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject 'Invitation declined' @@ -708,6 +769,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Commit link' it_behaves_like 'a user cannot unsubscribe through footer link' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject and body' do aggregate_failures do @@ -732,6 +795,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject and body' do aggregate_failures do @@ -756,6 +821,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject and body' do aggregate_failures do @@ -819,6 +886,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Commit link' it_behaves_like 'a user cannot unsubscribe through footer link' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject' do is_expected.to have_subject "Re: #{project.name} | #{commit.title} (#{commit.short_id})" @@ -845,6 +914,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject' do is_expected.to have_referable_subject(merge_request, reply: true) @@ -871,6 +942,8 @@ describe Notify do end it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject' do is_expected.to have_referable_subject(issue, reply: true) @@ -948,6 +1021,8 @@ describe Notify do it_behaves_like 'an email for a note on a diff discussion', :diff_note_on_commit it_behaves_like 'it should show Gmail Actions View Commit link' it_behaves_like 'a user cannot unsubscribe through footer link' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' end describe 'on a merge request' do @@ -958,6 +1033,8 @@ describe Notify do it_behaves_like 'an email for a note on a diff discussion', :diff_note_on_merge_request it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'an unsubscribeable thread' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' end end end @@ -976,6 +1053,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do to_emails = subject.header[:to].addrs.map(&:address) @@ -998,6 +1077,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject "Access to the #{group.name} group was denied" @@ -1014,6 +1095,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject "Access to the #{group.name} group was granted" @@ -1044,6 +1127,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject "Invitation to join the #{group.name} group" @@ -1068,6 +1153,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject 'Invitation accepted' @@ -1091,6 +1178,8 @@ describe Notify do it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like "a user cannot unsubscribe through footer link" + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'contains all the useful information' do is_expected.to have_subject 'Invitation declined' @@ -1140,6 +1229,8 @@ describe Notify do it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'an email with X-GitLab headers containing project details' it_behaves_like 'an email that contains a header with author username' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -1165,6 +1256,8 @@ describe Notify do it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like 'an email with X-GitLab headers containing project details' it_behaves_like 'an email that contains a header with author username' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -1189,6 +1282,8 @@ describe Notify do it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'an email with X-GitLab headers containing project details' it_behaves_like 'an email that contains a header with author username' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -1210,6 +1305,8 @@ describe Notify do it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'an email with X-GitLab headers containing project details' it_behaves_like 'an email that contains a header with author username' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -1237,6 +1334,8 @@ describe Notify do it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'an email with X-GitLab headers containing project details' it_behaves_like 'an email that contains a header with author username' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -1328,6 +1427,8 @@ describe Notify do it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'an email with X-GitLab headers containing project details' it_behaves_like 'an email that contains a header with author username' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -1348,6 +1449,11 @@ describe Notify do describe 'HTML emails setting' do let(:multipart_mail) { described_class.project_was_moved_email(project.id, user.id, "gitlab/gitlab") } + subject { multipart_mail } + + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + context 'when disabled' do it 'only sends the text template' do stub_application_setting(html_emails_enabled: false) @@ -1386,6 +1492,8 @@ describe Notify do subject { described_class.note_personal_snippet_email(personal_snippet_note.author_id, personal_snippet_note.id) } it_behaves_like 'a user cannot unsubscribe through footer link' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the correct subject and body' do is_expected.to have_referable_subject(personal_snippet, reply: true) diff --git a/spec/mailers/repository_check_mailer_spec.rb b/spec/mailers/repository_check_mailer_spec.rb index 00613c7b671..384660f7221 100644 --- a/spec/mailers/repository_check_mailer_spec.rb +++ b/spec/mailers/repository_check_mailer_spec.rb @@ -17,5 +17,12 @@ describe RepositoryCheckMailer do expect(mail).to have_subject 'GitLab Admin | 3 projects failed their last repository check' end + + context 'with footer and header' do + subject { described_class.notify(1) } + + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + end end end |