Commit 7da750cc authored by Marin Jankovski's avatar Marin Jankovski

Specs for links in email notifications for Gmail Actions.

parent ef2bc0f0
...@@ -77,6 +77,14 @@ describe Notify do ...@@ -77,6 +77,14 @@ describe Notify do
end end
end end
shared_examples 'it should have Gmail Actions links' do
it { is_expected.to have_body_text /ViewAction/ }
end
shared_examples 'it should not have Gmail Actions links' do
it { is_expected.to_not have_body_text /ViewAction/ }
end
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 }
let(:new_user) { create(:user, email: new_user_address, created_by_id: 1) } let(:new_user) { create(:user, email: new_user_address, created_by_id: 1) }
...@@ -87,6 +95,7 @@ describe Notify do ...@@ -87,6 +95,7 @@ describe Notify do
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'a new user email', new_user_address it_behaves_like 'a new user email', new_user_address
it_behaves_like 'it should not have Gmail Actions links'
it 'contains the password text' do it 'contains the password text' do
is_expected.to have_body_text /Click here to set your password/ is_expected.to have_body_text /Click here to set your password/
...@@ -115,6 +124,7 @@ describe Notify do ...@@ -115,6 +124,7 @@ describe Notify do
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'a new user email', new_user_address it_behaves_like 'a new user email', new_user_address
it_behaves_like 'it should not have Gmail Actions links'
it 'should not contain the new user\'s password' do it 'should not contain the new user\'s password' do
is_expected.not_to have_body_text /password/ is_expected.not_to have_body_text /password/
...@@ -127,6 +137,7 @@ describe Notify do ...@@ -127,6 +137,7 @@ describe Notify do
subject { Notify.new_ssh_key_email(key.id) } subject { Notify.new_ssh_key_email(key.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it 'is sent to the new user' do it 'is sent to the new user' do
is_expected.to deliver_to key.user.email is_expected.to deliver_to key.user.email
...@@ -150,6 +161,8 @@ describe Notify do ...@@ -150,6 +161,8 @@ describe Notify do
subject { Notify.new_email_email(email.id) } subject { Notify.new_email_email(email.id) }
it_behaves_like 'it should not have Gmail Actions links'
it 'is sent to the new user' do it 'is sent to the new user' do
is_expected.to deliver_to email.user.email is_expected.to deliver_to email.user.email
end end
...@@ -194,6 +207,7 @@ describe Notify do ...@@ -194,6 +207,7 @@ describe Notify do
it_behaves_like 'an assignee email' it_behaves_like 'an assignee email'
it_behaves_like 'an email starting a new thread', 'issue' it_behaves_like 'an email starting a new thread', 'issue'
it_behaves_like 'it should have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /#{project.name} \| #{issue.title} \(##{issue.iid}\)/ is_expected.to have_subject /#{project.name} \| #{issue.title} \(##{issue.iid}\)/
...@@ -202,6 +216,10 @@ describe Notify do ...@@ -202,6 +216,10 @@ describe Notify do
it 'contains a link to the new issue' do it 'contains a link to the new issue' do
is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/ is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Issue/
end
end end
describe 'that are new with a description' do describe 'that are new with a description' do
...@@ -217,6 +235,7 @@ describe Notify do ...@@ -217,6 +235,7 @@ describe Notify do
it_behaves_like 'a multiple recipients email' it_behaves_like 'a multiple recipients email'
it_behaves_like 'an answer to an existing thread', 'issue' it_behaves_like 'an answer to an existing thread', 'issue'
it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
...@@ -239,6 +258,10 @@ describe Notify do ...@@ -239,6 +258,10 @@ describe Notify do
it 'contains a link to the issue' do it 'contains a link to the issue' do
is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/ is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Issue/
end
end end
describe 'status changed' do describe 'status changed' do
...@@ -246,6 +269,7 @@ describe Notify do ...@@ -246,6 +269,7 @@ describe Notify do
subject { Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) } subject { Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) }
it_behaves_like 'an answer to an existing thread', 'issue' it_behaves_like 'an answer to an existing thread', 'issue'
it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
...@@ -268,8 +292,11 @@ describe Notify do ...@@ -268,8 +292,11 @@ describe Notify do
it 'contains a link to the issue' do it 'contains a link to the issue' do
is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/ is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/
end end
end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Issue/
end
end
end end
context 'for merge requests' do context 'for merge requests' do
...@@ -282,6 +309,7 @@ describe Notify do ...@@ -282,6 +309,7 @@ describe Notify do
it_behaves_like 'an assignee email' it_behaves_like 'an assignee email'
it_behaves_like 'an email starting a new thread', 'merge_request' it_behaves_like 'an email starting a new thread', 'merge_request'
it_behaves_like 'it should have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /#{merge_request.title} \(##{merge_request.iid}\)/ is_expected.to have_subject /#{merge_request.title} \(##{merge_request.iid}\)/
...@@ -302,14 +330,24 @@ describe Notify do ...@@ -302,14 +330,24 @@ describe Notify do
it 'has the correct message-id set' do it 'has the correct message-id set' do
is_expected.to have_header 'Message-ID', "<merge_request_#{merge_request.id}@#{Gitlab.config.gitlab.host}>" is_expected.to have_header 'Message-ID', "<merge_request_#{merge_request.id}@#{Gitlab.config.gitlab.host}>"
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Merge request/
end
end end
describe 'that are new with a description' do describe 'that are new with a description' do
subject { Notify.new_merge_request_email(merge_request_with_description.assignee_id, merge_request_with_description.id) } subject { Notify.new_merge_request_email(merge_request_with_description.assignee_id, merge_request_with_description.id) }
it_behaves_like 'it should have Gmail Actions links'
it 'contains the description' do it 'contains the description' do
is_expected.to have_body_text /#{merge_request_with_description.description}/ is_expected.to have_body_text /#{merge_request_with_description.description}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Merge request/
end
end end
describe 'that are reassigned' do describe 'that are reassigned' do
...@@ -317,6 +355,7 @@ describe Notify do ...@@ -317,6 +355,7 @@ describe Notify do
it_behaves_like 'a multiple recipients email' it_behaves_like 'a multiple recipients email'
it_behaves_like 'an answer to an existing thread', 'merge_request' it_behaves_like 'an answer to an existing thread', 'merge_request'
it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
...@@ -339,6 +378,10 @@ describe Notify do ...@@ -339,6 +378,10 @@ describe Notify do
it 'contains a link to the merge request' do 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}/ is_expected.to have_body_text /#{namespace_project_merge_request_path project.namespace, project, merge_request}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Merge request/
end
end end
describe 'status changed' do describe 'status changed' do
...@@ -346,6 +389,8 @@ describe Notify do ...@@ -346,6 +389,8 @@ describe Notify do
subject { Notify.merge_request_status_email(recipient.id, merge_request.id, status, current_user) } subject { Notify.merge_request_status_email(recipient.id, merge_request.id, status, current_user) }
it_behaves_like 'an answer to an existing thread', 'merge_request' it_behaves_like 'an answer to an existing thread', 'merge_request'
it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
...@@ -368,6 +413,10 @@ describe Notify do ...@@ -368,6 +413,10 @@ describe Notify do
it 'contains a link to the merge request' do 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}/ is_expected.to have_body_text /#{namespace_project_merge_request_path project.namespace, project, merge_request}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Merge request/
end
end end
describe 'that are merged' do describe 'that are merged' do
...@@ -375,6 +424,7 @@ describe Notify do ...@@ -375,6 +424,7 @@ describe Notify do
it_behaves_like 'a multiple recipients email' it_behaves_like 'a multiple recipients email'
it_behaves_like 'an answer to an existing thread', 'merge_request' it_behaves_like 'an answer to an existing thread', 'merge_request'
it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the merge author' do it 'is sent as the merge author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
...@@ -393,6 +443,10 @@ describe Notify do ...@@ -393,6 +443,10 @@ describe Notify do
it 'contains a link to the merge request' do 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}/ is_expected.to have_body_text /#{namespace_project_merge_request_path project.namespace, project, merge_request}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Merge request/
end
end end
end end
end end
...@@ -403,6 +457,7 @@ describe Notify do ...@@ -403,6 +457,7 @@ describe Notify do
subject { Notify.project_was_moved_email(project.id, user.id, "gitlab/gitlab") } subject { Notify.project_was_moved_email(project.id, user.id, "gitlab/gitlab") }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /Project was moved/ is_expected.to have_subject /Project was moved/
...@@ -424,13 +479,16 @@ describe Notify do ...@@ -424,13 +479,16 @@ describe Notify do
subject { Notify.project_access_granted_email(project_member.id) } subject { Notify.project_access_granted_email(project_member.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /Access to project was granted/ is_expected.to have_subject /Access to project was granted/
end end
it 'contains name of project' do it 'contains name of project' do
is_expected.to have_body_text /#{project.name}/ is_expected.to have_body_text /#{project.name}/
end end
it 'contains new user role' do it 'contains new user role' do
is_expected.to have_body_text /#{project_member.human_access}/ is_expected.to have_body_text /#{project_member.human_access}/
end end
...@@ -445,6 +503,8 @@ describe Notify do ...@@ -445,6 +503,8 @@ describe Notify do
end end
shared_examples 'a note email' do shared_examples 'a note email' do
it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent 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.display_name).to eq(note_author.name)
...@@ -469,6 +529,7 @@ describe Notify do ...@@ -469,6 +529,7 @@ describe Notify do
it_behaves_like 'a note email' it_behaves_like 'a note email'
it_behaves_like 'an answer to an existing thread', 'commit' it_behaves_like 'an answer to an existing thread', 'commit'
it_behaves_like 'it should have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /#{commit.title} \(#{commit.short_id}\)/ is_expected.to have_subject /#{commit.title} \(#{commit.short_id}\)/
...@@ -477,6 +538,10 @@ describe Notify do ...@@ -477,6 +538,10 @@ describe Notify do
it 'contains a link to the commit' do it 'contains a link to the commit' do
is_expected.to have_body_text commit.short_id is_expected.to have_body_text commit.short_id
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Commit/
end
end end
describe 'on a merge request' do describe 'on a merge request' do
...@@ -488,6 +553,7 @@ describe Notify do ...@@ -488,6 +553,7 @@ describe Notify do
it_behaves_like 'a note email' it_behaves_like 'a note email'
it_behaves_like 'an answer to an existing thread', 'merge_request' it_behaves_like 'an answer to an existing thread', 'merge_request'
it_behaves_like 'it should have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /#{merge_request.title} \(##{merge_request.iid}\)/ is_expected.to have_subject /#{merge_request.title} \(##{merge_request.iid}\)/
...@@ -496,6 +562,10 @@ describe Notify do ...@@ -496,6 +562,10 @@ describe Notify do
it 'contains a link to the merge request note' do it 'contains a link to the merge request note' do
is_expected.to have_body_text /#{note_on_merge_request_path}/ is_expected.to have_body_text /#{note_on_merge_request_path}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Merge request/
end
end end
describe 'on an issue' do describe 'on an issue' do
...@@ -507,6 +577,7 @@ describe Notify do ...@@ -507,6 +577,7 @@ describe Notify do
it_behaves_like 'a note email' it_behaves_like 'a note email'
it_behaves_like 'an answer to an existing thread', 'issue' it_behaves_like 'an answer to an existing thread', 'issue'
it_behaves_like 'it should have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /#{issue.title} \(##{issue.iid}\)/ is_expected.to have_subject /#{issue.title} \(##{issue.iid}\)/
...@@ -515,6 +586,10 @@ describe Notify do ...@@ -515,6 +586,10 @@ describe Notify do
it 'contains a link to the issue note' do it 'contains a link to the issue note' do
is_expected.to have_body_text /#{note_on_issue_path}/ is_expected.to have_body_text /#{note_on_issue_path}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Issue/
end
end end
end end
end end
...@@ -527,6 +602,7 @@ describe Notify do ...@@ -527,6 +602,7 @@ describe Notify do
subject { Notify.group_access_granted_email(membership.id) } subject { Notify.group_access_granted_email(membership.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject /Access to group was granted/ is_expected.to have_subject /Access to group was granted/
...@@ -574,6 +650,8 @@ describe Notify do ...@@ -574,6 +650,8 @@ describe Notify do
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :create) } subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :create) }
it_behaves_like 'it should not have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name) expect(sender.display_name).to eq(user.name)
...@@ -600,6 +678,8 @@ describe Notify do ...@@ -600,6 +678,8 @@ describe Notify do
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/tags/v1.0', action: :create) } subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/tags/v1.0', action: :create) }
it_behaves_like 'it should not have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name) expect(sender.display_name).to eq(user.name)
...@@ -625,6 +705,8 @@ describe Notify do ...@@ -625,6 +705,8 @@ describe Notify do
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :delete) } subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :delete) }
it_behaves_like 'it should not have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name) expect(sender.display_name).to eq(user.name)
...@@ -646,6 +728,8 @@ describe Notify do ...@@ -646,6 +728,8 @@ describe Notify do
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/tags/v1.0', action: :delete) } subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/tags/v1.0', action: :delete) }
it_behaves_like 'it should not have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name) expect(sender.display_name).to eq(user.name)
...@@ -671,6 +755,8 @@ describe Notify do ...@@ -671,6 +755,8 @@ describe Notify do
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare, reverse_compare: false, send_from_committer_email: send_from_committer_email) } subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare, reverse_compare: false, send_from_committer_email: send_from_committer_email) }
it_behaves_like 'it should not have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name) expect(sender.display_name).to eq(user.name)
...@@ -774,6 +860,8 @@ describe Notify do ...@@ -774,6 +860,8 @@ describe Notify do
subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare) } subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare) }
it_behaves_like 'it should have Gmail Actions links'
it 'is sent as the author' do it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name) expect(sender.display_name).to eq(user.name)
...@@ -799,5 +887,9 @@ describe Notify do ...@@ -799,5 +887,9 @@ describe Notify do
it 'contains a link to the diff' do it 'contains a link to the diff' do
is_expected.to have_body_text /#{diff_path}/ is_expected.to have_body_text /#{diff_path}/
end end
it 'Gmail Actions contain correct action name' do
is_expected.to have_body_text /View Commit/
end
end end
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