-
Notifications
You must be signed in to change notification settings - Fork 342
/
Copy pathsign_up_spec.rb
142 lines (114 loc) · 4.76 KB
/
sign_up_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require 'rails_helper'
describe 'Signing up for a new admin account' do
it 'with all required fields present and valid' do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
expect(page).to have_content 'activate your account'
expect(page).to have_content('Admin')
expect(page).to have_current_path(new_admin_session_path, ignore_query: true)
end
it 'with custom confirmation email address' do
reset_email
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
expect(first_email.from.first).to eq('[email protected]')
end
it 'with custom mailer' do
reset_email
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
expect(first_email.body).to include('Admin')
expect(first_email.body).to include('/admin')
expect(first_email.body).not_to include('documentation')
end
it 'with name missing' do
sign_up_admin('', '[email protected]', 'ohanatest', 'ohanatest')
expect(page).to have_content "Name can't be blank"
end
it 'with email missing' do
sign_up_admin('Moncef', '', 'ohanatest', 'ohanatest')
expect(page).to have_content "Email can't be blank"
end
it 'with password missing' do
sign_up_admin('Moncef', '[email protected]', '', 'ohanatest')
expect(page).to have_content "Password can't be blank"
end
it 'with password confirmation missing' do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', '')
expect(page).to have_content "Password confirmation doesn't match Password"
end
it "when password and confirmation don't match" do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohana')
expect(page).to have_content "Password confirmation doesn't match Password"
end
context 'when signing up with existing email', email: true do
before do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
end
def portal_name
I18n.t('titles.admin', brand: I18n.t('titles.brand'))
end
it 'does not reveal that the email has already been taken' do
expect(page).not_to have_content 'Email has already been taken'
end
it 'redirects back to admin portal sign in page' do
expect(page).to have_current_path new_admin_session_path, ignore_query: true
end
it 'sends an email to the user informing them of sign up' do
expect(last_email.body).to include 'email address is already in use'
end
it 'mentions the admin portal' do
expect(last_email.body).to include portal_name
end
it 'links to the admin sign in page' do
expect(last_email.body).to have_link new_admin_session_path
end
it 'links to the admin sign up page' do
expect(last_email.body).
to have_link 'sign up', href: 'http://example.com/admin/sign_up'
end
it 'links to the admin reset password page' do
expect(last_email.body).
to have_link 'resetting your password', href: 'http://example.com/admin/password/new'
end
it 'mentions the admin portal in the email subject' do
expect(last_email.subject).to eq "Request to sign up on #{portal_name}"
end
end
describe 'duplicate email along with other validation errors' do
shared_examples 'does not reveal existing email' do
it 'does not display duplicate email error' do
expect(page).not_to have_content 'Email has already been taken'
end
it 'does not send an email', email: true do
expect(ActionMailer::Base.deliveries.size).to eq 1
end
end
context 'when duplicate email and name is missing during sign up' do
before do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
sign_up_admin('', '[email protected]', 'ohanatest', 'ohanatest')
end
it_behaves_like 'does not reveal existing email'
end
context 'when duplicate email and password is missing during sign up' do
before do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
sign_up_admin('', '[email protected]', '', 'ohanatest')
end
it_behaves_like 'does not reveal existing email'
end
context 'when duplicate email and password_confirmation invalid during sign up' do
before do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
sign_up_admin('Moncef', '[email protected]', 'ohanatest', '')
end
it_behaves_like 'does not reveal existing email'
end
context 'when duplicate email and password is too short during sign up' do
before do
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
sign_up_admin('Moncef', '[email protected]', 'foo', 'foo')
end
it_behaves_like 'does not reveal existing email'
end
end
end