clearance 1.4.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/Gemfile.lock +90 -85
- data/NEWS.md +5 -0
- data/README.md +26 -8
- data/config/routes.rb +20 -18
- data/db/schema.rb +4 -4
- data/features/copy_routes_to_host_application.feature +9 -0
- data/lib/clearance/configuration.rb +6 -1
- data/lib/clearance/version.rb +1 -1
- data/lib/generators/clearance/routes/routes_generator.rb +23 -0
- data/lib/generators/clearance/routes/templates/routes.rb +12 -0
- data/spec/clearance/back_door_spec.rb +4 -4
- data/spec/clearance/rack_session_spec.rb +3 -3
- data/spec/clearance/session_spec.rb +47 -25
- data/spec/configuration_spec.rb +22 -11
- data/spec/controllers/apis_controller_spec.rb +1 -1
- data/spec/controllers/forgeries_controller_spec.rb +3 -3
- data/spec/controllers/passwords_controller_spec.rb +38 -35
- data/spec/controllers/permissions_controller_spec.rb +5 -5
- data/spec/controllers/sessions_controller_spec.rb +4 -4
- data/spec/controllers/users_controller_spec.rb +8 -8
- data/spec/mailers/clearance_mailer_spec.rb +6 -6
- data/spec/models/bcrypt_migration_from_sha1_spec.rb +12 -12
- data/spec/models/bcrypt_spec.rb +5 -5
- data/spec/models/blowfish_spec.rb +3 -3
- data/spec/models/password_strategies_spec.rb +2 -2
- data/spec/models/sha1_spec.rb +4 -4
- data/spec/models/user_spec.rb +38 -38
- data/spec/routing/clearance_routes_spec.rb +31 -6
- data/spec/spec_helper.rb +1 -0
- data/spec/support/cookies.rb +4 -4
- metadata +6 -4
- data/spec/controllers/flashes_controller_spec.rb +0 -32
@@ -1,6 +1,6 @@
|
|
1
1
|
module Clearance
|
2
2
|
class Configuration
|
3
|
-
attr_writer :allow_sign_up
|
3
|
+
attr_writer :allow_sign_up, :routes
|
4
4
|
|
5
5
|
attr_accessor \
|
6
6
|
:cookie_domain,
|
@@ -21,6 +21,7 @@ module Clearance
|
|
21
21
|
@httponly = false
|
22
22
|
@mailer_sender = 'reply@example.com'
|
23
23
|
@redirect_url = '/'
|
24
|
+
@routes = true
|
24
25
|
@secure_cookie = false
|
25
26
|
@sign_in_guards = []
|
26
27
|
end
|
@@ -44,6 +45,10 @@ module Clearance
|
|
44
45
|
def user_id_parameter
|
45
46
|
"#{user_model.model_name.singular}_id".to_sym
|
46
47
|
end
|
48
|
+
|
49
|
+
def routes_enabled?
|
50
|
+
@routes
|
51
|
+
end
|
47
52
|
end
|
48
53
|
|
49
54
|
def self.configuration
|
data/lib/clearance/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Clearance
|
4
|
+
module Generators
|
5
|
+
class RoutesGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def inject_clearance_routes_into_application_routes
|
9
|
+
route(clearance_routes)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def clearance_routes
|
15
|
+
File.read(routes_file_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def routes_file_path
|
19
|
+
File.expand_path(find_in_source_paths('routes.rb'))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
resources :passwords, controller: 'clearance/passwords', only: [:create, :new]
|
2
|
+
resource :session, controller: 'clearance/sessions', only: [:create]
|
3
|
+
|
4
|
+
resources :users, controller: 'clearance/users', only: [:create] do
|
5
|
+
resource :password,
|
6
|
+
controller: 'clearance/passwords',
|
7
|
+
only: [:create, :edit, :update]
|
8
|
+
end
|
9
|
+
|
10
|
+
get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'
|
11
|
+
delete '/sign_out' => 'clearance/sessions#destroy', as: 'sign_out'
|
12
|
+
get '/sign_up' => 'clearance/users#new', as: 'sign_up'
|
@@ -10,8 +10,8 @@ describe Clearance::BackDoor do
|
|
10
10
|
|
11
11
|
result = back_door.call(env)
|
12
12
|
|
13
|
-
env[:clearance].
|
14
|
-
result.
|
13
|
+
expect(env[:clearance]).to have_received(:sign_in).with(user)
|
14
|
+
expect(result).to eq mock_app.call(env)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'delegates directly without a user' do
|
@@ -20,8 +20,8 @@ describe Clearance::BackDoor do
|
|
20
20
|
|
21
21
|
result = back_door.call(env)
|
22
22
|
|
23
|
-
env[:clearance].
|
24
|
-
result.
|
23
|
+
expect(env[:clearance]).to have_received(:sign_in).never
|
24
|
+
expect(result).to eq mock_app.call(env)
|
25
25
|
end
|
26
26
|
|
27
27
|
def env_without_user_id
|
@@ -16,9 +16,9 @@ describe Clearance::RackSession do
|
|
16
16
|
|
17
17
|
response = Rack::MockResponse.new(*app.call(env))
|
18
18
|
|
19
|
-
Clearance::Session.
|
20
|
-
response.body.
|
21
|
-
expected_session.
|
19
|
+
expect(Clearance::Session).to have_received(:new).with(env)
|
20
|
+
expect(response.body).to eq expected_session
|
21
|
+
expect(expected_session).to have_received(:add_cookie_to_headers).
|
22
22
|
with(has_entries(headers))
|
23
23
|
end
|
24
24
|
end
|
@@ -4,7 +4,7 @@ describe Clearance::Session do
|
|
4
4
|
before { Timecop.freeze }
|
5
5
|
after { Timecop.return }
|
6
6
|
|
7
|
-
let(:headers) {{}}
|
7
|
+
let(:headers) { {} }
|
8
8
|
let(:session) { Clearance::Session.new(env_without_remember_token) }
|
9
9
|
let(:user) { create(:user) }
|
10
10
|
|
@@ -12,20 +12,22 @@ describe Clearance::Session do
|
|
12
12
|
user = create(:user)
|
13
13
|
env = env_with_remember_token(user.remember_token)
|
14
14
|
session = Clearance::Session.new(env)
|
15
|
-
|
16
|
-
session.
|
15
|
+
|
16
|
+
expect(session).to be_signed_in
|
17
|
+
expect(session.current_user).to eq user
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'returns nil for an unknown user' do
|
20
21
|
env = env_with_remember_token('bogus')
|
21
22
|
session = Clearance::Session.new(env)
|
22
|
-
|
23
|
-
session.
|
23
|
+
|
24
|
+
expect(session).to be_signed_out
|
25
|
+
expect(session.current_user).to be_nil
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'returns nil without a remember token' do
|
27
|
-
session.
|
28
|
-
session.current_user.
|
29
|
+
expect(session).to be_signed_out
|
30
|
+
expect(session.current_user).to be_nil
|
29
31
|
end
|
30
32
|
|
31
33
|
describe '#sign_in' do
|
@@ -109,13 +111,15 @@ describe Clearance::Session do
|
|
109
111
|
|
110
112
|
def stub_default_sign_in_guard
|
111
113
|
stub(:default_sign_in_guard).tap do |sign_in_guard|
|
112
|
-
Clearance::DefaultSignInGuard.stubs(:new).with(session).
|
114
|
+
Clearance::DefaultSignInGuard.stubs(:new).with(session).
|
115
|
+
returns(sign_in_guard)
|
113
116
|
end
|
114
117
|
end
|
115
118
|
|
116
119
|
def stub_guard_class(guard)
|
117
120
|
stub(:guard_class).tap do |guard_class|
|
118
|
-
guard_class.stubs(:new).with(session, stub_default_sign_in_guard).
|
121
|
+
guard_class.stubs(:new).with(session, stub_default_sign_in_guard).
|
122
|
+
returns(guard)
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
@@ -138,7 +142,7 @@ describe Clearance::Session do
|
|
138
142
|
it 'sets a httponly cookie' do
|
139
143
|
session.add_cookie_to_headers(headers)
|
140
144
|
|
141
|
-
headers['Set-Cookie'].
|
145
|
+
expect(headers['Set-Cookie']).to match(/remember_token=.+; HttpOnly/)
|
142
146
|
end
|
143
147
|
|
144
148
|
after { restore_default_config }
|
@@ -152,7 +156,7 @@ describe Clearance::Session do
|
|
152
156
|
it 'sets a standard cookie' do
|
153
157
|
session.add_cookie_to_headers(headers)
|
154
158
|
|
155
|
-
headers['Set-Cookie'].
|
159
|
+
expect(headers['Set-Cookie']).not_to match(/remember_token=.+; HttpOnly/)
|
156
160
|
end
|
157
161
|
end
|
158
162
|
|
@@ -164,7 +168,11 @@ describe Clearance::Session do
|
|
164
168
|
session = Clearance::Session.new(env_without_remember_token)
|
165
169
|
session.sign_in user
|
166
170
|
session.add_cookie_to_headers headers
|
167
|
-
|
171
|
+
|
172
|
+
expect(headers).to set_cookie(
|
173
|
+
'remember_token',
|
174
|
+
user.remember_token, 1.year.from_now
|
175
|
+
)
|
168
176
|
end
|
169
177
|
end
|
170
178
|
|
@@ -175,6 +183,7 @@ describe Clearance::Session do
|
|
175
183
|
session = Clearance::Session.new(env_without_remember_token)
|
176
184
|
session.stubs(:warn)
|
177
185
|
session.add_cookie_to_headers headers
|
186
|
+
|
178
187
|
expect(session).to have_received(:warn).once
|
179
188
|
end
|
180
189
|
end
|
@@ -188,7 +197,11 @@ describe Clearance::Session do
|
|
188
197
|
session.sign_in user
|
189
198
|
session.stubs(:warn)
|
190
199
|
session.add_cookie_to_headers headers
|
191
|
-
|
200
|
+
|
201
|
+
expect(headers).to set_cookie(
|
202
|
+
'remember_token',
|
203
|
+
user.remember_token, expires_at.call
|
204
|
+
)
|
192
205
|
end
|
193
206
|
end
|
194
207
|
end
|
@@ -196,14 +209,23 @@ describe Clearance::Session do
|
|
196
209
|
context 'configured with lambda taking one argument' do
|
197
210
|
it 'it can use other cookies to set the value of the expires token' do
|
198
211
|
remembered_expires = 12.hours.from_now
|
199
|
-
expires_at = ->(cookies)
|
212
|
+
expires_at = ->(cookies) do
|
213
|
+
cookies['remember_me'] ? remembered_expires : nil
|
214
|
+
end
|
200
215
|
with_custom_expiration expires_at do
|
201
216
|
user = stub('User', remember_token: '123abc')
|
202
217
|
headers = {}
|
203
|
-
|
218
|
+
environment = env_with_cookies(remember_me: 'true')
|
219
|
+
session = Clearance::Session.new(environment)
|
204
220
|
session.sign_in user
|
205
221
|
session.add_cookie_to_headers headers
|
206
|
-
|
222
|
+
|
223
|
+
expect(headers).to set_cookie(
|
224
|
+
'remember_token',
|
225
|
+
user.remember_token,
|
226
|
+
remembered_expires
|
227
|
+
)
|
228
|
+
|
207
229
|
end
|
208
230
|
end
|
209
231
|
end
|
@@ -218,7 +240,7 @@ describe Clearance::Session do
|
|
218
240
|
it 'sets a standard cookie' do
|
219
241
|
session.add_cookie_to_headers(headers)
|
220
242
|
|
221
|
-
headers['Set-Cookie'].
|
243
|
+
expect(headers['Set-Cookie']).not_to match(/remember_token=.+; secure/)
|
222
244
|
end
|
223
245
|
end
|
224
246
|
|
@@ -231,7 +253,7 @@ describe Clearance::Session do
|
|
231
253
|
it 'sets a secure cookie' do
|
232
254
|
session.add_cookie_to_headers(headers)
|
233
255
|
|
234
|
-
headers['Set-Cookie'].
|
256
|
+
expect(headers['Set-Cookie']).to match(/remember_token=.+; secure/)
|
235
257
|
end
|
236
258
|
|
237
259
|
after { restore_default_config }
|
@@ -248,7 +270,7 @@ describe Clearance::Session do
|
|
248
270
|
it 'sets a standard cookie' do
|
249
271
|
session.add_cookie_to_headers(headers)
|
250
272
|
|
251
|
-
headers['Set-Cookie'].
|
273
|
+
expect(headers['Set-Cookie']).to match(/domain=\.example\.com; path/)
|
252
274
|
end
|
253
275
|
|
254
276
|
after { restore_default_config }
|
@@ -260,7 +282,7 @@ describe Clearance::Session do
|
|
260
282
|
it 'sets a standard cookie' do
|
261
283
|
session.add_cookie_to_headers(headers)
|
262
284
|
|
263
|
-
headers['Set-Cookie'].
|
285
|
+
expect(headers['Set-Cookie']).not_to match(/domain=.+; path/)
|
264
286
|
end
|
265
287
|
end
|
266
288
|
end
|
@@ -272,7 +294,7 @@ describe Clearance::Session do
|
|
272
294
|
it 'sets a standard cookie' do
|
273
295
|
session.add_cookie_to_headers(headers)
|
274
296
|
|
275
|
-
headers['Set-Cookie'].
|
297
|
+
expect(headers['Set-Cookie']).to_not match(/domain=.+; path/)
|
276
298
|
end
|
277
299
|
end
|
278
300
|
|
@@ -285,7 +307,7 @@ describe Clearance::Session do
|
|
285
307
|
it 'sets a standard cookie' do
|
286
308
|
session.add_cookie_to_headers(headers)
|
287
309
|
|
288
|
-
headers['Set-Cookie'].
|
310
|
+
expect(headers['Set-Cookie']).to match(/path=\/user; expires/)
|
289
311
|
end
|
290
312
|
|
291
313
|
after { restore_default_config }
|
@@ -296,7 +318,7 @@ describe Clearance::Session do
|
|
296
318
|
headers = {}
|
297
319
|
session = Clearance::Session.new(env_without_remember_token)
|
298
320
|
session.add_cookie_to_headers headers
|
299
|
-
headers.
|
321
|
+
expect(headers).not_to set_cookie('remember_token')
|
300
322
|
end
|
301
323
|
|
302
324
|
it 'signs out a user' do
|
@@ -305,8 +327,8 @@ describe Clearance::Session do
|
|
305
327
|
env = env_with_remember_token(old_remember_token)
|
306
328
|
session = Clearance::Session.new(env)
|
307
329
|
session.sign_out
|
308
|
-
session.current_user.
|
309
|
-
user.reload.remember_token.
|
330
|
+
expect(session.current_user).to be_nil
|
331
|
+
expect(user.reload.remember_token).not_to eq old_remember_token
|
310
332
|
end
|
311
333
|
|
312
334
|
def env_with_cookies(cookies)
|
data/spec/configuration_spec.rb
CHANGED
@@ -36,7 +36,7 @@ describe Clearance::Configuration do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'returns true' do
|
39
|
-
expect(Clearance.configuration.secure_cookie).to
|
39
|
+
expect(Clearance.configuration.secure_cookie).to eq true
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -47,12 +47,12 @@ describe Clearance::Configuration do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'defaults to false' do
|
50
|
-
expect(Clearance.configuration.secure_cookie).to
|
50
|
+
expect(Clearance.configuration.secure_cookie).to eq false
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
context 'when no redirect URL specified' do
|
55
|
-
it '
|
55
|
+
it 'returns "/" as redirect URL' do
|
56
56
|
expect(Clearance::Configuration.new.redirect_url).to eq '/'
|
57
57
|
end
|
58
58
|
end
|
@@ -66,7 +66,7 @@ describe Clearance::Configuration do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
it '
|
69
|
+
it 'returns new redirect URL' do
|
70
70
|
expect(Clearance.configuration.redirect_url).to eq new_redirect_url
|
71
71
|
end
|
72
72
|
end
|
@@ -80,7 +80,7 @@ describe Clearance::Configuration do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
it '
|
83
|
+
it 'returns the stack with added guards' do
|
84
84
|
expect(Clearance.configuration.sign_in_guards).to eq [DummyGuard]
|
85
85
|
end
|
86
86
|
end
|
@@ -113,17 +113,17 @@ describe Clearance::Configuration do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
describe '#
|
116
|
+
describe '#allow_sign_up?' do
|
117
117
|
context 'when allow_sign_up is configured to false' do
|
118
118
|
it 'returns false' do
|
119
119
|
Clearance.configure { |config| config.allow_sign_up = false }
|
120
|
-
Clearance.configuration.allow_sign_up
|
120
|
+
expect(Clearance.configuration.allow_sign_up?).to eq false
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'when allow_sign_up has not been configured' do
|
125
125
|
it 'returns true' do
|
126
|
-
Clearance.configuration.allow_sign_up
|
126
|
+
expect(Clearance.configuration.allow_sign_up?).to eq true
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -132,13 +132,13 @@ describe Clearance::Configuration do
|
|
132
132
|
context 'when allow_sign_up is configured to false' do
|
133
133
|
it 'returns empty array' do
|
134
134
|
Clearance.configure { |config| config.allow_sign_up = false }
|
135
|
-
Clearance.configuration.user_actions.
|
135
|
+
expect(Clearance.configuration.user_actions).to eq []
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
139
|
context 'when sign_up has not been configured' do
|
140
140
|
it 'returns create' do
|
141
|
-
Clearance.configuration.user_actions.
|
141
|
+
expect(Clearance.configuration.user_actions).to eq [:create]
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
@@ -148,7 +148,18 @@ describe Clearance::Configuration do
|
|
148
148
|
CustomUser = Class.new(ActiveRecord::Base)
|
149
149
|
Clearance.configure { |config| config.user_model = CustomUser }
|
150
150
|
|
151
|
-
Clearance.configuration.user_id_parameter.
|
151
|
+
expect(Clearance.configuration.user_id_parameter).to eq :custom_user_id
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#routes_enabled?' do
|
156
|
+
it 'is true by default' do
|
157
|
+
expect(Clearance.configuration.routes_enabled?).to be true
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'is false when routes are set to false' do
|
161
|
+
Clearance.configure { |config| config.routes = false }
|
162
|
+
expect(Clearance.configuration.routes_enabled?).to be false
|
152
163
|
end
|
153
164
|
end
|
154
165
|
end
|
@@ -34,17 +34,17 @@ describe ForgeriesController do
|
|
34
34
|
|
35
35
|
it 'succeeds with authentic token' do
|
36
36
|
post :create, authenticity_token: 'golden-ticket'
|
37
|
-
subject.
|
37
|
+
expect(subject).to redirect_to(action: 'index')
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'fails with invalid token' do
|
41
41
|
post :create, authenticity_token: 'hax0r'
|
42
|
-
subject.
|
42
|
+
expect(subject).to deny_access
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'fails with no token' do
|
46
46
|
post :create
|
47
|
-
subject.
|
47
|
+
expect(subject).to deny_access
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Clearance::PasswordsController do
|
4
|
-
it {
|
4
|
+
it { is_expected.to be_a Clearance::BaseController }
|
5
5
|
|
6
6
|
describe 'a signed up user' do
|
7
7
|
before do
|
@@ -11,8 +11,8 @@ describe Clearance::PasswordsController do
|
|
11
11
|
describe 'on GET to #new' do
|
12
12
|
before { get :new, user_id: @user.to_param }
|
13
13
|
|
14
|
-
it {
|
15
|
-
it {
|
14
|
+
it { is_expected.to respond_with(:success) }
|
15
|
+
it { is_expected.to render_template(:new) }
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'on POST to #create' do
|
@@ -23,15 +23,15 @@ describe Clearance::PasswordsController do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should generate a token for the change your password email' do
|
26
|
-
@user.reload.confirmation_token.
|
26
|
+
expect(@user.reload.confirmation_token).not_to be_nil
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'sends an email with relevant subject' do
|
30
30
|
email = ActionMailer::Base.deliveries.last
|
31
|
-
email.subject.
|
31
|
+
expect(email.subject).to match(/change your password/i)
|
32
32
|
end
|
33
33
|
|
34
|
-
it {
|
34
|
+
it { is_expected.to respond_with(:success) }
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'with correct email address capitalized differently' do
|
@@ -41,36 +41,38 @@ describe Clearance::PasswordsController do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should generate a token for the change your password email' do
|
44
|
-
@user.reload.confirmation_token.
|
44
|
+
expect(@user.reload.confirmation_token).not_to be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'sends an email with relevant subject' do
|
48
48
|
email = ActionMailer::Base.deliveries.last
|
49
|
-
email.subject.
|
49
|
+
expect(email.subject).to match(/change your password/i)
|
50
50
|
end
|
51
51
|
|
52
|
-
it {
|
52
|
+
it { is_expected.to respond_with(:success) }
|
53
53
|
end
|
54
54
|
|
55
55
|
describe 'with incorrect email address' do
|
56
56
|
before do
|
57
57
|
email = 'user1@example.com'
|
58
|
-
|
58
|
+
user = Clearance.configuration.user_model.exists?(email: email)
|
59
|
+
expect(user).not_to be_present
|
60
|
+
|
59
61
|
ActionMailer::Base.deliveries.clear
|
60
|
-
@user.reload.confirmation_token.
|
62
|
+
expect(@user.reload.confirmation_token).to eq @user.confirmation_token
|
61
63
|
|
62
64
|
post :create, password: { email: email }
|
63
65
|
end
|
64
66
|
|
65
67
|
it 'should not generate a token for the change your password email' do
|
66
|
-
@user.reload.confirmation_token.
|
68
|
+
expect(@user.reload.confirmation_token).to eq @user.confirmation_token
|
67
69
|
end
|
68
70
|
|
69
71
|
it 'should not send a password reminder email' do
|
70
|
-
ActionMailer::Base.deliveries.
|
72
|
+
expect(ActionMailer::Base.deliveries).to be_empty
|
71
73
|
end
|
72
74
|
|
73
|
-
it {
|
75
|
+
it { is_expected.to render_template(:create) }
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
@@ -83,16 +85,17 @@ describe Clearance::PasswordsController do
|
|
83
85
|
|
84
86
|
describe 'on GET to #edit with correct id and token' do
|
85
87
|
before do
|
86
|
-
get :edit,
|
87
|
-
|
88
|
+
get :edit,
|
89
|
+
user_id: @user.to_param,
|
90
|
+
token: @user.confirmation_token
|
88
91
|
end
|
89
92
|
|
90
93
|
it 'should find the user' do
|
91
|
-
assigns(:user).
|
94
|
+
expect(assigns(:user)).to eq @user
|
92
95
|
end
|
93
96
|
|
94
|
-
it {
|
95
|
-
it {
|
97
|
+
it { is_expected.to respond_with(:success) }
|
98
|
+
it { is_expected.to render_template(:edit) }
|
96
99
|
end
|
97
100
|
|
98
101
|
describe 'on GET to #edit with correct id but blank token' do
|
@@ -100,8 +103,8 @@ describe Clearance::PasswordsController do
|
|
100
103
|
get :edit, user_id: @user.to_param, token: ''
|
101
104
|
end
|
102
105
|
|
103
|
-
it {
|
104
|
-
it {
|
106
|
+
it { is_expected.to set_the_flash.to(/double check the URL/i).now }
|
107
|
+
it { is_expected.to render_template(:new) }
|
105
108
|
end
|
106
109
|
|
107
110
|
describe 'on GET to #edit with correct id but no token' do
|
@@ -109,8 +112,8 @@ describe Clearance::PasswordsController do
|
|
109
112
|
get :edit, user_id: @user.to_param
|
110
113
|
end
|
111
114
|
|
112
|
-
it {
|
113
|
-
it {
|
115
|
+
it { is_expected.to set_the_flash.to(/double check the URL/i).now }
|
116
|
+
it { is_expected.to render_template(:new) }
|
114
117
|
end
|
115
118
|
|
116
119
|
describe 'on PUT to #update with password' do
|
@@ -124,18 +127,18 @@ describe Clearance::PasswordsController do
|
|
124
127
|
end
|
125
128
|
|
126
129
|
it 'should update password' do
|
127
|
-
@user.encrypted_password.to_s.
|
130
|
+
expect(@user.encrypted_password.to_s).not_to eq @old_encrypted_password
|
128
131
|
end
|
129
132
|
|
130
133
|
it 'should clear confirmation token' do
|
131
|
-
@user.confirmation_token.
|
134
|
+
expect(@user.confirmation_token).to be_nil
|
132
135
|
end
|
133
136
|
|
134
137
|
it 'should set remember token' do
|
135
|
-
@user.remember_token.
|
138
|
+
expect(@user.remember_token).not_to be_nil
|
136
139
|
end
|
137
140
|
|
138
|
-
it {
|
141
|
+
it { is_expected.to redirect_to_url_after_update }
|
139
142
|
end
|
140
143
|
|
141
144
|
describe 'on PUT to #update with blank password' do
|
@@ -146,20 +149,20 @@ describe Clearance::PasswordsController do
|
|
146
149
|
end
|
147
150
|
|
148
151
|
it 'should not update password to be blank' do
|
149
|
-
@user.encrypted_password.
|
152
|
+
expect(@user.encrypted_password).not_to be_blank
|
150
153
|
end
|
151
154
|
|
152
155
|
it 'should not clear token' do
|
153
|
-
@user.confirmation_token.
|
156
|
+
expect(@user.confirmation_token).not_to be_nil
|
154
157
|
end
|
155
158
|
|
156
159
|
it 'should not be signed in' do
|
157
|
-
cookies[:remember_token].
|
160
|
+
expect(cookies[:remember_token]).to be_nil
|
158
161
|
end
|
159
162
|
|
160
|
-
it {
|
161
|
-
it {
|
162
|
-
it {
|
163
|
+
it { is_expected.to set_the_flash.to(/password can't be blank/i).now }
|
164
|
+
it { is_expected.to respond_with(:success) }
|
165
|
+
it { is_expected.to render_template(:edit) }
|
163
166
|
end
|
164
167
|
|
165
168
|
describe 'on PUT to #update with an empty token after the user sets a password' do
|
@@ -170,8 +173,8 @@ describe Clearance::PasswordsController do
|
|
170
173
|
password_reset: { password: 'new password' }
|
171
174
|
end
|
172
175
|
|
173
|
-
it {
|
174
|
-
it {
|
176
|
+
it { is_expected.to set_the_flash.to(/double check the URL/i).now }
|
177
|
+
it { is_expected.to render_template(:new) }
|
175
178
|
end
|
176
179
|
end
|
177
180
|
|