devise 3.2.4 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +33 -17
  4. data/CHANGELOG.md +57 -1033
  5. data/CODE_OF_CONDUCT.md +22 -0
  6. data/CONTRIBUTING.md +2 -0
  7. data/Gemfile +5 -5
  8. data/Gemfile.lock +138 -115
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +124 -65
  11. data/Rakefile +2 -1
  12. data/app/controllers/devise/confirmations_controller.rb +7 -3
  13. data/app/controllers/devise/omniauth_callbacks_controller.rb +8 -4
  14. data/app/controllers/devise/passwords_controller.rb +16 -6
  15. data/app/controllers/devise/registrations_controller.rb +22 -10
  16. data/app/controllers/devise/sessions_controller.rb +42 -14
  17. data/app/controllers/devise/unlocks_controller.rb +5 -2
  18. data/app/controllers/devise_controller.rb +63 -29
  19. data/app/mailers/devise/mailer.rb +4 -0
  20. data/app/views/devise/confirmations/new.html.erb +7 -3
  21. data/app/views/devise/mailer/password_change.html.erb +3 -0
  22. data/app/views/devise/passwords/edit.html.erb +14 -5
  23. data/app/views/devise/passwords/new.html.erb +7 -3
  24. data/app/views/devise/registrations/edit.html.erb +19 -9
  25. data/app/views/devise/registrations/new.html.erb +18 -7
  26. data/app/views/devise/sessions/new.html.erb +16 -7
  27. data/app/views/devise/shared/{_links.erb → _links.html.erb} +2 -2
  28. data/app/views/devise/unlocks/new.html.erb +7 -3
  29. data/bin/test +13 -0
  30. data/config/locales/en.yml +19 -16
  31. data/devise.gemspec +3 -4
  32. data/gemfiles/{Gemfile.rails-3.2-stable → Gemfile.rails-4.1-stable} +6 -6
  33. data/gemfiles/Gemfile.rails-4.1-stable.lock +167 -0
  34. data/gemfiles/{Gemfile.rails-head → Gemfile.rails-4.2-stable} +6 -6
  35. data/gemfiles/Gemfile.rails-4.2-stable.lock +189 -0
  36. data/gemfiles/Gemfile.rails-5.0-beta +37 -0
  37. data/gemfiles/Gemfile.rails-5.0-beta.lock +199 -0
  38. data/lib/devise/controllers/helpers.rb +94 -27
  39. data/lib/devise/controllers/rememberable.rb +9 -2
  40. data/lib/devise/controllers/sign_in_out.rb +2 -9
  41. data/lib/devise/controllers/store_location.rb +11 -3
  42. data/lib/devise/controllers/url_helpers.rb +7 -7
  43. data/lib/devise/encryptor.rb +22 -0
  44. data/lib/devise/failure_app.rb +72 -23
  45. data/lib/devise/hooks/activatable.rb +3 -4
  46. data/lib/devise/hooks/csrf_cleaner.rb +3 -1
  47. data/lib/devise/hooks/timeoutable.rb +13 -8
  48. data/lib/devise/mailers/helpers.rb +1 -1
  49. data/lib/devise/mapping.rb +6 -2
  50. data/lib/devise/models/authenticatable.rb +32 -28
  51. data/lib/devise/models/confirmable.rb +55 -22
  52. data/lib/devise/models/database_authenticatable.rb +32 -19
  53. data/lib/devise/models/lockable.rb +5 -5
  54. data/lib/devise/models/recoverable.rb +44 -20
  55. data/lib/devise/models/rememberable.rb +54 -27
  56. data/lib/devise/models/timeoutable.rb +0 -6
  57. data/lib/devise/models/trackable.rb +5 -3
  58. data/lib/devise/models/validatable.rb +3 -3
  59. data/lib/devise/models.rb +1 -1
  60. data/lib/devise/omniauth/url_helpers.rb +62 -4
  61. data/lib/devise/parameter_sanitizer.rb +176 -61
  62. data/lib/devise/rails/routes.rb +76 -59
  63. data/lib/devise/rails/warden_compat.rb +1 -10
  64. data/lib/devise/rails.rb +2 -11
  65. data/lib/devise/strategies/authenticatable.rb +15 -6
  66. data/lib/devise/strategies/database_authenticatable.rb +5 -4
  67. data/lib/devise/strategies/rememberable.rb +13 -3
  68. data/lib/devise/test_helpers.rb +12 -7
  69. data/lib/devise/token_generator.rb +1 -41
  70. data/lib/devise/version.rb +1 -1
  71. data/lib/devise.rb +150 -58
  72. data/lib/generators/active_record/devise_generator.rb +28 -4
  73. data/lib/generators/active_record/templates/migration.rb +3 -3
  74. data/lib/generators/active_record/templates/migration_existing.rb +3 -3
  75. data/lib/generators/devise/controllers_generator.rb +44 -0
  76. data/lib/generators/devise/install_generator.rb +15 -0
  77. data/lib/generators/devise/orm_helpers.rb +1 -18
  78. data/lib/generators/devise/views_generator.rb +14 -3
  79. data/lib/generators/templates/README +1 -1
  80. data/lib/generators/templates/controllers/README +14 -0
  81. data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
  82. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
  83. data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
  84. data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
  85. data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
  86. data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
  87. data/lib/generators/templates/devise.rb +36 -28
  88. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  89. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  90. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  91. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  92. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
  93. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  94. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +2 -2
  95. data/test/controllers/custom_registrations_controller_test.rb +40 -0
  96. data/test/controllers/custom_strategy_test.rb +7 -5
  97. data/test/controllers/helper_methods_test.rb +22 -0
  98. data/test/controllers/helpers_test.rb +41 -1
  99. data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
  100. data/test/controllers/internal_helpers_test.rb +19 -15
  101. data/test/controllers/load_hooks_controller_test.rb +19 -0
  102. data/test/controllers/passwords_controller_test.rb +5 -4
  103. data/test/controllers/sessions_controller_test.rb +24 -21
  104. data/test/controllers/url_helpers_test.rb +7 -1
  105. data/test/devise_test.rb +48 -8
  106. data/test/failure_app_test.rb +107 -19
  107. data/test/generators/active_record_generator_test.rb +6 -26
  108. data/test/generators/controllers_generator_test.rb +48 -0
  109. data/test/generators/install_generator_test.rb +14 -3
  110. data/test/generators/views_generator_test.rb +8 -1
  111. data/test/helpers/devise_helper_test.rb +10 -12
  112. data/test/integration/authenticatable_test.rb +37 -21
  113. data/test/integration/confirmable_test.rb +54 -14
  114. data/test/integration/database_authenticatable_test.rb +12 -1
  115. data/test/integration/http_authenticatable_test.rb +4 -5
  116. data/test/integration/lockable_test.rb +10 -9
  117. data/test/integration/omniauthable_test.rb +13 -11
  118. data/test/integration/recoverable_test.rb +28 -15
  119. data/test/integration/registerable_test.rb +41 -33
  120. data/test/integration/rememberable_test.rb +51 -7
  121. data/test/integration/timeoutable_test.rb +23 -22
  122. data/test/integration/trackable_test.rb +3 -3
  123. data/test/mailers/confirmation_instructions_test.rb +10 -10
  124. data/test/mailers/reset_password_instructions_test.rb +8 -8
  125. data/test/mailers/unlock_instructions_test.rb +8 -8
  126. data/test/mapping_test.rb +7 -0
  127. data/test/models/authenticatable_test.rb +11 -1
  128. data/test/models/confirmable_test.rb +91 -42
  129. data/test/models/database_authenticatable_test.rb +26 -6
  130. data/test/models/lockable_test.rb +29 -17
  131. data/test/models/recoverable_test.rb +74 -7
  132. data/test/models/rememberable_test.rb +68 -94
  133. data/test/models/trackable_test.rb +28 -0
  134. data/test/models/validatable_test.rb +9 -17
  135. data/test/models_test.rb +15 -6
  136. data/test/omniauth/url_helpers_test.rb +4 -7
  137. data/test/orm/active_record.rb +6 -1
  138. data/test/parameter_sanitizer_test.rb +103 -53
  139. data/test/rails_app/app/active_record/user.rb +1 -0
  140. data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
  141. data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
  142. data/test/rails_app/app/active_record/user_without_email.rb +8 -0
  143. data/test/rails_app/app/controllers/admins_controller.rb +1 -6
  144. data/test/rails_app/app/controllers/application_controller.rb +5 -2
  145. data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
  146. data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
  147. data/test/rails_app/app/controllers/home_controller.rb +5 -1
  148. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +3 -3
  149. data/test/rails_app/app/controllers/users_controller.rb +6 -6
  150. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
  151. data/test/rails_app/app/mailers/users/mailer.rb +0 -9
  152. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
  153. data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
  154. data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
  155. data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
  156. data/test/rails_app/config/application.rb +3 -3
  157. data/test/rails_app/config/boot.rb +4 -4
  158. data/test/rails_app/config/environments/production.rb +6 -2
  159. data/test/rails_app/config/environments/test.rb +13 -3
  160. data/test/rails_app/config/initializers/devise.rb +15 -16
  161. data/test/rails_app/config/initializers/secret_token.rb +1 -6
  162. data/test/rails_app/config/routes.rb +23 -3
  163. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -2
  164. data/test/rails_app/lib/shared_user.rb +1 -1
  165. data/test/rails_app/lib/shared_user_without_email.rb +26 -0
  166. data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
  167. data/test/rails_test.rb +9 -0
  168. data/test/routes_test.rb +33 -16
  169. data/test/support/assertions.rb +2 -3
  170. data/test/support/helpers.rb +13 -6
  171. data/test/support/http_method_compatibility.rb +51 -0
  172. data/test/support/integration.rb +4 -4
  173. data/test/support/webrat/integrations/rails.rb +9 -0
  174. data/test/test_helper.rb +7 -0
  175. data/test/test_helpers_test.rb +43 -38
  176. data/test/test_models.rb +3 -3
  177. metadata +77 -23
  178. data/gemfiles/Gemfile.rails-4.0-stable +0 -29
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class PasswordTest < ActionDispatch::IntegrationTest
3
+ class PasswordTest < Devise::IntegrationTest
4
4
 
5
5
  def visit_new_password_path
6
6
  visit new_user_session_path
@@ -160,8 +160,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
160
160
  assert_response :success
161
161
  assert_current_url '/users/password'
162
162
  assert_have_selector '#error_explanation'
163
- assert_contain Devise.rails4? ?
164
- "Password confirmation doesn't match Password" : "Password doesn't match confirmation"
163
+ assert_contain "Password confirmation doesn't match Password"
165
164
  assert_not user.reload.valid_password?('987654321')
166
165
  end
167
166
 
@@ -171,7 +170,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
171
170
  reset_password
172
171
 
173
172
  assert_current_url '/'
174
- assert_contain 'Your password was changed successfully. You are now signed in.'
173
+ assert_contain 'Your password has been changed successfully. You are now signed in.'
175
174
  assert user.reload.valid_password?('987654321')
176
175
  end
177
176
 
@@ -185,7 +184,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
185
184
  assert_not user.reload.valid_password?('987654321')
186
185
 
187
186
  reset_password visit: false
188
- assert_contain 'Your password was changed successfully.'
187
+ assert_contain 'Your password has been changed successfully.'
189
188
  assert user.reload.valid_password?('987654321')
190
189
  end
191
190
 
@@ -197,6 +196,19 @@ class PasswordTest < ActionDispatch::IntegrationTest
197
196
  assert warden.authenticated?(:user)
198
197
  end
199
198
 
199
+ test 'does not sign in user automatically after changing its password if config.sign_in_after_reset_password is false' do
200
+ swap Devise, sign_in_after_reset_password: false do
201
+ create_user
202
+ request_forgot_password
203
+ reset_password
204
+
205
+ assert_contain 'Your password has been changed successfully.'
206
+ assert_not_contain 'You are now signed in.'
207
+ assert_equal new_user_session_path, @request.path
208
+ assert !warden.authenticated?(:user)
209
+ end
210
+ end
211
+
200
212
  test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
201
213
  [:none, :time].each do |strategy|
202
214
  swap Devise, unlock_strategy: strategy do
@@ -204,7 +216,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
204
216
  request_forgot_password
205
217
  reset_password
206
218
 
207
- assert_contain 'Your password was changed successfully.'
219
+ assert_contain 'Your password has been changed successfully.'
208
220
  assert_not_contain 'You are now signed in.'
209
221
  assert_equal new_user_session_path, @request.path
210
222
  assert !warden.authenticated?(:user)
@@ -218,7 +230,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
218
230
  request_forgot_password
219
231
  reset_password
220
232
 
221
- assert_contain 'Your password was changed successfully.'
233
+ assert_contain 'Your password has been changed successfully.'
222
234
  assert !user.reload.access_locked?
223
235
  assert warden.authenticated?(:user)
224
236
  end
@@ -230,7 +242,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
230
242
  request_forgot_password
231
243
  reset_password
232
244
 
233
- assert_contain 'Your password was changed successfully.'
245
+ assert_contain 'Your password has been changed successfully.'
234
246
  assert !user.reload.access_locked?
235
247
  assert warden.authenticated?(:user)
236
248
  end
@@ -238,14 +250,14 @@ class PasswordTest < ActionDispatch::IntegrationTest
238
250
 
239
251
  test 'reset password request with valid E-Mail in XML format should return valid response' do
240
252
  create_user
241
- post user_password_path(format: 'xml'), user: {email: "user@test.com"}
253
+ post user_password_path(format: 'xml'), params: { user: {email: "user@test.com"} }
242
254
  assert_response :success
243
255
  assert_equal response.body, { }.to_xml
244
256
  end
245
257
 
246
258
  test 'reset password request with invalid E-Mail in XML format should return valid response' do
247
259
  create_user
248
- post user_password_path(format: 'xml'), user: {email: "invalid.test@test.com"}
260
+ post user_password_path(format: 'xml'), params: { user: {email: "invalid.test@test.com"} }
249
261
  assert_response :unprocessable_entity
250
262
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
251
263
  end
@@ -253,7 +265,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
253
265
  test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do
254
266
  swap Devise, paranoid: true do
255
267
  create_user
256
- post user_password_path(format: 'xml'), user: {email: "invalid@test.com"}
268
+ post user_password_path(format: 'xml'), params: { user: {email: "invalid@test.com"} }
257
269
  assert_response :success
258
270
  assert_equal response.body, { }.to_xml
259
271
  end
@@ -262,8 +274,9 @@ class PasswordTest < ActionDispatch::IntegrationTest
262
274
  test 'change password with valid parameters in XML format should return valid response' do
263
275
  create_user
264
276
  request_forgot_password
265
- put user_password_path(format: 'xml'), user: {
277
+ put user_password_path(format: 'xml'), params: { user: {
266
278
  reset_password_token: 'abcdef', password: '987654321', password_confirmation: '987654321'
279
+ }
267
280
  }
268
281
  assert_response :success
269
282
  assert warden.authenticated?(:user)
@@ -272,7 +285,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
272
285
  test 'change password with invalid token in XML format should return invalid response' do
273
286
  create_user
274
287
  request_forgot_password
275
- put user_password_path(format: 'xml'), user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'}
288
+ put user_password_path(format: 'xml'), params: { user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} }
276
289
  assert_response :unprocessable_entity
277
290
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
278
291
  end
@@ -280,7 +293,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
280
293
  test 'change password with invalid new password in XML format should return invalid response' do
281
294
  user = create_user
282
295
  request_forgot_password
283
- put user_password_path(format: 'xml'), user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'}
296
+ put user_password_path(format: 'xml'), params: { user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} }
284
297
  assert_response :unprocessable_entity
285
298
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
286
299
  end
@@ -288,7 +301,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
288
301
  test "when using json requests to ask a confirmable request, should not return the object" do
289
302
  user = create_user(confirm: false)
290
303
 
291
- post user_password_path(format: :json), user: { email: user.email }
304
+ post user_password_path(format: :json), params: { user: { email: user.email } }
292
305
 
293
306
  assert_response :success
294
307
  assert_equal response.body, "{}"
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RegistrationTest < ActionDispatch::IntegrationTest
3
+ class RegistrationTest < Devise::IntegrationTest
4
4
 
5
5
  test 'a guest admin should be able to sign in successfully' do
6
6
  get new_admin_session_path
@@ -17,7 +17,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
17
17
  assert warden.authenticated?(:admin)
18
18
  assert_current_url "/admin_area/home"
19
19
 
20
- admin = Admin.order(:id).last
20
+ admin = Admin.to_adapter.find_first(order: [:id, :desc])
21
21
  assert_equal admin.email, 'new_user@test.com'
22
22
  end
23
23
 
@@ -36,6 +36,11 @@ class RegistrationTest < ActionDispatch::IntegrationTest
36
36
  assert_current_url "/?custom=1"
37
37
  end
38
38
 
39
+ test 'a guest admin should not see a warning about minimum password length' do
40
+ get new_admin_session_path
41
+ assert_not_contain 'characters minimum'
42
+ end
43
+
39
44
  def user_sign_up
40
45
  ActionMailer::Base.deliveries.clear
41
46
 
@@ -47,16 +52,21 @@ class RegistrationTest < ActionDispatch::IntegrationTest
47
52
  click_button 'Sign up'
48
53
  end
49
54
 
55
+ test 'a guest user should see a warning about minimum password length' do
56
+ get new_user_registration_path
57
+ assert_contain '7 characters minimum'
58
+ end
59
+
50
60
  test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
51
61
  user_sign_up
52
62
 
53
- assert_contain 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
63
+ assert_contain 'A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.'
54
64
  assert_not_contain 'You have to confirm your account before continuing'
55
65
  assert_current_url "/"
56
66
 
57
67
  assert_not warden.authenticated?(:user)
58
68
 
59
- user = User.order(:id).last
69
+ user = User.to_adapter.find_first(order: [:id, :desc])
60
70
  assert_equal user.email, 'new_user@test.com'
61
71
  assert_not user.confirmed?
62
72
  end
@@ -100,10 +110,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
100
110
  assert_template 'registrations/new'
101
111
  assert_have_selector '#error_explanation'
102
112
  assert_contain "Email is invalid"
103
- assert_contain Devise.rails4? ?
104
- "Password confirmation doesn't match Password" : "Password doesn't match confirmation"
113
+ assert_contain "Password confirmation doesn't match Password"
105
114
  assert_contain "2 errors prohibited"
106
- assert_nil User.first
115
+ assert_nil User.to_adapter.find_first
107
116
 
108
117
  assert_not warden.authenticated?(:user)
109
118
  end
@@ -149,9 +158,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
149
158
  click_button 'Update'
150
159
 
151
160
  assert_current_url '/'
152
- assert_contain 'You updated your account successfully.'
161
+ assert_contain 'Your account has been updated successfully.'
153
162
 
154
- assert_equal "user.new@example.com", User.first.email
163
+ assert_equal "user.new@example.com", User.to_adapter.find_first.email
155
164
  end
156
165
 
157
166
  test 'a signed in user should still be able to use the website after changing their password' do
@@ -163,7 +172,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
163
172
  fill_in 'current password', with: '12345678'
164
173
  click_button 'Update'
165
174
 
166
- assert_contain 'You updated your account successfully.'
175
+ assert_contain 'Your account has been updated successfully.'
167
176
  get users_path
168
177
  assert warden.authenticated?(:user)
169
178
  end
@@ -180,7 +189,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
180
189
  assert_contain 'user@test.com'
181
190
  assert_have_selector 'form input[value="user.new@example.com"]'
182
191
 
183
- assert_equal "user@test.com", User.first.email
192
+ assert_equal "user@test.com", User.to_adapter.find_first.email
184
193
  end
185
194
 
186
195
  test 'a signed in user should be able to edit their password' do
@@ -193,9 +202,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
193
202
  click_button 'Update'
194
203
 
195
204
  assert_current_url '/'
196
- assert_contain 'You updated your account successfully.'
205
+ assert_contain 'Your account has been updated successfully.'
197
206
 
198
- assert User.first.valid_password?('pass1234')
207
+ assert User.to_adapter.find_first.valid_password?('pass1234')
199
208
  end
200
209
 
201
210
  test 'a signed in user should not be able to edit their password with invalid confirmation' do
@@ -207,9 +216,8 @@ class RegistrationTest < ActionDispatch::IntegrationTest
207
216
  fill_in 'current password', with: '12345678'
208
217
  click_button 'Update'
209
218
 
210
- assert_contain Devise.rails4? ?
211
- "Password confirmation doesn't match Password" : "Password doesn't match confirmation"
212
- assert_not User.first.valid_password?('pas123')
219
+ assert_contain "Password confirmation doesn't match Password"
220
+ assert_not User.to_adapter.find_first.valid_password?('pas123')
213
221
  end
214
222
 
215
223
  test 'a signed in user should be able to cancel their account' do
@@ -217,9 +225,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
217
225
  get edit_user_registration_path
218
226
 
219
227
  click_button "Cancel my account"
220
- assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
228
+ assert_contain "Bye! Your account has been successfully cancelled. We hope to see you again soon."
221
229
 
222
- assert User.all.empty?
230
+ assert User.to_adapter.find_all.empty?
223
231
  end
224
232
 
225
233
  test 'a user should be able to cancel sign up by deleting data in the session' do
@@ -249,39 +257,39 @@ class RegistrationTest < ActionDispatch::IntegrationTest
249
257
  end
250
258
 
251
259
  test 'an admin sign up with valid information in XML format should return valid response' do
252
- post admin_registration_path(format: 'xml'), admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' }
260
+ post admin_registration_path(format: 'xml'), params: { admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
253
261
  assert_response :success
254
262
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
255
263
 
256
- admin = Admin.order(:id).last
264
+ admin = Admin.to_adapter.find_first(order: [:id, :desc])
257
265
  assert_equal admin.email, 'new_user@test.com'
258
266
  end
259
267
 
260
268
  test 'a user sign up with valid information in XML format should return valid response' do
261
- post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' }
269
+ post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
262
270
  assert_response :success
263
271
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
264
272
 
265
- user = User.order(:id).last
273
+ user = User.to_adapter.find_first(order: [:id, :desc])
266
274
  assert_equal user.email, 'new_user@test.com'
267
275
  end
268
276
 
269
277
  test 'a user sign up with invalid information in XML format should return invalid response' do
270
- post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' }
278
+ post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } }
271
279
  assert_response :unprocessable_entity
272
280
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
273
281
  end
274
282
 
275
283
  test 'a user update information with valid data in XML format should return valid response' do
276
284
  user = sign_in_as_user
277
- put user_registration_path(format: 'xml'), user: { current_password: '12345678', email: 'user.new@test.com' }
285
+ put user_registration_path(format: 'xml'), params: { user: { current_password: '12345678', email: 'user.new@test.com' } }
278
286
  assert_response :success
279
287
  assert_equal user.reload.email, 'user.new@test.com'
280
288
  end
281
289
 
282
290
  test 'a user update information with invalid data in XML format should return invalid response' do
283
291
  user = sign_in_as_user
284
- put user_registration_path(format: 'xml'), user: { current_password: 'invalid', email: 'user.new@test.com' }
292
+ put user_registration_path(format: 'xml'), params: { user: { current_password: 'invalid', email: 'user.new@test.com' } }
285
293
  assert_response :unprocessable_entity
286
294
  assert_equal user.reload.email, 'user@test.com'
287
295
  end
@@ -290,11 +298,11 @@ class RegistrationTest < ActionDispatch::IntegrationTest
290
298
  sign_in_as_user
291
299
  delete user_registration_path(format: 'xml')
292
300
  assert_response :success
293
- assert_equal User.count, 0
301
+ assert_equal User.to_adapter.find_all.size, 0
294
302
  end
295
303
  end
296
304
 
297
- class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
305
+ class ReconfirmableRegistrationTest < Devise::IntegrationTest
298
306
  test 'a signed in admin should see a more appropriate flash message when editing their account if reconfirmable is enabled' do
299
307
  sign_in_as_admin
300
308
  get edit_admin_registration_path
@@ -305,7 +313,7 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
305
313
 
306
314
  assert_current_url '/admin_area/home'
307
315
  assert_contain 'but we need to verify your new email address'
308
- assert_equal 'admin.new@example.com', Admin.first.unconfirmed_email
316
+ assert_equal 'admin.new@example.com', Admin.to_adapter.find_first.unconfirmed_email
309
317
 
310
318
  get edit_admin_registration_path
311
319
  assert_contain 'Currently waiting confirmation for: admin.new@example.com'
@@ -321,9 +329,9 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
321
329
  click_button 'Update'
322
330
 
323
331
  assert_current_url '/admin_area/home'
324
- assert_contain 'You updated your account successfully.'
332
+ assert_contain 'Your account has been updated successfully.'
325
333
 
326
- assert Admin.first.valid_password?('pas123')
334
+ assert Admin.to_adapter.find_first.valid_password?('pas123')
327
335
  end
328
336
 
329
337
  test 'a signed in admin should not see a reconfirmation message if they did not change their email, despite having an unconfirmed email' do
@@ -341,9 +349,9 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
341
349
  click_button 'Update'
342
350
 
343
351
  assert_current_url '/admin_area/home'
344
- assert_contain 'You updated your account successfully.'
352
+ assert_contain 'Your account has been updated successfully.'
345
353
 
346
- assert_equal "admin.new@example.com", Admin.first.unconfirmed_email
347
- assert Admin.first.valid_password?('pas123')
354
+ assert_equal "admin.new@example.com", Admin.to_adapter.find_first.unconfirmed_email
355
+ assert Admin.to_adapter.find_first.valid_password?('pas123')
348
356
  end
349
357
  end
@@ -1,16 +1,16 @@
1
1
  require 'test_helper'
2
2
 
3
- class RememberMeTest < ActionDispatch::IntegrationTest
3
+ class RememberMeTest < Devise::IntegrationTest
4
4
  def create_user_and_remember(add_to_token='')
5
5
  user = create_user
6
6
  user.remember_me!
7
- raw_cookie = User.serialize_into_cookie(user).tap { |a| a.last << add_to_token }
7
+ raw_cookie = User.serialize_into_cookie(user).tap { |a| a[1] << add_to_token }
8
8
  cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)
9
9
  user
10
10
  end
11
11
 
12
12
  def generate_signed_cookie(raw_cookie)
13
- request = ActionDispatch::TestRequest.new
13
+ request = Devise.rails5? ? ActionDispatch::TestRequest.create : ActionDispatch::TestRequest.new
14
14
  request.cookie_jar.signed['raw_cookie'] = raw_cookie
15
15
  request.cookie_jar['raw_cookie']
16
16
  end
@@ -47,8 +47,10 @@ class RememberMeTest < ActionDispatch::IntegrationTest
47
47
  get new_user_session_path
48
48
  assert request.session[:_csrf_token]
49
49
 
50
- post user_session_path, authenticity_token: "oops", user:
51
- { email: "jose.valim@gmail.com", password: "123456", remember_me: "1" }
50
+ post user_session_path, params: {
51
+ authenticity_token: "oops",
52
+ user: { email: "jose.valim@gmail.com", password: "123456", remember_me: "1" }
53
+ }
52
54
  assert_not warden.authenticated?(:user)
53
55
  assert_not request.cookies['remember_user_token']
54
56
  end
@@ -92,7 +94,6 @@ class RememberMeTest < ActionDispatch::IntegrationTest
92
94
  assert_response :success
93
95
  assert warden.authenticated?(:user)
94
96
  assert warden.user(:user) == user
95
- assert_match /remember_user_token[^\n]*HttpOnly/, response.headers["Set-Cookie"], "Expected Set-Cookie header in response to set HttpOnly flag on remember_user_token cookie."
96
97
  end
97
98
 
98
99
  test 'remember the user before sign up and redirect them to their home' do
@@ -118,6 +119,40 @@ class RememberMeTest < ActionDispatch::IntegrationTest
118
119
  end
119
120
  end
120
121
 
122
+ test 'extends remember period when extend remember period config is true' do
123
+ swap Devise, extend_remember_period: true, remember_for: 1.year do
124
+ user = create_user_and_remember
125
+ old_remember_token = nil
126
+
127
+ travel_to 1.day.ago do
128
+ get root_path
129
+ old_remember_token = request.cookies['remember_user_token']
130
+ end
131
+
132
+ get root_path
133
+ current_remember_token = request.cookies['remember_user_token']
134
+
135
+ refute_equal old_remember_token, current_remember_token
136
+ end
137
+ end
138
+
139
+ test 'does not extend remember period when extend period config is false' do
140
+ swap Devise, extend_remember_period: false, remember_for: 1.year do
141
+ user = create_user_and_remember
142
+ old_remember_token = nil
143
+
144
+ travel_to 1.day.ago do
145
+ get root_path
146
+ old_remember_token = request.cookies['remember_user_token']
147
+ end
148
+
149
+ get root_path
150
+ current_remember_token = request.cookies['remember_user_token']
151
+
152
+ assert_equal old_remember_token, current_remember_token
153
+ end
154
+ end
155
+
121
156
  test 'do not remember other scopes' do
122
157
  create_user_and_remember
123
158
  get root_path
@@ -135,7 +170,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest
135
170
 
136
171
  test 'do not remember with expired token' do
137
172
  create_user_and_remember
138
- swap Devise, remember_for: 0 do
173
+ swap Devise, remember_for: 0.days do
139
174
  get users_path
140
175
  assert_not warden.authenticated?(:user)
141
176
  assert_redirected_to new_user_session_path
@@ -164,4 +199,13 @@ class RememberMeTest < ActionDispatch::IntegrationTest
164
199
  get users_path
165
200
  assert_not warden.authenticated?(:user)
166
201
  end
202
+
203
+ test 'valid sign in calls after_remembered callback' do
204
+ user = create_user_and_remember
205
+
206
+ User.expects(:serialize_from_cookie).returns user
207
+ user.expects :after_remembered
208
+
209
+ get new_user_registration_path
210
+ end
167
211
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class SessionTimeoutTest < ActionDispatch::IntegrationTest
3
+ class SessionTimeoutTest < Devise::IntegrationTest
4
4
 
5
5
  def last_request_at
6
6
  @controller.user_session['last_request_at']
@@ -8,12 +8,11 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
8
8
 
9
9
  test 'set last request at in user session after each request' do
10
10
  sign_in_as_user
11
- old_last_request = last_request_at
12
11
  assert_not_nil last_request_at
13
12
 
13
+ @controller.user_session.delete('last_request_at')
14
14
  get users_path
15
15
  assert_not_nil last_request_at
16
- assert_not_equal old_last_request, last_request_at
17
16
  end
18
17
 
19
18
  test 'set last request at in user session after each request is skipped if tracking is disabled' do
@@ -21,7 +20,19 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
21
20
  old_last_request = last_request_at
22
21
  assert_not_nil last_request_at
23
22
 
24
- get users_path, {}, 'devise.skip_trackable' => true
23
+ get users_path, headers: { 'devise.skip_trackable' => true }
24
+ assert_equal old_last_request, last_request_at
25
+ end
26
+
27
+ test 'does not set last request at in user session after each request if timeoutable is disabled' do
28
+ sign_in_as_user
29
+ old_last_request = last_request_at
30
+ assert_not_nil last_request_at
31
+
32
+ new_time = 2.seconds.from_now
33
+ Time.stubs(:now).returns(new_time)
34
+
35
+ get users_path, headers: { 'devise.skip_timeoutable' => true }
25
36
  assert_equal old_last_request, last_request_at
26
37
  end
27
38
 
@@ -104,30 +115,13 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
104
115
  user = sign_in_as_user
105
116
  get expire_user_path(user)
106
117
 
107
- post "/users/sign_in", email: user.email, password: "123456"
118
+ post "/users/sign_in", params: { email: user.email, password: "123456" }
108
119
 
109
120
  assert_response :redirect
110
121
  follow_redirect!
111
122
  assert_contain 'You are signed in'
112
123
  end
113
124
 
114
- test 'admin does not explode on time out' do
115
- admin = sign_in_as_admin
116
- get expire_admin_path(admin)
117
-
118
- Admin.send :define_method, :reset_authentication_token! do
119
- nil
120
- end
121
-
122
- begin
123
- get admins_path
124
- assert_redirected_to admins_path
125
- assert_not warden.authenticated?(:admin)
126
- ensure
127
- Admin.send(:remove_method, :reset_authentication_token!)
128
- end
129
- end
130
-
131
125
  test 'user configured timeout limit' do
132
126
  swap Devise, timeout_in: 8.minutes do
133
127
  user = sign_in_as_user
@@ -180,4 +174,11 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
180
174
  assert_response :success
181
175
  assert warden.authenticated?(:user)
182
176
  end
177
+
178
+ test 'does not crash when the last_request_at is a String' do
179
+ user = sign_in_as_user
180
+
181
+ get edit_form_user_path(user, last_request_at: Time.now.utc.to_s)
182
+ get users_path
183
+ end
183
184
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class TrackableHooksTest < ActionDispatch::IntegrationTest
3
+ class TrackableHooksTest < Devise::IntegrationTest
4
4
 
5
5
  test "current and last sign in timestamps are updated on each sign in" do
6
6
  user = create_user
@@ -10,8 +10,8 @@ class TrackableHooksTest < ActionDispatch::IntegrationTest
10
10
  sign_in_as_user
11
11
  user.reload
12
12
 
13
- assert_kind_of Time, user.current_sign_in_at
14
- assert_kind_of Time, user.last_sign_in_at
13
+ assert user.current_sign_in_at.acts_like?(:time)
14
+ assert user.last_sign_in_at.acts_like?(:time)
15
15
 
16
16
  assert_equal user.current_sign_in_at, user.last_sign_in_at
17
17
  assert user.current_sign_in_at >= user.created_at
@@ -37,36 +37,36 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
37
37
  assert_equal [user.email], mail.to
38
38
  end
39
39
 
40
- test 'setup sender from configuration' do
40
+ test 'set up sender from configuration' do
41
41
  assert_equal ['test@example.com'], mail.from
42
42
  end
43
43
 
44
- test 'setup sender from custom mailer defaults' do
44
+ test 'set up sender from custom mailer defaults' do
45
45
  Devise.mailer = 'Users::Mailer'
46
46
  assert_equal ['custom@example.com'], mail.from
47
47
  end
48
48
 
49
- test 'setup sender from custom mailer defaults with proc' do
49
+ test 'set up sender from custom mailer defaults with proc' do
50
50
  Devise.mailer = 'Users::FromProcMailer'
51
51
  assert_equal ['custom@example.com'], mail.from
52
52
  end
53
53
 
54
54
  test 'custom mailer renders parent mailer template' do
55
55
  Devise.mailer = 'Users::Mailer'
56
- assert_not_blank mail.body.encoded
56
+ assert_present mail.body.encoded
57
57
  end
58
58
 
59
- test 'setup reply to as copy from sender' do
59
+ test 'set up reply to as copy from sender' do
60
60
  assert_equal ['test@example.com'], mail.reply_to
61
61
  end
62
62
 
63
- test 'setup reply to as different if set in defaults' do
63
+ test 'set up reply to as different if set in defaults' do
64
64
  Devise.mailer = 'Users::ReplyToMailer'
65
65
  assert_equal ['custom@example.com'], mail.from
66
66
  assert_equal ['custom_reply_to@example.com'], mail.reply_to
67
67
  end
68
68
 
69
- test 'setup subject from I18n' do
69
+ test 'set up subject from I18n' do
70
70
  store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do
71
71
  assert_equal 'Account Confirmation', mail.subject
72
72
  end
@@ -83,10 +83,10 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
83
83
  end
84
84
 
85
85
  test 'body should have link to confirm the account' do
86
- host = ActionMailer::Base.default_url_options[:host]
86
+ host, port = ActionMailer::Base.default_url_options.values_at :host, :port
87
87
 
88
- if mail.body.encoded =~ %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=([^"]+)">}
89
- assert_equal Devise.token_generator.digest(user.class, :confirmation_token, $1), user.confirmation_token
88
+ if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/confirmation\?confirmation_token=([^"]+)">}
89
+ assert_equal $1, user.confirmation_token
90
90
  else
91
91
  flunk "expected confirmation url regex to match"
92
92
  end