BigW Consortium Gitlab

profile_spec.rb 3.63 KB
Newer Older
1 2 3
require 'spec_helper'
require 'email_spec'

4
describe Emails::Profile do
5 6 7
  include EmailSpec::Matchers
  include_context 'gitlab email notification'

8 9 10 11 12 13 14 15 16 17
  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

18 19 20 21
  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) }
    let(:token) { 'kETLwRaayvigPq_x3SNM' }
22

23
    subject { Notify.new_user_email(new_user.id, token) }
24

25 26 27 28
    it_behaves_like 'an email sent from GitLab'
    it_behaves_like 'a new user email'
    it_behaves_like 'it should not have Gmail Actions links'
    it_behaves_like 'a user cannot unsubscribe through footer link'
29

30 31 32
    it 'contains the password text' do
      is_expected.to have_body_text /Click here to set your password/
    end
33

34 35 36 37 38 39
    it 'includes a link for user to set password' do
      params = "reset_password_token=#{token}"
      is_expected.to have_body_text(
        %r{http://#{Gitlab.config.gitlab.host}(:\d+)?/users/password/edit\?#{params}}
      )
    end
40

41 42 43 44
    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(new_user_password_url)
      is_expected.to have_body_text(/\?user_email=.*%40.*/)
45
    end
46
  end
47

48 49 50
  describe 'for users that signed up, the email' do
    let(:example_site_path) { root_path }
    let(:new_user) { create(:user, email: new_user_address, password: "securePassword") }
51

52
    subject { Notify.new_user_email(new_user.id) }
53

54 55 56 57
    it_behaves_like 'an email sent from GitLab'
    it_behaves_like 'a new user email'
    it_behaves_like 'it should not have Gmail Actions links'
    it_behaves_like 'a user cannot unsubscribe through footer link'
58

59 60
    it 'does not contain the new user\'s password' do
      is_expected.not_to have_body_text /password/
61
    end
62
  end
63

64 65
  describe 'user added ssh key' do
    let(:key) { create(:personal_key) }
66

67
    subject { Notify.new_ssh_key_email(key.id) }
68

69 70 71
    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'
72

73 74 75
    it 'is sent to the new user' do
      is_expected.to deliver_to key.user.email
    end
76

77 78 79
    it 'has the correct subject' do
      is_expected.to have_subject /^SSH key was added to your account$/i
    end
80

81 82 83
    it 'contains the new ssh key title' do
      is_expected.to have_body_text /#{key.title}/
    end
84

85 86 87
    it 'includes a link to ssh keys page' do
      is_expected.to have_body_text /#{profile_keys_path}/
    end
88

89 90
    context 'with SSH key that does not exist' do
      it { expect { Notify.new_ssh_key_email('foo') }.not_to raise_error }
91
    end
92
  end
93

94 95
  describe 'user added email' do
    let(:email) { create(:email) }
96

97
    subject { Notify.new_email_email(email.id) }
98

99 100
    it_behaves_like 'it should not have Gmail Actions links'
    it_behaves_like 'a user cannot unsubscribe through footer link'
101

102 103 104
    it 'is sent to the new user' do
      is_expected.to deliver_to email.user.email
    end
105

106 107 108
    it 'has the correct subject' do
      is_expected.to have_subject /^Email was added to your account$/i
    end
109

110 111 112
    it 'contains the new email address' do
      is_expected.to have_body_text /#{email.email}/
    end
113

114 115
    it 'includes a link to emails page' do
      is_expected.to have_body_text /#{profile_emails_path}/
116 117 118
    end
  end
end