Commit 56e06b03 authored by Vinnie Okada's avatar Vinnie Okada

Add tests for password reset token changes

parent af428b12
...@@ -5,6 +5,8 @@ describe Notify do ...@@ -5,6 +5,8 @@ describe Notify do
include EmailSpec::Matchers include EmailSpec::Matchers
include RepoHelpers include RepoHelpers
new_user_address = 'newguy@example.com'
let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name } let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name }
let(:gitlab_sender) { Gitlab.config.gitlab.email_from } let(:gitlab_sender) { Gitlab.config.gitlab.email_from }
let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to } let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to }
...@@ -55,18 +57,9 @@ describe Notify do ...@@ -55,18 +57,9 @@ describe Notify do
end end
end end
describe 'for new users, the email' do shared_examples 'a new user email' do |user_email, site_path|
let(:example_site_path) { root_path }
let(:new_user) { create(:user, email: 'newguy@example.com', created_by_id: 1) }
token = 'kETLwRaayvigPq_x3SNM'
subject { Notify.new_user_email(new_user.id, token) }
it_behaves_like 'an email sent from GitLab'
it 'is sent to the new user' do it 'is sent to the new user' do
is_expected.to deliver_to new_user.email is_expected.to deliver_to user_email
end end
it 'has the correct subject' do it 'has the correct subject' do
...@@ -74,9 +67,25 @@ describe Notify do ...@@ -74,9 +67,25 @@ describe Notify do
end end
it 'contains the new user\'s login name' do it 'contains the new user\'s login name' do
is_expected.to have_body_text /#{new_user.email}/ is_expected.to have_body_text /#{user_email}/
end end
it 'includes a link to the site' do
is_expected.to have_body_text /#{site_path}/
end
end
describe 'for new users, the email' do
let(:example_site_path) { root_path }
let(:new_user) { create(:user, email: new_user_address, created_by_id: 1) }
token = 'kETLwRaayvigPq_x3SNM'
subject { Notify.new_user_email(new_user.id, token) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'a new user email', new_user_address
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/
end end
...@@ -88,44 +97,26 @@ describe Notify do ...@@ -88,44 +97,26 @@ describe Notify do
) )
end end
it 'includes a link to the site' do
is_expected.to have_body_text /#{example_site_path}/
end
it 'explains the reset link expiration' do it 'explains the reset link expiration' do
is_expected.to have_body_text(/This link is valid for \d+ (hours?|days?)/) is_expected.to have_body_text(/This link is valid for \d+ (hours?|days?)/)
is_expected.to have_body_text(new_user_password_url) is_expected.to have_body_text(new_user_password_url)
is_expected.to have_body_text(/\?user_email=.*%40.*/)
end end
end end
describe 'for users that signed up, the email' do describe 'for users that signed up, the email' do
let(:example_site_path) { root_path } let(:example_site_path) { root_path }
let(:new_user) { create(:user, email: 'newguy@example.com', password: "securePassword") } let(:new_user) { create(:user, email: new_user_address, password: "securePassword") }
subject { Notify.new_user_email(new_user.id) } subject { Notify.new_user_email(new_user.id) }
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 'is sent to the new user' do
is_expected.to deliver_to new_user.email
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.email}/
end
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/
end end
it 'includes a link to the site' do
is_expected.to have_body_text /#{example_site_path}/
end
end end
describe 'user added ssh key' do describe 'user added ssh key' do
......
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