mongoid-devise 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/CHANGELOG.rdoc +333 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +260 -0
  4. data/Rakefile +53 -0
  5. data/TODO +2 -0
  6. data/app/controllers/confirmations_controller.rb +33 -0
  7. data/app/controllers/passwords_controller.rb +42 -0
  8. data/app/controllers/registrations_controller.rb +55 -0
  9. data/app/controllers/sessions_controller.rb +45 -0
  10. data/app/controllers/unlocks_controller.rb +33 -0
  11. data/app/models/devise_mailer.rb +68 -0
  12. data/app/views/confirmations/new.html.erb +12 -0
  13. data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
  14. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  15. data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
  16. data/app/views/passwords/edit.html.erb +16 -0
  17. data/app/views/passwords/new.html.erb +12 -0
  18. data/app/views/registrations/edit.html.erb +25 -0
  19. data/app/views/registrations/new.html.erb +17 -0
  20. data/app/views/sessions/new.html.erb +17 -0
  21. data/app/views/shared/_devise_links.erb +19 -0
  22. data/app/views/unlocks/new.html.erb +12 -0
  23. data/generators/devise/USAGE +5 -0
  24. data/generators/devise/devise_generator.rb +15 -0
  25. data/generators/devise/lib/route_devise.rb +32 -0
  26. data/generators/devise/templates/migration.rb +23 -0
  27. data/generators/devise/templates/model.rb +9 -0
  28. data/generators/devise_install/USAGE +3 -0
  29. data/generators/devise_install/devise_install_generator.rb +15 -0
  30. data/generators/devise_install/templates/README +18 -0
  31. data/generators/devise_install/templates/devise.rb +102 -0
  32. data/generators/devise_views/USAGE +3 -0
  33. data/generators/devise_views/devise_views_generator.rb +21 -0
  34. data/init.rb +2 -0
  35. data/lib/devise.rb +253 -0
  36. data/lib/devise/controllers/helpers.rb +200 -0
  37. data/lib/devise/controllers/internal_helpers.rb +129 -0
  38. data/lib/devise/controllers/url_helpers.rb +41 -0
  39. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  40. data/lib/devise/encryptors/base.rb +20 -0
  41. data/lib/devise/encryptors/bcrypt.rb +21 -0
  42. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  43. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  44. data/lib/devise/encryptors/sha1.rb +27 -0
  45. data/lib/devise/encryptors/sha512.rb +27 -0
  46. data/lib/devise/failure_app.rb +65 -0
  47. data/lib/devise/hooks/activatable.rb +15 -0
  48. data/lib/devise/hooks/rememberable.rb +30 -0
  49. data/lib/devise/hooks/timeoutable.rb +18 -0
  50. data/lib/devise/hooks/trackable.rb +18 -0
  51. data/lib/devise/locales/en.yml +35 -0
  52. data/lib/devise/mapping.rb +131 -0
  53. data/lib/devise/models.rb +112 -0
  54. data/lib/devise/models/activatable.rb +16 -0
  55. data/lib/devise/models/authenticatable.rb +146 -0
  56. data/lib/devise/models/confirmable.rb +172 -0
  57. data/lib/devise/models/http_authenticatable.rb +21 -0
  58. data/lib/devise/models/lockable.rb +160 -0
  59. data/lib/devise/models/recoverable.rb +80 -0
  60. data/lib/devise/models/registerable.rb +8 -0
  61. data/lib/devise/models/rememberable.rb +94 -0
  62. data/lib/devise/models/timeoutable.rb +28 -0
  63. data/lib/devise/models/token_authenticatable.rb +89 -0
  64. data/lib/devise/models/trackable.rb +16 -0
  65. data/lib/devise/models/validatable.rb +48 -0
  66. data/lib/devise/orm/active_record.rb +41 -0
  67. data/lib/devise/orm/data_mapper.rb +83 -0
  68. data/lib/devise/orm/mongo_mapper.rb +51 -0
  69. data/lib/devise/orm/mongoid.rb +60 -0
  70. data/lib/devise/rails.rb +14 -0
  71. data/lib/devise/rails/routes.rb +125 -0
  72. data/lib/devise/rails/warden_compat.rb +25 -0
  73. data/lib/devise/schema.rb +65 -0
  74. data/lib/devise/strategies/authenticatable.rb +36 -0
  75. data/lib/devise/strategies/base.rb +16 -0
  76. data/lib/devise/strategies/http_authenticatable.rb +49 -0
  77. data/lib/devise/strategies/rememberable.rb +37 -0
  78. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  79. data/lib/devise/test_helpers.rb +86 -0
  80. data/lib/devise/version.rb +3 -0
  81. data/test/controllers/helpers_test.rb +177 -0
  82. data/test/controllers/internal_helpers_test.rb +55 -0
  83. data/test/controllers/url_helpers_test.rb +47 -0
  84. data/test/devise_test.rb +69 -0
  85. data/test/encryptors_test.rb +31 -0
  86. data/test/failure_app_test.rb +44 -0
  87. data/test/integration/authenticatable_test.rb +271 -0
  88. data/test/integration/confirmable_test.rb +97 -0
  89. data/test/integration/http_authenticatable_test.rb +44 -0
  90. data/test/integration/lockable_test.rb +83 -0
  91. data/test/integration/recoverable_test.rb +141 -0
  92. data/test/integration/registerable_test.rb +130 -0
  93. data/test/integration/rememberable_test.rb +63 -0
  94. data/test/integration/timeoutable_test.rb +68 -0
  95. data/test/integration/token_authenticatable_test.rb +55 -0
  96. data/test/integration/trackable_test.rb +64 -0
  97. data/test/mailers/confirmation_instructions_test.rb +80 -0
  98. data/test/mailers/reset_password_instructions_test.rb +68 -0
  99. data/test/mailers/unlock_instructions_test.rb +62 -0
  100. data/test/mapping_test.rb +153 -0
  101. data/test/models/authenticatable_test.rb +180 -0
  102. data/test/models/confirmable_test.rb +228 -0
  103. data/test/models/lockable_test.rb +202 -0
  104. data/test/models/recoverable_test.rb +138 -0
  105. data/test/models/rememberable_test.rb +135 -0
  106. data/test/models/timeoutable_test.rb +28 -0
  107. data/test/models/token_authenticatable_test.rb +51 -0
  108. data/test/models/trackable_test.rb +5 -0
  109. data/test/models/validatable_test.rb +106 -0
  110. data/test/models_test.rb +56 -0
  111. data/test/orm/active_record.rb +31 -0
  112. data/test/orm/mongo_mapper.rb +20 -0
  113. data/test/orm/mongoid.rb +22 -0
  114. data/test/rails_app/app/active_record/admin.rb +7 -0
  115. data/test/rails_app/app/active_record/user.rb +7 -0
  116. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  117. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  118. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  119. data/test/rails_app/app/controllers/users_controller.rb +16 -0
  120. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  121. data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
  122. data/test/rails_app/app/mongo_mapper/user.rb +8 -0
  123. data/test/rails_app/app/mongoid/admin.rb +9 -0
  124. data/test/rails_app/app/mongoid/user.rb +8 -0
  125. data/test/rails_app/config/boot.rb +110 -0
  126. data/test/rails_app/config/environment.rb +42 -0
  127. data/test/rails_app/config/environments/development.rb +17 -0
  128. data/test/rails_app/config/environments/production.rb +28 -0
  129. data/test/rails_app/config/environments/test.rb +28 -0
  130. data/test/rails_app/config/initializers/devise.rb +79 -0
  131. data/test/rails_app/config/initializers/inflections.rb +2 -0
  132. data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  133. data/test/rails_app/config/initializers/session_store.rb +15 -0
  134. data/test/rails_app/config/routes.rb +21 -0
  135. data/test/routes_test.rb +110 -0
  136. data/test/support/assertions_helper.rb +37 -0
  137. data/test/support/integration_tests_helper.rb +71 -0
  138. data/test/support/test_silencer.rb +5 -0
  139. data/test/support/tests_helper.rb +39 -0
  140. data/test/test_helper.rb +21 -0
  141. data/test/test_helpers_test.rb +57 -0
  142. metadata +216 -0
@@ -0,0 +1,44 @@
1
+ require 'test/test_helper'
2
+
3
+ class HttpAuthenticationTest < ActionController::IntegrationTest
4
+
5
+ test 'sign in should authenticate with http' do
6
+ sign_in_as_new_user_with_http
7
+ assert_response :success
8
+ assert_template 'users/index'
9
+ assert_contain 'Welcome'
10
+ assert warden.authenticated?(:user)
11
+ end
12
+
13
+ test 'returns a custom response with www-authenticate header on failures' do
14
+ sign_in_as_new_user_with_http("unknown")
15
+ assert_equal 401, status
16
+ assert_equal 'Basic realm="Application"', headers["WWW-Authenticate"]
17
+ end
18
+
19
+ test 'returns a custom response with www-authenticate and chosen realm' do
20
+ swap Devise, :http_authentication_realm => "MyApp" do
21
+ sign_in_as_new_user_with_http("unknown")
22
+ assert_equal 401, status
23
+ assert_equal 'Basic realm="MyApp"', headers["WWW-Authenticate"]
24
+ end
25
+ end
26
+
27
+ test 'sign in should authenticate with http even with specific authentication keys' do
28
+ swap Devise, :authentication_keys => [:username] do
29
+ sign_in_as_new_user_with_http "usertest"
30
+ assert_response :success
31
+ assert_template 'users/index'
32
+ assert_contain 'Welcome'
33
+ assert warden.authenticated?(:user)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def sign_in_as_new_user_with_http(username="user@test.com", password="123456")
40
+ user = create_user
41
+ get users_path, {}, :authorization => "Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}"
42
+ user
43
+ end
44
+ end
@@ -0,0 +1,83 @@
1
+ require 'test/test_helper'
2
+
3
+ class LockTest < ActionController::IntegrationTest
4
+
5
+ def visit_user_unlock_with_token(unlock_token)
6
+ visit user_unlock_path(:unlock_token => unlock_token)
7
+ end
8
+
9
+ test 'user should be able to request a new unlock token' do
10
+ user = create_user(:locked => true)
11
+ ActionMailer::Base.deliveries.clear
12
+
13
+ visit new_user_session_path
14
+ click_link 'Didn\'t receive unlock instructions?'
15
+
16
+ fill_in 'email', :with => user.email
17
+ click_button 'Resend unlock instructions'
18
+
19
+ assert_template 'sessions/new'
20
+ assert_contain 'You will receive an email with instructions about how to unlock your account in a few minutes'
21
+ assert_equal 1, ActionMailer::Base.deliveries.size
22
+ end
23
+
24
+ test 'unlocked user should not be able to request a unlock token' do
25
+ user = create_user(:locked => false)
26
+ ActionMailer::Base.deliveries.clear
27
+
28
+ visit new_user_session_path
29
+ click_link 'Didn\'t receive unlock instructions?'
30
+
31
+ fill_in 'email', :with => user.email
32
+ click_button 'Resend unlock instructions'
33
+
34
+ assert_template 'unlocks/new'
35
+ assert_contain 'not locked'
36
+ assert_equal 0, ActionMailer::Base.deliveries.size
37
+ end
38
+
39
+ test 'user with invalid unlock token should not be able to unlock an account' do
40
+ visit_user_unlock_with_token('invalid_token')
41
+
42
+ assert_response :success
43
+ assert_template 'unlocks/new'
44
+ assert_have_selector '#errorExplanation'
45
+ assert_contain /Unlock token(.*)invalid/
46
+ end
47
+
48
+ test "locked user should be able to unlock account" do
49
+ user = create_user(:locked => true)
50
+ assert user.locked?
51
+
52
+ visit_user_unlock_with_token(user.unlock_token)
53
+
54
+ assert_template 'home/index'
55
+ assert_contain 'Your account was successfully unlocked.'
56
+
57
+ assert_not user.reload.locked?
58
+ end
59
+
60
+ test "sign in user automatically after unlocking it's account" do
61
+ user = create_user(:locked => true)
62
+ visit_user_unlock_with_token(user.unlock_token)
63
+
64
+ assert warden.authenticated?(:user)
65
+ end
66
+
67
+ test "user should not be able to sign in when locked" do
68
+ user = sign_in_as_user(:locked => true)
69
+ assert_template 'sessions/new'
70
+ assert_contain 'Your account is locked.'
71
+ assert_not warden.authenticated?(:user)
72
+ end
73
+
74
+ test 'error message is configurable by resource name' do
75
+ store_translations :en, :devise => {
76
+ :sessions => { :admin => { :locked => "You are locked!" } }
77
+ } do
78
+ get new_admin_session_path(:locked => true)
79
+ assert_contain 'You are locked!'
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,141 @@
1
+ require 'test/test_helper'
2
+
3
+ class PasswordTest < ActionController::IntegrationTest
4
+
5
+ def visit_new_password_path
6
+ visit new_user_session_path
7
+ click_link 'Forgot password?'
8
+ end
9
+
10
+ def request_forgot_password(&block)
11
+ visit_new_password_path
12
+
13
+ assert_response :success
14
+ assert_template 'passwords/new'
15
+ assert_not warden.authenticated?(:user)
16
+
17
+ fill_in 'email', :with => 'user@test.com'
18
+ yield if block_given?
19
+ click_button 'Send me reset password instructions'
20
+ end
21
+
22
+ def reset_password(options={}, &block)
23
+ unless options[:visit] == false
24
+ visit edit_user_password_path(:reset_password_token => options[:reset_password_token])
25
+ end
26
+ assert_response :success
27
+ assert_template 'passwords/edit'
28
+
29
+ fill_in 'Password', :with => '987654321'
30
+ fill_in 'Password confirmation', :with => '987654321'
31
+ yield if block_given?
32
+ click_button 'Change my password'
33
+ end
34
+
35
+ test 'authenticated user should not be able to visit forgot password page' do
36
+ sign_in_as_user
37
+ assert warden.authenticated?(:user)
38
+
39
+ get new_user_password_path
40
+
41
+ assert_response :redirect
42
+ assert_redirected_to root_path
43
+ end
44
+
45
+ test 'not authenticated user should be able to request a forgot password' do
46
+ create_user
47
+ request_forgot_password
48
+
49
+ assert_template 'sessions/new'
50
+ assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
51
+ end
52
+
53
+ test 'not authenticated user with invalid email should receive an error message' do
54
+ request_forgot_password do
55
+ fill_in 'email', :with => 'invalid.test@test.com'
56
+ end
57
+
58
+ assert_response :success
59
+ assert_template 'passwords/new'
60
+ assert_have_selector 'input[type=text][value=\'invalid.test@test.com\']'
61
+ assert_contain 'Email not found'
62
+ end
63
+
64
+ test 'authenticated user should not be able to visit edit password page' do
65
+ sign_in_as_user
66
+
67
+ get edit_user_password_path
68
+
69
+ assert_response :redirect
70
+ assert_redirected_to root_path
71
+ assert warden.authenticated?(:user)
72
+ end
73
+
74
+ test 'not authenticated user with invalid reset password token should not be able to change his password' do
75
+ user = create_user
76
+ reset_password :reset_password_token => 'invalid_reset_password'
77
+
78
+ assert_response :success
79
+ assert_template 'passwords/edit'
80
+ assert_have_selector '#errorExplanation'
81
+ assert_contain /Reset password token(.*)invalid/
82
+ assert_not user.reload.valid_password?('987654321')
83
+ end
84
+
85
+ test 'not authenticated user with valid reset password token but invalid password should not be able to change his password' do
86
+ user = create_user
87
+ request_forgot_password
88
+ reset_password :reset_password_token => user.reload.reset_password_token do
89
+ fill_in 'Password confirmation', :with => 'other_password'
90
+ end
91
+
92
+ assert_response :success
93
+ assert_template 'passwords/edit'
94
+ assert_have_selector '#errorExplanation'
95
+ assert_contain 'Password doesn\'t match confirmation'
96
+ assert_not user.reload.valid_password?('987654321')
97
+ end
98
+
99
+ test 'not authenticated user with valid data should be able to change his password' do
100
+ user = create_user
101
+ request_forgot_password
102
+ reset_password :reset_password_token => user.reload.reset_password_token
103
+
104
+ assert_template 'home/index'
105
+ assert_contain 'Your password was changed successfully.'
106
+ assert user.reload.valid_password?('987654321')
107
+ end
108
+
109
+ test 'after entering invalid data user should still be able to change his password' do
110
+ user = create_user
111
+ request_forgot_password
112
+ reset_password :reset_password_token => user.reload.reset_password_token do
113
+ fill_in 'Password confirmation', :with => 'other_password'
114
+ end
115
+ assert_response :success
116
+ assert_have_selector '#errorExplanation'
117
+ assert_not user.reload.valid_password?('987654321')
118
+
119
+ reset_password :reset_password_token => user.reload.reset_password_token, :visit => false
120
+ assert_contain 'Your password was changed successfully.'
121
+ assert user.reload.valid_password?('987654321')
122
+ end
123
+
124
+ test 'sign in user automatically after changing it\'s password' do
125
+ user = create_user
126
+ request_forgot_password
127
+ reset_password :reset_password_token => user.reload.reset_password_token
128
+
129
+ assert warden.authenticated?(:user)
130
+ end
131
+
132
+ test 'does not sign in user automatically after changing it\'s password if it\'s not active' do
133
+ user = create_user(:confirm => false)
134
+ request_forgot_password
135
+ reset_password :reset_password_token => user.reload.reset_password_token
136
+
137
+ assert_redirected_to new_user_session_path(:unconfirmed => true)
138
+ assert !warden.authenticated?(:user)
139
+ end
140
+
141
+ end
@@ -0,0 +1,130 @@
1
+ require 'test/test_helper'
2
+
3
+ class RegistrationTest < ActionController::IntegrationTest
4
+
5
+ test 'a guest admin should be able to sign in successfully' do
6
+ visit new_admin_session_path
7
+ click_link 'Sign up'
8
+
9
+ assert_template 'registrations/new'
10
+
11
+ fill_in 'email', :with => 'new_user@test.com'
12
+ fill_in 'password', :with => 'new_user123'
13
+ fill_in 'password confirmation', :with => 'new_user123'
14
+ click_button 'Sign up'
15
+
16
+ assert_contain 'You have signed up successfully.'
17
+ assert warden.authenticated?(:admin)
18
+
19
+ admin = Admin.last
20
+ assert_equal admin.email, 'new_user@test.com'
21
+ end
22
+
23
+ test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
24
+ visit new_user_registration_path
25
+
26
+ fill_in 'email', :with => 'new_user@test.com'
27
+ fill_in 'password', :with => 'new_user123'
28
+ fill_in 'password confirmation', :with => 'new_user123'
29
+ click_button 'Sign up'
30
+
31
+ assert_equal true, @controller.send(:flash)[:"user_signed_up"]
32
+ assert_equal "You have signed up successfully.", @controller.send(:flash)[:notice]
33
+
34
+ # For some reason flash is not being set correctly, so instead of getting the
35
+ # "signed_up" message we get the unconfirmed one. Seems to be an issue with
36
+ # the internal redirect by the hook and the tests.
37
+ # follow_redirect!
38
+ # assert_contain 'You have signed up successfully.'
39
+ # assert_not_contain 'confirm your account'
40
+
41
+ assert_not warden.authenticated?(:user)
42
+
43
+ user = User.last
44
+ assert_equal user.email, 'new_user@test.com'
45
+ assert_not user.confirmed?
46
+ end
47
+
48
+ test 'a guest user cannot sign up with invalid information' do
49
+ visit new_user_registration_path
50
+
51
+ fill_in 'email', :with => 'invalid_email'
52
+ fill_in 'password', :with => 'new_user123'
53
+ fill_in 'password confirmation', :with => 'new_user321'
54
+ click_button 'Sign up'
55
+
56
+ assert_template 'registrations/new'
57
+ assert_have_selector '#errorExplanation'
58
+ assert_contain "Email is invalid"
59
+ assert_contain "Password doesn't match confirmation"
60
+ assert_nil User.first
61
+
62
+ assert_not warden.authenticated?(:user)
63
+ end
64
+
65
+ test 'a guest should not sign up with email/password that already exists' do
66
+ user = create_user
67
+ visit new_user_registration_path
68
+
69
+ fill_in 'email', :with => 'user@test.com'
70
+ fill_in 'password', :with => '123456'
71
+ fill_in 'password confirmation', :with => '123456'
72
+ click_button 'Sign up'
73
+
74
+ assert_template 'registrations/new'
75
+ assert_contain 'Email has already been taken'
76
+
77
+ assert_not warden.authenticated?(:user)
78
+ end
79
+
80
+ test 'a guest should not be able to change account' do
81
+ visit edit_user_registration_path
82
+ follow_redirect!
83
+ assert_template 'sessions/new'
84
+ end
85
+
86
+ test 'a signed in user should not be able to access sign up' do
87
+ sign_in_as_user
88
+ visit new_user_registration_path
89
+ assert_template 'home/index'
90
+ end
91
+
92
+ test 'a signed in user should be able to edit his account' do
93
+ sign_in_as_user
94
+ visit edit_user_registration_path
95
+
96
+ fill_in 'email', :with => 'user.new@email.com'
97
+ fill_in 'current password', :with => '123456'
98
+ click_button 'Update'
99
+
100
+ assert_template 'home/index'
101
+ assert_contain 'You updated your account successfully.'
102
+
103
+ assert_equal "user.new@email.com", User.first.email
104
+ end
105
+
106
+ test 'a signed in user should be able to edit his password' do
107
+ sign_in_as_user
108
+ visit edit_user_registration_path
109
+
110
+ fill_in 'password', :with => 'pas123'
111
+ fill_in 'password confirmation', :with => 'pas123'
112
+ fill_in 'current password', :with => '123456'
113
+ click_button 'Update'
114
+
115
+ assert_template 'home/index'
116
+ assert_contain 'You updated your account successfully.'
117
+
118
+ assert User.first.valid_password?('pas123')
119
+ end
120
+
121
+ test 'a signed in user should be able to cancel his account' do
122
+ sign_in_as_user
123
+ visit edit_user_registration_path
124
+
125
+ click_link "Cancel my account"
126
+ assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
127
+
128
+ assert User.all.empty?
129
+ end
130
+ end
@@ -0,0 +1,63 @@
1
+ require 'test/test_helper'
2
+
3
+ class RememberMeTest < ActionController::IntegrationTest
4
+
5
+ def create_user_and_remember(add_to_token='')
6
+ Devise.remember_for = 1
7
+ user = create_user
8
+ user.remember_me!
9
+ cookies['remember_user_token'] = User.serialize_into_cookie(user) + add_to_token
10
+ user
11
+ end
12
+
13
+ test 'do not remember the user if he has not checked remember me option' do
14
+ user = sign_in_as_user
15
+ assert_nil user.reload.remember_token
16
+ end
17
+
18
+ test 'generate remember token after sign in' do
19
+ user = sign_in_as_user :remember_me => true
20
+ assert_not_nil user.reload.remember_token
21
+ end
22
+
23
+ test 'remember the user before sign in' do
24
+ user = create_user_and_remember
25
+ get users_path
26
+ assert_response :success
27
+ assert warden.authenticated?(:user)
28
+ assert_equal user.reload, warden.user(:user)
29
+ end
30
+
31
+ test 'do not remember with invalid token' do
32
+ user = create_user_and_remember('add')
33
+ get users_path
34
+ assert_response :success
35
+ assert_not warden.authenticated?(:user)
36
+ end
37
+
38
+ test 'do not remember with token expired' do
39
+ user = create_user_and_remember
40
+ Devise.remember_for = 0
41
+ get users_path
42
+ assert_response :success
43
+ assert_not warden.authenticated?(:user)
44
+ end
45
+
46
+ test 'forget the user before sign out' do
47
+ user = create_user_and_remember
48
+ get users_path
49
+ assert warden.authenticated?(:user)
50
+ get destroy_user_session_path
51
+ assert_not warden.authenticated?(:user)
52
+ assert_nil user.reload.remember_token
53
+ end
54
+
55
+ test 'do not remember the user anymore after forget' do
56
+ user = create_user_and_remember
57
+ get users_path
58
+ assert warden.authenticated?(:user)
59
+ get destroy_user_session_path
60
+ get users_path
61
+ assert_not warden.authenticated?(:user)
62
+ end
63
+ end