summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-03-17 15:18:34 +0000
committerDJ Mountney <david@twkie.net>2017-03-17 11:17:30 -0700
commit01ff99cbe5b5dc7c3922149e6b0a2a449f36ab2f (patch)
treec43c6aaaae187b8f71054ed6fa91593792372d02
parent3d58c349e24d67cb653c00c8fd177807a74343cf (diff)
downloadgitlab-ce-01ff99cbe5b5dc7c3922149e6b0a2a449f36ab2f.tar.gz
Merge branch '20121-add-a-new-have_html_escaped_body_text-matcher' into 'master'
Add a new have_html_escaped_body_text that match an HTML-escaped text Closes #20121 See merge request !10015
-rw-r--r--spec/mailers/notify_spec.rb115
-rw-r--r--spec/support/matchers/email_matchers.rb5
2 files changed, 63 insertions, 57 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index b692142713f..581e656dca7 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -54,7 +54,7 @@ describe Notify do
end
it 'contains a link to note author' do
- is_expected.to have_body_text issue.author_name
+ is_expected.to have_html_escaped_body_text issue.author_name
is_expected.to have_body_text /wrote\:/
end
end
@@ -66,7 +66,7 @@ describe Notify do
it_behaves_like 'it should show Gmail Actions View Issue link'
it 'contains the description' do
- is_expected.to have_body_text /#{issue_with_description.description}/
+ is_expected.to have_html_escaped_body_text issue_with_description.description
end
end
@@ -91,11 +91,11 @@ describe Notify do
end
it 'contains the name of the previous assignee' do
- is_expected.to have_body_text /#{previous_assignee.name}/
+ is_expected.to have_html_escaped_body_text previous_assignee.name
end
it 'contains the name of the new assignee' do
- is_expected.to have_body_text /#{assignee.name}/
+ is_expected.to have_html_escaped_body_text assignee.name
end
it 'contains a link to the issue' do
@@ -158,7 +158,7 @@ describe Notify do
end
it 'contains the user name' do
- is_expected.to have_body_text /#{current_user.name}/i
+ is_expected.to have_html_escaped_body_text current_user.name
end
it 'contains a link to the issue' do
@@ -233,7 +233,7 @@ describe Notify do
end
it 'contains a link to note author' do
- is_expected.to have_body_text merge_request.author_name
+ is_expected.to have_html_escaped_body_text merge_request.author_name
is_expected.to have_body_text /wrote\:/
end
end
@@ -246,7 +246,7 @@ describe Notify do
it_behaves_like "an unsubscribeable thread"
it 'contains the description' do
- is_expected.to have_body_text /#{merge_request_with_description.description}/
+ is_expected.to have_html_escaped_body_text merge_request_with_description.description
end
end
@@ -271,11 +271,11 @@ describe Notify do
end
it 'contains the name of the previous assignee' do
- is_expected.to have_body_text /#{previous_assignee.name}/
+ is_expected.to have_html_escaped_body_text previous_assignee.name
end
it 'contains the name of the new assignee' do
- is_expected.to have_body_text /#{assignee.name}/
+ is_expected.to have_html_escaped_body_text assignee.name
end
it 'contains a link to the merge request' do
@@ -338,7 +338,7 @@ describe Notify do
end
it 'contains the user name' do
- is_expected.to have_body_text /#{current_user.name}/i
+ is_expected.to have_html_escaped_body_text current_user.name
end
it 'contains a link to the merge request' do
@@ -391,7 +391,7 @@ describe Notify do
end
it 'contains name of project' do
- is_expected.to have_body_text /#{project.name_with_namespace}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
end
it 'contains new user role' do
@@ -424,9 +424,9 @@ describe Notify do
expect(to_emails[0].address).to eq(project.members.owners_and_masters.first.user.notification_email)
is_expected.to have_subject "Request to join the #{project.name_with_namespace} project"
- is_expected.to have_body_text /#{project.name_with_namespace}/
- is_expected.to have_body_text /#{namespace_project_project_members_url(project.namespace, project)}/
- is_expected.to have_body_text /#{project_member.human_access}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
+ is_expected.to have_body_text namespace_project_project_members_url(project.namespace, project)
+ is_expected.to have_body_text project_member.human_access
end
end
@@ -451,9 +451,9 @@ describe Notify do
expect(to_emails[0].address).to eq(group.members.owners_and_masters.first.user.notification_email)
is_expected.to have_subject "Request to join the #{project.name_with_namespace} project"
- is_expected.to have_body_text /#{project.name_with_namespace}/
- is_expected.to have_body_text /#{namespace_project_project_members_url(project.namespace, project)}/
- is_expected.to have_body_text /#{project_member.human_access}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
+ is_expected.to have_body_text namespace_project_project_members_url(project.namespace, project)
+ is_expected.to have_body_text project_member.human_access
end
end
end
@@ -473,13 +473,14 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject "Access to the #{project.name_with_namespace} project was denied"
- is_expected.to have_body_text /#{project.name_with_namespace}/
- is_expected.to have_body_text /#{project.web_url}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
+ is_expected.to have_body_text project.web_url
end
end
describe 'project access changed' do
- let(:project) { create(:empty_project, :public, :access_requestable) }
+ let(:owner) { create(:user, name: "Chang O'Keefe") }
+ let(:project) { create(:empty_project, :public, :access_requestable, namespace: owner.namespace) }
let(:user) { create(:user) }
let(:project_member) { create(:project_member, project: project, user: user) }
subject { Notify.member_access_granted_email('project', project_member.id) }
@@ -490,9 +491,9 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject "Access to the #{project.name_with_namespace} project was granted"
- is_expected.to have_body_text /#{project.name_with_namespace}/
- is_expected.to have_body_text /#{project.web_url}/
- is_expected.to have_body_text /#{project_member.human_access}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
+ is_expected.to have_body_text project.web_url
+ is_expected.to have_body_text project_member.human_access
end
end
@@ -521,10 +522,10 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject "Invitation to join the #{project.name_with_namespace} project"
- is_expected.to have_body_text /#{project.name_with_namespace}/
- is_expected.to have_body_text /#{project.web_url}/
- is_expected.to have_body_text /#{project_member.human_access}/
- is_expected.to have_body_text /#{project_member.invite_token}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
+ is_expected.to have_body_text project.web_url
+ is_expected.to have_body_text project_member.human_access
+ is_expected.to have_body_text project_member.invite_token
end
end
@@ -546,10 +547,10 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject 'Invitation accepted'
- is_expected.to have_body_text /#{project.name_with_namespace}/
- is_expected.to have_body_text /#{project.web_url}/
- is_expected.to have_body_text /#{project_member.invite_email}/
- is_expected.to have_body_text /#{invited_user.name}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
+ is_expected.to have_body_text project.web_url
+ is_expected.to have_body_text project_member.invite_email
+ is_expected.to have_html_escaped_body_text invited_user.name
end
end
@@ -570,9 +571,9 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject 'Invitation declined'
- is_expected.to have_body_text /#{project.name_with_namespace}/
- is_expected.to have_body_text /#{project.web_url}/
- is_expected.to have_body_text /#{project_member.invite_email}/
+ is_expected.to have_html_escaped_body_text project.name_with_namespace
+ is_expected.to have_body_text project.web_url
+ is_expected.to have_body_text project_member.invite_email
end
end
@@ -598,7 +599,7 @@ describe Notify do
end
it 'contains the message from the note' do
- is_expected.to have_body_text /#{note.note}/
+ is_expected.to have_html_escaped_body_text note.note
end
it 'does not contain note author' do
@@ -611,7 +612,7 @@ describe Notify do
end
it 'contains a link to note author' do
- is_expected.to have_body_text note.author_name
+ is_expected.to have_html_escaped_body_text note.author_name
is_expected.to have_body_text /wrote\:/
end
end
@@ -718,7 +719,7 @@ describe Notify do
end
it 'contains the message from the note' do
- is_expected.to have_body_text /#{note.note}/
+ is_expected.to have_html_escaped_body_text note.note
end
it 'does not contain note author' do
@@ -731,7 +732,7 @@ describe Notify do
end
it 'contains a link to note author' do
- is_expected.to have_body_text note.author_name
+ is_expected.to have_html_escaped_body_text note.author_name
is_expected.to have_body_text /wrote\:/
end
end
@@ -777,9 +778,9 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject "Request to join the #{group.name} group"
- is_expected.to have_body_text /#{group.name}/
- is_expected.to have_body_text /#{group_group_members_url(group)}/
- is_expected.to have_body_text /#{group_member.human_access}/
+ is_expected.to have_html_escaped_body_text group.name
+ is_expected.to have_body_text group_group_members_url(group)
+ is_expected.to have_body_text group_member.human_access
end
end
@@ -798,8 +799,8 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject "Access to the #{group.name} group was denied"
- is_expected.to have_body_text /#{group.name}/
- is_expected.to have_body_text /#{group.web_url}/
+ is_expected.to have_html_escaped_body_text group.name
+ is_expected.to have_body_text group.web_url
end
end
@@ -816,9 +817,9 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject "Access to the #{group.name} group was granted"
- is_expected.to have_body_text /#{group.name}/
- is_expected.to have_body_text /#{group.web_url}/
- is_expected.to have_body_text /#{group_member.human_access}/
+ is_expected.to have_html_escaped_body_text group.name
+ is_expected.to have_body_text group.web_url
+ is_expected.to have_body_text group_member.human_access
end
end
@@ -847,10 +848,10 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject "Invitation to join the #{group.name} group"
- is_expected.to have_body_text /#{group.name}/
- is_expected.to have_body_text /#{group.web_url}/
- is_expected.to have_body_text /#{group_member.human_access}/
- is_expected.to have_body_text /#{group_member.invite_token}/
+ is_expected.to have_html_escaped_body_text group.name
+ is_expected.to have_body_text group.web_url
+ is_expected.to have_body_text group_member.human_access
+ is_expected.to have_body_text group_member.invite_token
end
end
@@ -872,10 +873,10 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject 'Invitation accepted'
- is_expected.to have_body_text /#{group.name}/
- is_expected.to have_body_text /#{group.web_url}/
- is_expected.to have_body_text /#{group_member.invite_email}/
- is_expected.to have_body_text /#{invited_user.name}/
+ is_expected.to have_html_escaped_body_text group.name
+ is_expected.to have_body_text group.web_url
+ is_expected.to have_body_text group_member.invite_email
+ is_expected.to have_html_escaped_body_text invited_user.name
end
end
@@ -896,9 +897,9 @@ describe Notify do
it 'contains all the useful information' do
is_expected.to have_subject 'Invitation declined'
- is_expected.to have_body_text /#{group.name}/
- is_expected.to have_body_text /#{group.web_url}/
- is_expected.to have_body_text /#{group_member.invite_email}/
+ is_expected.to have_html_escaped_body_text group.name
+ is_expected.to have_body_text group.web_url
+ is_expected.to have_body_text group_member.invite_email
end
end
end
diff --git a/spec/support/matchers/email_matchers.rb b/spec/support/matchers/email_matchers.rb
new file mode 100644
index 00000000000..d9d59ec12ec
--- /dev/null
+++ b/spec/support/matchers/email_matchers.rb
@@ -0,0 +1,5 @@
+RSpec::Matchers.define :have_html_escaped_body_text do |expected|
+ match do |actual|
+ expect(actual).to have_body_text(ERB::Util.html_escape(expected))
+ end
+end