Commit a0192b4e authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-notify-mailer-specs' into 'master'

Cleanup Notify spec and combine multiple examples into one

See merge request !10129
parents 64aaa1ae a6e43aa2
...@@ -5,6 +5,16 @@ describe Notify do ...@@ -5,6 +5,16 @@ describe Notify do
include EmailSpec::Matchers include EmailSpec::Matchers
include_context 'gitlab email notification' include_context 'gitlab email notification'
shared_examples 'a new user email' do
it 'is sent to the new user with the correct subject and body' do
aggregate_failures do
is_expected.to deliver_to new_user_address
is_expected.to have_subject(/^Account was created for you$/i)
is_expected.to have_body_text(new_user_address)
end
end
end
describe 'profile notifications' do describe 'profile notifications' do
describe 'for new users, the email' do describe 'for new users, the email' do
let(:example_site_path) { root_path } let(:example_site_path) { root_path }
......
...@@ -24,14 +24,14 @@ describe Notify do ...@@ -24,14 +24,14 @@ describe Notify do
let(:previous_assignee) { create(:user, name: 'Previous Assignee') } let(:previous_assignee) { create(:user, name: 'Previous Assignee') }
shared_examples 'an assignee email' do shared_examples 'an assignee email' do
it 'is sent as the author' do it 'is sent to the assignee as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs.first
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
end
it 'is sent to the assignee' do aggregate_failures do
is_expected.to deliver_to assignee.email expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect(subject).to deliver_to(assignee.email)
end
end end
end end
...@@ -49,12 +49,11 @@ describe Notify do ...@@ -49,12 +49,11 @@ describe Notify do
it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'it should show Gmail Actions View Issue link'
it_behaves_like 'an unsubscribeable thread' it_behaves_like 'an unsubscribeable thread'
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(issue) aggregate_failures do
end is_expected.to have_referable_subject(issue)
is_expected.to have_body_text(namespace_project_issue_path(project.namespace, project, issue))
it 'contains a link to the new issue' do end
is_expected.to have_body_text namespace_project_issue_path(project.namespace, project, issue)
end end
context 'when enabled email_author_in_body' do context 'when enabled email_author_in_body' do
...@@ -63,7 +62,7 @@ describe Notify do ...@@ -63,7 +62,7 @@ describe Notify do
end end
it 'contains a link to note author' do it 'contains a link to note author' do
is_expected.to have_html_escaped_body_text issue.author_name is_expected.to have_html_escaped_body_text(issue.author_name)
is_expected.to have_body_text 'wrote:' is_expected.to have_body_text 'wrote:'
end end
end end
...@@ -95,20 +94,13 @@ describe Notify do ...@@ -95,20 +94,13 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(issue, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(issue, reply: true)
is_expected.to have_html_escaped_body_text(previous_assignee.name)
it 'contains the name of the previous assignee' do is_expected.to have_html_escaped_body_text(assignee.name)
is_expected.to have_html_escaped_body_text previous_assignee.name is_expected.to have_body_text(namespace_project_issue_path(project.namespace, project, issue))
end end
it 'contains the name of the new assignee' do
is_expected.to have_html_escaped_body_text assignee.name
end
it 'contains a link to the issue' do
is_expected.to have_body_text namespace_project_issue_path(project.namespace, project, issue)
end end
end end
...@@ -129,16 +121,12 @@ describe Notify do ...@@ -129,16 +121,12 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(issue, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(issue, reply: true)
is_expected.to have_body_text('foo, bar, and baz')
it 'contains the names of the added labels' do is_expected.to have_body_text(namespace_project_issue_path(project.namespace, project, issue))
is_expected.to have_body_text 'foo, bar, and baz' end
end
it 'contains a link to the issue' do
is_expected.to have_body_text namespace_project_issue_path(project.namespace, project, issue)
end end
end end
...@@ -158,20 +146,13 @@ describe Notify do ...@@ -158,20 +146,13 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(issue, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(issue, reply: true)
is_expected.to have_body_text(status)
it 'contains the new status' do is_expected.to have_html_escaped_body_text(current_user.name)
is_expected.to have_body_text status is_expected.to have_body_text(namespace_project_issue_path project.namespace, project, issue)
end end
it 'contains the user name' do
is_expected.to have_html_escaped_body_text current_user.name
end
it 'contains a link to the issue' do
is_expected.to have_body_text(namespace_project_issue_path project.namespace, project, issue)
end end
end end
...@@ -189,18 +170,15 @@ describe Notify do ...@@ -189,18 +170,15 @@ describe Notify do
is_expected.to have_body_text 'Issue was moved to another project' is_expected.to have_body_text 'Issue was moved to another project'
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(issue, reply: true)
end
it 'contains link to new issue' do
new_issue_url = namespace_project_issue_path(new_issue.project.namespace, new_issue_url = namespace_project_issue_path(new_issue.project.namespace,
new_issue.project, new_issue) new_issue.project, new_issue)
is_expected.to have_body_text new_issue_url
end
it 'contains a link to the original issue' do aggregate_failures do
is_expected.to have_body_text namespace_project_issue_path(project.namespace, project, issue) is_expected.to have_referable_subject(issue, reply: true)
is_expected.to have_body_text(new_issue_url)
is_expected.to have_body_text(namespace_project_issue_path(project.namespace, project, issue))
end
end end
end end
end end
...@@ -220,20 +198,13 @@ describe Notify do ...@@ -220,20 +198,13 @@ describe Notify do
it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'it should show Gmail Actions View Merge request link'
it_behaves_like 'an unsubscribeable thread' it_behaves_like 'an unsubscribeable thread'
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(merge_request) aggregate_failures do
end is_expected.to have_referable_subject(merge_request)
is_expected.to have_body_text(namespace_project_merge_request_path(project.namespace, project, merge_request))
it 'contains a link to the new merge request' do is_expected.to have_body_text(merge_request.source_branch)
is_expected.to have_body_text namespace_project_merge_request_path(project.namespace, project, merge_request) is_expected.to have_body_text(merge_request.target_branch)
end end
it 'contains the source branch for the merge request' do
is_expected.to have_body_text merge_request.source_branch
end
it 'contains the target branch for the merge request' do
is_expected.to have_body_text merge_request.target_branch
end end
context 'when enabled email_author_in_body' do context 'when enabled email_author_in_body' do
...@@ -275,20 +246,13 @@ describe Notify do ...@@ -275,20 +246,13 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(merge_request, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_html_escaped_body_text(previous_assignee.name)
it 'contains the name of the previous assignee' do is_expected.to have_body_text(namespace_project_merge_request_path(project.namespace, project, merge_request))
is_expected.to have_html_escaped_body_text previous_assignee.name is_expected.to have_html_escaped_body_text(assignee.name)
end end
it 'contains the name of the new assignee' do
is_expected.to have_html_escaped_body_text assignee.name
end
it 'contains a link to the merge request' do
is_expected.to have_body_text namespace_project_merge_request_path(project.namespace, project, merge_request)
end end
end end
...@@ -309,16 +273,10 @@ describe Notify do ...@@ -309,16 +273,10 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(merge_request, reply: true) is_expected.to have_referable_subject(merge_request, reply: true)
end is_expected.to have_body_text('foo, bar, and baz')
is_expected.to have_body_text(namespace_project_merge_request_path(project.namespace, project, merge_request))
it 'contains the names of the added labels' do
is_expected.to have_body_text 'foo, bar, and baz'
end
it 'contains a link to the merge request' do
is_expected.to have_body_text namespace_project_merge_request_path(project.namespace, project, merge_request)
end end
end end
...@@ -338,20 +296,13 @@ describe Notify do ...@@ -338,20 +296,13 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(merge_request, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text(status)
it 'contains the new status' do is_expected.to have_html_escaped_body_text(current_user.name)
is_expected.to have_body_text status is_expected.to have_body_text(namespace_project_merge_request_path(project.namespace, project, merge_request))
end end
it 'contains the user name' do
is_expected.to have_html_escaped_body_text current_user.name
end
it 'contains a link to the merge request' do
is_expected.to have_body_text namespace_project_merge_request_path(project.namespace, project, merge_request)
end end
end end
...@@ -371,16 +322,12 @@ describe Notify do ...@@ -371,16 +322,12 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(merge_request, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text('merged')
it 'contains the new status' do is_expected.to have_body_text(namespace_project_merge_request_path(project.namespace, project, merge_request))
is_expected.to have_body_text 'merged' end
end
it 'contains a link to the merge request' do
is_expected.to have_body_text namespace_project_merge_request_path(project.namespace, project, merge_request)
end end
end end
end end
...@@ -395,16 +342,10 @@ describe Notify do ...@@ -395,16 +342,10 @@ describe Notify do
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_subject "#{project.name} | Project was moved" is_expected.to have_subject("#{project.name} | Project was moved")
end
it 'contains name of project' do
is_expected.to have_html_escaped_body_text project.name_with_namespace is_expected.to have_html_escaped_body_text project.name_with_namespace
end is_expected.to have_body_text(project.ssh_url_to_repo)
it 'contains new user role' do
is_expected.to have_body_text project.ssh_url_to_repo
end end
end end
...@@ -597,14 +538,14 @@ describe Notify do ...@@ -597,14 +538,14 @@ describe Notify do
shared_examples 'a note email' do shared_examples 'a note email' do
it_behaves_like 'it should have Gmail Actions links' it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent to the given recipient as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(note_author.name)
expect(sender.address).to eq(gitlab_sender)
end
it 'is sent to the given recipient' do aggregate_failures do
is_expected.to deliver_to recipient.notification_email 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 end
it 'contains the message from the note' do it 'contains the message from the note' do
...@@ -641,12 +582,11 @@ describe Notify do ...@@ -641,12 +582,11 @@ describe Notify do
it_behaves_like 'it should show Gmail Actions View Commit link' it_behaves_like 'it should show Gmail Actions View Commit link'
it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'a user cannot unsubscribe through footer link'
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_subject "Re: #{project.name} | #{commit.title.strip} (#{commit.short_id})" aggregate_failures do
end is_expected.to have_subject("Re: #{project.name} | #{commit.title.strip} (#{commit.short_id})")
is_expected.to have_body_text(commit.short_id)
it 'contains a link to the commit' do end
is_expected.to have_body_text commit.short_id
end end
end end
...@@ -664,12 +604,11 @@ describe Notify do ...@@ -664,12 +604,11 @@ describe Notify do
it_behaves_like 'it should show Gmail Actions View Merge request link' it_behaves_like 'it should show Gmail Actions View Merge request link'
it_behaves_like 'an unsubscribeable thread' it_behaves_like 'an unsubscribeable thread'
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(merge_request, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text note_on_merge_request_path
it 'contains a link to the merge request note' do end
is_expected.to have_body_text note_on_merge_request_path
end end
end end
...@@ -687,12 +626,11 @@ describe Notify do ...@@ -687,12 +626,11 @@ describe Notify do
it_behaves_like 'it should show Gmail Actions View Issue link' it_behaves_like 'it should show Gmail Actions View Issue link'
it_behaves_like 'an unsubscribeable thread' it_behaves_like 'an unsubscribeable thread'
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_referable_subject(issue, reply: true) aggregate_failures do
end is_expected.to have_referable_subject(issue, reply: true)
is_expected.to have_body_text(note_on_issue_path)
it 'contains a link to the issue note' do end
is_expected.to have_body_text note_on_issue_path
end end
end end
end end
...@@ -717,14 +655,14 @@ describe Notify do ...@@ -717,14 +655,14 @@ describe Notify do
it_behaves_like 'it should have Gmail Actions links' it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent to the given recipient as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(note_author.name)
expect(sender.address).to eq(gitlab_sender)
end
it 'is sent to the given recipient' do aggregate_failures do
is_expected.to deliver_to recipient.notification_email 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 end
it 'contains the message from the note' do it 'contains the message from the note' do
...@@ -934,21 +872,20 @@ describe Notify do ...@@ -934,21 +872,20 @@ describe Notify do
is_expected.to deliver_to 'new-email@mail.com' is_expected.to deliver_to 'new-email@mail.com'
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_subject 'Confirmation instructions | A Nice Suffix' aggregate_failures do
end is_expected.to have_subject('Confirmation instructions | A Nice Suffix')
is_expected.to have_body_text(example_site_path)
it 'includes a link to the site' do end
is_expected.to have_body_text example_site_path
end end
end end
describe 'email on push for a created branch' do describe 'email on push for a created branch' do
let(:example_site_path) { root_path } let(:example_site_path) { root_path }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:tree_path) { namespace_project_tree_path(project.namespace, project, "master") } let(:tree_path) { namespace_project_tree_path(project.namespace, project, "empty-branch") }
subject { Notify.repository_push_email(project.id, author_id: user.id, ref: 'refs/heads/master', action: :create) } subject { Notify.repository_push_email(project.id, author_id: user.id, ref: 'refs/heads/empty-branch', action: :create) }
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'a user cannot unsubscribe through footer link'
...@@ -961,12 +898,11 @@ describe Notify do ...@@ -961,12 +898,11 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_subject "[Git][#{project.full_path}] Pushed new branch master" aggregate_failures do
end is_expected.to have_subject("[Git][#{project.full_path}] Pushed new branch empty-branch")
is_expected.to have_body_text(tree_path)
it 'contains a link to the branch' do end
is_expected.to have_body_text tree_path
end end
end end
...@@ -988,12 +924,11 @@ describe Notify do ...@@ -988,12 +924,11 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_subject "[Git][#{project.full_path}] Pushed new tag v1.0" aggregate_failures do
end is_expected.to have_subject("[Git][#{project.full_path}] Pushed new tag v1.0")
is_expected.to have_body_text(tree_path)
it 'contains a link to the tag' do end
is_expected.to have_body_text tree_path
end end
end end
...@@ -1064,24 +999,14 @@ describe Notify do ...@@ -1064,24 +999,14 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_subject "[Git][#{project.full_path}][master] #{commits.length} commits: Ruby files modified" aggregate_failures do
end is_expected.to have_subject("[Git][#{project.full_path}][master] #{commits.length} commits: Ruby files modified")
is_expected.to have_body_text('Change some files')
it 'includes commits list' do is_expected.to have_body_text('def</span> <span class="nf">archive_formats_regex')
is_expected.to have_body_text 'Change some files' is_expected.to have_body_text(diff_path)
end is_expected.not_to have_body_text('you are a member of')
end
it 'includes diffs with character-level highlighting' do
is_expected.to have_body_text 'def</span> <span class="nf">archive_formats_regex'
end
it 'contains a link to the diff' do
is_expected.to have_body_text diff_path
end
it 'does not contain the misleading footer' do
is_expected.not_to have_body_text 'you are a member of'
end end
context "when set to send from committer email if domain matches" do context "when set to send from committer email if domain matches" do
...@@ -1098,13 +1023,13 @@ describe Notify do ...@@ -1098,13 +1023,13 @@ describe Notify do
end end
it "is sent from the committer email" do it "is sent from the committer email" do
sender = subject.header[:from].addrs[0] from = subject.header[:from].addrs.first
expect(sender.address).to eq(user.email) reply = subject.header[:reply_to].addrs.first
end
it "is set to reply to the committer email" do aggregate_failures do
sender = subject.header[:reply_to].addrs[0] expect(from.address).to eq(user.email)
expect(sender.address).to eq(user.email) expect(reply.address).to eq(user.email)
end
end end
end end
...@@ -1115,13 +1040,13 @@ describe Notify do ...@@ -1115,13 +1040,13 @@ describe Notify do
end end
it "is sent from the default email" do it "is sent from the default email" do
sender = subject.header[:from].addrs[0] from = subject.header[:from].addrs.first
expect(sender.address).to eq(gitlab_sender) reply = subject.header[:reply_to].addrs.first
end
it "is set to reply to the default email" do aggregate_failures do
sender = subject.header[:reply_to].addrs[0] expect(from.address).to eq(gitlab_sender)
expect(sender.address).to eq(gitlab_sender_reply_to) expect(reply.address).to eq(gitlab_sender_reply_to)
end
end end
end end
...@@ -1132,13 +1057,13 @@ describe Notify do ...@@ -1132,13 +1057,13 @@ describe Notify do
end end
it "is sent from the default email" do it "is sent from the default email" do
sender = subject.header[:from].addrs[0] from = subject.header[:from].addrs.first
expect(sender.address).to eq(gitlab_sender) reply = subject.header[:reply_to].addrs.first
end
it "is set to reply to the default email" do aggregate_failures do
sender = subject.header[:reply_to].addrs[0] expect(from.address).to eq(gitlab_sender)
expect(sender.address).to eq(gitlab_sender_reply_to) expect(reply.address).to eq(gitlab_sender_reply_to)
end
end end
end end
end end
...@@ -1166,20 +1091,13 @@ describe Notify do ...@@ -1166,20 +1091,13 @@ describe Notify do
expect(sender.address).to eq(gitlab_sender) expect(sender.address).to eq(gitlab_sender)
end end
it 'has the correct subject' do it 'has the correct subject and body' do
is_expected.to have_subject "[Git][#{project.full_path}][master] #{commits.first.title}" aggregate_failures do
end is_expected.to have_subject("[Git][#{project.full_path}][master] #{commits.first.title}")
is_expected.to have_body_text('Change some files')
it 'includes commits list' do is_expected.to have_body_text('def</span> <span class="nf">archive_formats_regex')
is_expected.to have_body_text 'Change some files' is_expected.to have_body_text(diff_path)
end end
it 'includes diffs with character-level highlighting' do
is_expected.to have_body_text 'def</span> <span class="nf">archive_formats_regex'
end
it 'contains a link to the diff' do
is_expected.to have_body_text diff_path
end end
end end
......
...@@ -27,24 +27,14 @@ shared_examples 'a multiple recipients email' do ...@@ -27,24 +27,14 @@ shared_examples 'a multiple recipients email' do
end end
shared_examples 'an email sent from GitLab' do shared_examples 'an email sent from GitLab' do
it 'is sent from GitLab' do it 'has the characteristics of an email sent from GitLab' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(gitlab_sender_display_name)
expect(sender.address).to eq(gitlab_sender)
end
it 'has a Reply-To address' do
reply_to = subject.header[:reply_to].addresses reply_to = subject.header[:reply_to].addresses
expect(reply_to).to eq([gitlab_sender_reply_to])
end
context 'when custom suffix for email subject is set' do
before do
stub_config_setting(email_subject_suffix: 'A Nice Suffix')
end
it 'ends the subject with the suffix' do aggregate_failures do
is_expected.to have_subject /\ \| A Nice Suffix$/ expect(sender.display_name).to eq(gitlab_sender_display_name)
expect(sender.address).to eq(gitlab_sender)
expect(reply_to).to eq([gitlab_sender_reply_to])
end end
end end
end end
...@@ -56,43 +46,40 @@ shared_examples 'an email that contains a header with author username' do ...@@ -56,43 +46,40 @@ shared_examples 'an email that contains a header with author username' do
end end
shared_examples 'an email with X-GitLab headers containing project details' do shared_examples 'an email with X-GitLab headers containing project details' do
it 'has X-GitLab-Project* headers' do it 'has X-GitLab-Project headers' do
is_expected.to have_header 'X-GitLab-Project', /#{project.name}/ aggregate_failures do
is_expected.to have_header 'X-GitLab-Project-Id', /#{project.id}/ is_expected.to have_header('X-GitLab-Project', /#{project.name}/)
is_expected.to have_header 'X-GitLab-Project-Path', /#{project.path_with_namespace}/ is_expected.to have_header('X-GitLab-Project-Id', /#{project.id}/)
is_expected.to have_header('X-GitLab-Project-Path', /#{project.path_with_namespace}/)
end
end end
end end
shared_examples 'a new thread email with reply-by-email enabled' do shared_examples 'a new thread email with reply-by-email enabled' do
let(:regex) { /\A<reply\-(.*)@#{Gitlab.config.gitlab.host}>\Z/ } it 'has the characteristics of a threaded email' do
host = Gitlab.config.gitlab.host
it 'has a Message-ID header' do route_key = "#{model.class.model_name.singular_route_key}_#{model.id}"
is_expected.to have_header 'Message-ID', "<#{model.class.model_name.singular_route_key}_#{model.id}@#{Gitlab.config.gitlab.host}>"
end
it 'has a References header' do aggregate_failures do
is_expected.to have_header 'References', regex is_expected.to have_header('Message-ID', "<#{route_key}@#{host}>")
is_expected.to have_header('References', /\A<reply\-.*@#{host}>\Z/ )
end
end end
end end
shared_examples 'a thread answer email with reply-by-email enabled' do shared_examples 'a thread answer email with reply-by-email enabled' do
include_examples 'an email with X-GitLab headers containing project details' include_examples 'an email with X-GitLab headers containing project details'
let(:regex) { /\A<#{model.class.model_name.singular_route_key}_#{model.id}@#{Gitlab.config.gitlab.host}> <reply\-(.*)@#{Gitlab.config.gitlab.host}>\Z/ }
it 'has a Message-ID header' do
is_expected.to have_header 'Message-ID', /\A<(.*)@#{Gitlab.config.gitlab.host}>\Z/
end
it 'has a In-Reply-To header' do
is_expected.to have_header 'In-Reply-To', "<#{model.class.model_name.singular_route_key}_#{model.id}@#{Gitlab.config.gitlab.host}>"
end
it 'has a References header' do it 'has the characteristics of a threaded reply' do
is_expected.to have_header 'References', regex host = Gitlab.config.gitlab.host
end route_key = "#{model.class.model_name.singular_route_key}_#{model.id}"
it 'has a subject that begins with Re: ' do aggregate_failures do
is_expected.to have_subject /^Re: / is_expected.to have_header('Message-ID', /\A<.*@#{host}>\Z/)
is_expected.to have_header('In-Reply-To', "<#{route_key}@#{host}>")
is_expected.to have_header('References', /\A<#{route_key}@#{host}> <reply\-.*@#{host}>\Z/ )
is_expected.to have_subject(/^Re: /)
end
end end
end end
...@@ -136,80 +123,77 @@ shared_examples 'an answer to an existing thread with reply-by-email enabled' do ...@@ -136,80 +123,77 @@ shared_examples 'an answer to an existing thread with reply-by-email enabled' do
end end
end end
shared_examples 'a new user email' do
it 'is sent to the new user' do
is_expected.to deliver_to new_user_address
end
it 'has the correct subject' do
is_expected.to have_subject /^Account was created for you$/i
end
it 'contains the new user\'s login name' do
is_expected.to have_body_text /#{new_user_address}/
end
end
shared_examples 'it should have Gmail Actions links' do shared_examples 'it should have Gmail Actions links' do
it { is_expected.to have_body_text '<script type="application/ld+json">' } it do
it { is_expected.to have_body_text /ViewAction/ } aggregate_failures do
is_expected.to have_body_text('<script type="application/ld+json">')
is_expected.to have_body_text('ViewAction')
end
end
end end
shared_examples 'it should not have Gmail Actions links' do shared_examples 'it should not have Gmail Actions links' do
it { is_expected.not_to have_body_text '<script type="application/ld+json">' } it do
it { is_expected.not_to have_body_text /ViewAction/ } aggregate_failures do
is_expected.not_to have_body_text('<script type="application/ld+json">')
is_expected.not_to have_body_text('ViewAction')
end
end
end end
shared_examples 'it should show Gmail Actions View Issue link' do shared_examples 'it should show Gmail Actions View Issue link' do
it_behaves_like 'it should have Gmail Actions links' it_behaves_like 'it should have Gmail Actions links'
it { is_expected.to have_body_text /View Issue/ } it { is_expected.to have_body_text('View Issue') }
end end
shared_examples 'it should show Gmail Actions View Merge request link' do shared_examples 'it should show Gmail Actions View Merge request link' do
it_behaves_like 'it should have Gmail Actions links' it_behaves_like 'it should have Gmail Actions links'
it { is_expected.to have_body_text /View Merge request/ } it { is_expected.to have_body_text('View Merge request') }
end end
shared_examples 'it should show Gmail Actions View Commit link' do shared_examples 'it should show Gmail Actions View Commit link' do
it_behaves_like 'it should have Gmail Actions links' it_behaves_like 'it should have Gmail Actions links'
it { is_expected.to have_body_text /View Commit/ } it { is_expected.to have_body_text('View Commit') }
end end
shared_examples 'an unsubscribeable thread' do shared_examples 'an unsubscribeable thread' do
it_behaves_like 'an unsubscribeable thread with incoming address without %{key}' it_behaves_like 'an unsubscribeable thread with incoming address without %{key}'
it 'has a List-Unsubscribe header in the correct format' do it 'has a List-Unsubscribe header in the correct format, and a body link' do
is_expected.to have_header 'List-Unsubscribe', /unsubscribe/ aggregate_failures do
is_expected.to have_header 'List-Unsubscribe', /mailto/ is_expected.to have_header('List-Unsubscribe', /unsubscribe/)
is_expected.to have_header 'List-Unsubscribe', /^<.+,.+>$/ is_expected.to have_header('List-Unsubscribe', /mailto/)
is_expected.to have_header('List-Unsubscribe', /^<.+,.+>$/)
is_expected.to have_body_text('unsubscribe')
end
end end
it { is_expected.to have_body_text /unsubscribe/ }
end end
shared_examples 'an unsubscribeable thread with incoming address without %{key}' do shared_examples 'an unsubscribeable thread with incoming address without %{key}' do
include_context 'reply-by-email is enabled with incoming address without %{key}' include_context 'reply-by-email is enabled with incoming address without %{key}'
it 'has a List-Unsubscribe header in the correct format' do it 'has a List-Unsubscribe header in the correct format, and a body link' do
is_expected.to have_header 'List-Unsubscribe', /unsubscribe/ aggregate_failures do
is_expected.not_to have_header 'List-Unsubscribe', /mailto/ is_expected.to have_header('List-Unsubscribe', /unsubscribe/)
is_expected.to have_header 'List-Unsubscribe', /^<[^,]+>$/ is_expected.not_to have_header('List-Unsubscribe', /mailto/)
is_expected.to have_header('List-Unsubscribe', /^<[^,]+>$/)
is_expected.to have_body_text('unsubscribe')
end
end end
it { is_expected.to have_body_text /unsubscribe/ }
end end
shared_examples 'a user cannot unsubscribe through footer link' do shared_examples 'a user cannot unsubscribe through footer link' do
it 'does not have a List-Unsubscribe header' do it 'does not have a List-Unsubscribe header or a body link' do
is_expected.not_to have_header 'List-Unsubscribe', /unsubscribe/ aggregate_failures do
is_expected.not_to have_header('List-Unsubscribe', /unsubscribe/)
is_expected.not_to have_body_text('unsubscribe')
end
end end
it { is_expected.not_to have_body_text /unsubscribe/ }
end end
shared_examples 'an email with a labels subscriptions link in its footer' do shared_examples 'an email with a labels subscriptions link in its footer' do
it { is_expected.to have_body_text /label subscriptions/ } it { is_expected.to have_body_text('label subscriptions') }
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment