File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ def update
36
36
37
37
if resource . errors . empty?
38
38
resource . unlock_access! if unlockable? ( resource )
39
- if resource_class . sign_in_after_reset_password
39
+ if sign_in_after_reset_password? ( resource )
40
40
flash_message = resource . active_for_authentication? ? :updated : :updated_not_active
41
41
set_flash_message! ( :notice , flash_message )
42
42
resource . after_database_authentication
@@ -52,8 +52,13 @@ def update
52
52
end
53
53
54
54
protected
55
+ def sign_in_after_reset_password? ( resource )
56
+ value = resource_class . sign_in_after_reset_password
57
+ value . respond_to? ( :call ) ? value . call ( resource ) : value
58
+ end
59
+
55
60
def after_resetting_password_path_for ( resource )
56
- resource_class . sign_in_after_reset_password ? after_sign_in_path_for ( resource ) : new_session_path ( resource_name )
61
+ sign_in_after_reset_password? ( resource ) ? after_sign_in_path_for ( resource ) : new_session_path ( resource_name )
57
62
end
58
63
59
64
# The path used after sending reset password instructions
Original file line number Diff line number Diff line change @@ -247,6 +247,29 @@ def reset_password(options = {}, &block)
247
247
end
248
248
end
249
249
250
+ test 'sign in user automatically with proc' do
251
+ swap Devise , sign_in_after_reset_password : -> ( resource ) { true } do
252
+ create_user
253
+ request_forgot_password
254
+ reset_password
255
+
256
+ assert warden . authenticated? ( :user )
257
+ end
258
+ end
259
+
260
+ test 'does not sign in user automatically with proc' do
261
+ swap Devise , sign_in_after_reset_password : -> ( resource ) { false } do
262
+ create_user
263
+ request_forgot_password
264
+ reset_password
265
+
266
+ assert_contain 'Your password has been changed successfully.'
267
+ assert_not_contain 'You are now signed in.'
268
+ assert_equal new_user_session_path , @request . path
269
+ assert_not warden . authenticated? ( :user )
270
+ end
271
+ end
272
+
250
273
test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
251
274
[ :none , :time ] . each do |strategy |
252
275
swap Devise , unlock_strategy : strategy do
You can’t perform that action at this time.
0 commit comments