devise 4.1.1 → 4.2.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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -7
  3. data/CHANGELOG.md +46 -2
  4. data/CONTRIBUTING.md +30 -7
  5. data/Gemfile +14 -7
  6. data/Gemfile.lock +96 -81
  7. data/README.md +89 -37
  8. data/app/controllers/devise/omniauth_callbacks_controller.rb +3 -3
  9. data/app/controllers/devise/registrations_controller.rb +3 -3
  10. data/app/views/devise/registrations/edit.html.erb +4 -0
  11. data/gemfiles/Gemfile.rails-4.1-stable +4 -4
  12. data/gemfiles/Gemfile.rails-4.1-stable.lock +27 -23
  13. data/gemfiles/Gemfile.rails-4.2-stable +4 -4
  14. data/gemfiles/Gemfile.rails-4.2-stable.lock +58 -54
  15. data/guides/bug_report_templates/integration_test.rb +104 -0
  16. data/lib/devise.rb +21 -14
  17. data/lib/devise/controllers/helpers.rb +12 -1
  18. data/lib/devise/controllers/rememberable.rb +1 -1
  19. data/lib/devise/controllers/sign_in_out.rb +25 -10
  20. data/lib/devise/failure_app.rb +25 -17
  21. data/lib/devise/hooks/proxy.rb +1 -1
  22. data/lib/devise/models/authenticatable.rb +23 -2
  23. data/lib/devise/models/confirmable.rb +13 -7
  24. data/lib/devise/models/database_authenticatable.rb +0 -5
  25. data/lib/devise/models/recoverable.rb +10 -15
  26. data/lib/devise/omniauth/url_helpers.rb +0 -51
  27. data/lib/devise/orm/active_record.rb +3 -1
  28. data/lib/devise/orm/mongoid.rb +4 -2
  29. data/lib/devise/parameter_sanitizer.rb +0 -55
  30. data/lib/devise/rails.rb +3 -1
  31. data/lib/devise/test/controller_helpers.rb +162 -0
  32. data/lib/devise/test/integration_helpers.rb +61 -0
  33. data/lib/devise/test_helpers.rb +5 -129
  34. data/lib/devise/version.rb +1 -1
  35. data/lib/generators/templates/README +1 -8
  36. data/lib/generators/templates/devise.rb +6 -0
  37. data/test/controllers/custom_registrations_controller_test.rb +1 -1
  38. data/test/controllers/custom_strategy_test.rb +1 -1
  39. data/test/controllers/helpers_test.rb +4 -4
  40. data/test/controllers/internal_helpers_test.rb +1 -1
  41. data/test/controllers/passwords_controller_test.rb +1 -1
  42. data/test/controllers/sessions_controller_test.rb +2 -2
  43. data/test/devise_test.rb +9 -9
  44. data/test/failure_app_test.rb +18 -0
  45. data/test/integration/authenticatable_test.rb +36 -36
  46. data/test/integration/confirmable_test.rb +7 -7
  47. data/test/integration/database_authenticatable_test.rb +5 -5
  48. data/test/integration/http_authenticatable_test.rb +2 -2
  49. data/test/integration/lockable_test.rb +1 -1
  50. data/test/integration/mounted_engine_test.rb +36 -0
  51. data/test/integration/omniauthable_test.rb +1 -1
  52. data/test/integration/recoverable_test.rb +4 -4
  53. data/test/integration/registerable_test.rb +12 -6
  54. data/test/integration/rememberable_test.rb +10 -10
  55. data/test/integration/timeoutable_test.rb +5 -5
  56. data/test/mapping_test.rb +1 -1
  57. data/test/models/confirmable_test.rb +33 -25
  58. data/test/models/database_authenticatable_test.rb +13 -13
  59. data/test/models/lockable_test.rb +16 -16
  60. data/test/models/omniauthable_test.rb +1 -1
  61. data/test/models/recoverable_test.rb +10 -10
  62. data/test/models/registerable_test.rb +1 -1
  63. data/test/models/rememberable_test.rb +16 -3
  64. data/test/models/serializable_test.rb +5 -0
  65. data/test/models/timeoutable_test.rb +7 -7
  66. data/test/models/trackable_test.rb +1 -1
  67. data/test/models/validatable_test.rb +1 -1
  68. data/test/models_test.rb +2 -2
  69. data/test/parameter_sanitizer_test.rb +0 -56
  70. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +1 -1
  71. data/test/rails_app/config/environments/production.rb +3 -1
  72. data/test/rails_app/config/environments/test.rb +5 -6
  73. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +5 -1
  74. data/test/support/assertions.rb +0 -11
  75. data/test/{test_helpers_test.rb → test/controller_helpers_test.rb} +2 -2
  76. data/test/test/integration_helpers_test.rb +32 -0
  77. metadata +11 -6
  78. data/gemfiles/Gemfile.rails-5.0-beta +0 -37
  79. data/gemfiles/Gemfile.rails-5.0-beta.lock +0 -199
@@ -41,12 +41,12 @@ class ConfirmationTest < Devise::IntegrationTest
41
41
  test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do
42
42
  swap Devise, confirm_within: 3.days do
43
43
  user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
44
- assert_not user.confirmed?
44
+ refute user.confirmed?
45
45
  visit_user_confirmation_with_token(user.raw_confirmation_token)
46
46
 
47
47
  assert_have_selector '#error_explanation'
48
48
  assert_contain %r{needs to be confirmed within 3 days}
49
- assert_not user.reload.confirmed?
49
+ refute user.reload.confirmed?
50
50
  assert_current_url "/users/confirmation?confirmation_token=#{user.raw_confirmation_token}"
51
51
  end
52
52
  end
@@ -84,7 +84,7 @@ class ConfirmationTest < Devise::IntegrationTest
84
84
  test 'user with valid confirmation token should be able to confirm an account before the token has expired' do
85
85
  swap Devise, confirm_within: 3.days do
86
86
  user = create_user(confirm: false, confirmation_sent_at: 2.days.ago)
87
- assert_not user.confirmed?
87
+ refute user.confirmed?
88
88
  visit_user_confirmation_with_token(user.raw_confirmation_token)
89
89
 
90
90
  assert_contain 'Your email address has been successfully confirmed.'
@@ -130,7 +130,7 @@ class ConfirmationTest < Devise::IntegrationTest
130
130
  sign_in_as_user(confirm: false)
131
131
 
132
132
  assert_contain 'You have to confirm your email address before continuing'
133
- assert_not warden.authenticated?(:user)
133
+ refute warden.authenticated?(:user)
134
134
  end
135
135
  end
136
136
 
@@ -141,7 +141,7 @@ class ConfirmationTest < Devise::IntegrationTest
141
141
  end
142
142
 
143
143
  assert_contain 'Invalid Email or password'
144
- assert_not warden.authenticated?(:user)
144
+ refute warden.authenticated?(:user)
145
145
  end
146
146
  end
147
147
 
@@ -284,7 +284,7 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
284
284
  assert_contain 'Your email address has been successfully confirmed.'
285
285
  assert_current_url '/admin_area/sign_in'
286
286
  assert admin.reload.confirmed?
287
- assert_not admin.reload.pending_reconfirmation?
287
+ refute admin.reload.pending_reconfirmation?
288
288
  end
289
289
 
290
290
  test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do
@@ -306,7 +306,7 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
306
306
  assert_contain 'Your email address has been successfully confirmed.'
307
307
  assert_current_url '/admin_area/sign_in'
308
308
  assert admin.reload.confirmed?
309
- assert_not admin.reload.pending_reconfirmation?
309
+ refute admin.reload.pending_reconfirmation?
310
310
  end
311
311
 
312
312
  test 'admin email should be unique also within unconfirmed_email' do
@@ -19,7 +19,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
19
19
  fill_in 'email', with: 'foo@bar.com'
20
20
  end
21
21
 
22
- assert_not warden.authenticated?(:user)
22
+ refute warden.authenticated?(:user)
23
23
  end
24
24
  end
25
25
 
@@ -41,14 +41,14 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
41
41
  fill_in 'email', with: ' foo@bar.com '
42
42
  end
43
43
 
44
- assert_not warden.authenticated?(:user)
44
+ refute warden.authenticated?(:user)
45
45
  end
46
46
  end
47
47
 
48
48
  test 'sign in should not authenticate if not using proper authentication keys' do
49
49
  swap Devise, authentication_keys: [:username] do
50
50
  sign_in_as_user
51
- assert_not warden.authenticated?(:user)
51
+ refute warden.authenticated?(:user)
52
52
  end
53
53
  end
54
54
 
@@ -59,7 +59,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
59
59
  end
60
60
 
61
61
  assert_contain 'Invalid email address'
62
- assert_not warden.authenticated?(:admin)
62
+ refute warden.authenticated?(:admin)
63
63
  end
64
64
  end
65
65
 
@@ -69,7 +69,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
69
69
  end
70
70
 
71
71
  assert_contain 'Invalid Email or password'
72
- assert_not warden.authenticated?(:admin)
72
+ refute warden.authenticated?(:admin)
73
73
  end
74
74
 
75
75
  test 'error message is configurable by resource name' do
@@ -65,7 +65,7 @@ class HttpAuthenticationTest < Devise::IntegrationTest
65
65
  end
66
66
 
67
67
  test 'it uses appropriate authentication_keys when configured with hash' do
68
- swap Devise, authentication_keys: ActiveSupport::OrderedHash[:username, false, :email, false] do
68
+ swap Devise, authentication_keys: { username: false, email: false } do
69
69
  sign_in_as_new_user_with_http("usertest")
70
70
  assert_response :success
71
71
  assert_match '<email>user@test.com</email>', response.body
@@ -74,7 +74,7 @@ class HttpAuthenticationTest < Devise::IntegrationTest
74
74
  end
75
75
 
76
76
  test 'it uses the appropriate key when configured explicitly' do
77
- swap Devise, authentication_keys: ActiveSupport::OrderedHash[:email, false, :username, false], http_authentication_key: :username do
77
+ swap Devise, authentication_keys: { email: false, username: false }, http_authentication_key: :username do
78
78
  sign_in_as_new_user_with_http("usertest")
79
79
  assert_response :success
80
80
  assert_match '<email>user@test.com</email>', response.body
@@ -85,7 +85,7 @@ class LockTest < Devise::IntegrationTest
85
85
 
86
86
  assert_current_url "/users/sign_in"
87
87
  assert_contain 'Your account has been unlocked successfully. Please sign in to continue.'
88
- assert_not user.reload.access_locked?
88
+ refute user.reload.access_locked?
89
89
  end
90
90
 
91
91
  test "user should not send a new e-mail if already locked" do
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ class MyMountableEngine
4
+ def self.call(env)
5
+ ['200', { 'Content-Type' => 'text/html' }, ['Rendered content of MyMountableEngine']]
6
+ end
7
+ end
8
+
9
+ # If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling
10
+ # again the draw method. Look at the source code at:
11
+ # http://www.rubydoc.info/docs/rails/ActionDispatch/Routing/RouteSet:draw
12
+ Rails.application.routes.disable_clear_and_finalize = true
13
+
14
+ Rails.application.routes.draw do
15
+ authenticate(:user) do
16
+ mount MyMountableEngine, at: '/mountable_engine'
17
+ end
18
+ end
19
+
20
+ class AuthenticatedMountedEngineTest < Devise::IntegrationTest
21
+ test 'redirects to the sign in page when not authenticated' do
22
+ get '/mountable_engine'
23
+ follow_redirect!
24
+
25
+ assert_response :ok
26
+ assert_contain 'You need to sign in or sign up before continuing.'
27
+ end
28
+
29
+ test 'renders the mounted engine when authenticated' do
30
+ sign_in_as_user
31
+ get '/mountable_engine'
32
+
33
+ assert_response :success
34
+ assert_contain 'Rendered content of MyMountableEngine'
35
+ end
36
+ end
@@ -71,7 +71,7 @@ class OmniauthableIntegrationTest < Devise::IntegrationTest
71
71
  assert_current_url "/"
72
72
  assert_contain "You have signed up successfully."
73
73
  assert_contain "Hello User user@example.com"
74
- assert_not session["devise.facebook_data"]
74
+ refute session["devise.facebook_data"]
75
75
  end
76
76
 
77
77
  test "cleans up session on cancel" do
@@ -10,7 +10,7 @@ class PasswordTest < Devise::IntegrationTest
10
10
  def request_forgot_password(&block)
11
11
  visit_new_password_path
12
12
  assert_response :success
13
- assert_not warden.authenticated?(:user)
13
+ refute warden.authenticated?(:user)
14
14
 
15
15
  fill_in 'email', with: 'user@test.com'
16
16
  yield if block_given?
@@ -147,7 +147,7 @@ class PasswordTest < Devise::IntegrationTest
147
147
  assert_current_url '/users/password'
148
148
  assert_have_selector '#error_explanation'
149
149
  assert_contain %r{Reset password token(.*)invalid}
150
- assert_not user.reload.valid_password?('987654321')
150
+ refute user.reload.valid_password?('987654321')
151
151
  end
152
152
 
153
153
  test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do
@@ -161,7 +161,7 @@ class PasswordTest < Devise::IntegrationTest
161
161
  assert_current_url '/users/password'
162
162
  assert_have_selector '#error_explanation'
163
163
  assert_contain "Password confirmation doesn't match Password"
164
- assert_not user.reload.valid_password?('987654321')
164
+ refute user.reload.valid_password?('987654321')
165
165
  end
166
166
 
167
167
  test 'not authenticated user with valid data should be able to change their password' do
@@ -181,7 +181,7 @@ class PasswordTest < Devise::IntegrationTest
181
181
  reset_password { fill_in 'Confirm new password', with: 'other_password' }
182
182
  assert_response :success
183
183
  assert_have_selector '#error_explanation'
184
- assert_not user.reload.valid_password?('987654321')
184
+ refute user.reload.valid_password?('987654321')
185
185
 
186
186
  reset_password visit: false
187
187
  assert_contain 'Your password has been changed successfully.'
@@ -64,11 +64,11 @@ class RegistrationTest < Devise::IntegrationTest
64
64
  assert_not_contain 'You have to confirm your account before continuing'
65
65
  assert_current_url "/"
66
66
 
67
- assert_not warden.authenticated?(:user)
67
+ refute warden.authenticated?(:user)
68
68
 
69
69
  user = User.to_adapter.find_first(order: [:id, :desc])
70
70
  assert_equal user.email, 'new_user@test.com'
71
- assert_not user.confirmed?
71
+ refute user.confirmed?
72
72
  end
73
73
 
74
74
  test 'a guest user should receive the confirmation instructions from the default mailer' do
@@ -92,7 +92,7 @@ class RegistrationTest < Devise::IntegrationTest
92
92
  click_button 'Sign up'
93
93
 
94
94
  assert_current_url "/?custom=1"
95
- assert_not warden.authenticated?(:user)
95
+ refute warden.authenticated?(:user)
96
96
  end
97
97
 
98
98
  test 'a guest user cannot sign up with invalid information' do
@@ -114,7 +114,7 @@ class RegistrationTest < Devise::IntegrationTest
114
114
  assert_contain "2 errors prohibited"
115
115
  assert_nil User.to_adapter.find_first
116
116
 
117
- assert_not warden.authenticated?(:user)
117
+ refute warden.authenticated?(:user)
118
118
  end
119
119
 
120
120
  test 'a guest should not sign up with email/password that already exists' do
@@ -133,7 +133,7 @@ class RegistrationTest < Devise::IntegrationTest
133
133
  assert_current_url '/users'
134
134
  assert_contain(/Email.*already.*taken/)
135
135
 
136
- assert_not warden.authenticated?(:user)
136
+ refute warden.authenticated?(:user)
137
137
  end
138
138
 
139
139
  test 'a guest should not be able to change account' do
@@ -217,7 +217,13 @@ class RegistrationTest < Devise::IntegrationTest
217
217
  click_button 'Update'
218
218
 
219
219
  assert_contain "Password confirmation doesn't match Password"
220
- assert_not User.to_adapter.find_first.valid_password?('pas123')
220
+ refute User.to_adapter.find_first.valid_password?('pas123')
221
+ end
222
+
223
+ test 'a signed in user should see a warning about minimum password length' do
224
+ sign_in_as_user
225
+ get edit_user_registration_path
226
+ assert_contain 'characters minimum'
221
227
  end
222
228
 
223
229
  test 'a signed in user should be able to cancel their account' do
@@ -33,12 +33,12 @@ class RememberMeTest < Devise::IntegrationTest
33
33
  test 'handle unverified requests gets rid of caches' do
34
34
  swap ApplicationController, allow_forgery_protection: true do
35
35
  post exhibit_user_url(1)
36
- assert_not warden.authenticated?(:user)
36
+ refute warden.authenticated?(:user)
37
37
 
38
38
  create_user_and_remember
39
39
  post exhibit_user_url(1)
40
40
  assert_equal "User is not authenticated", response.body
41
- assert_not warden.authenticated?(:user)
41
+ refute warden.authenticated?(:user)
42
42
  end
43
43
  end
44
44
 
@@ -51,8 +51,8 @@ class RememberMeTest < Devise::IntegrationTest
51
51
  authenticity_token: "oops",
52
52
  user: { email: "jose.valim@gmail.com", password: "123456", remember_me: "1" }
53
53
  }
54
- assert_not warden.authenticated?(:user)
55
- assert_not request.cookies['remember_user_token']
54
+ refute warden.authenticated?(:user)
55
+ refute request.cookies['remember_user_token']
56
56
  end
57
57
  end
58
58
 
@@ -158,13 +158,13 @@ class RememberMeTest < Devise::IntegrationTest
158
158
  get root_path
159
159
  assert_response :success
160
160
  assert warden.authenticated?(:user)
161
- assert_not warden.authenticated?(:admin)
161
+ refute warden.authenticated?(:admin)
162
162
  end
163
163
 
164
164
  test 'do not remember with invalid token' do
165
165
  create_user_and_remember('add')
166
166
  get users_path
167
- assert_not warden.authenticated?(:user)
167
+ refute warden.authenticated?(:user)
168
168
  assert_redirected_to new_user_session_path
169
169
  end
170
170
 
@@ -172,7 +172,7 @@ class RememberMeTest < Devise::IntegrationTest
172
172
  create_user_and_remember
173
173
  swap Devise, remember_for: 0.days do
174
174
  get users_path
175
- assert_not warden.authenticated?(:user)
175
+ refute warden.authenticated?(:user)
176
176
  assert_redirected_to new_user_session_path
177
177
  end
178
178
  end
@@ -183,11 +183,11 @@ class RememberMeTest < Devise::IntegrationTest
183
183
  assert warden.authenticated?(:user)
184
184
 
185
185
  delete destroy_user_session_path
186
- assert_not warden.authenticated?(:user)
186
+ refute warden.authenticated?(:user)
187
187
  assert_nil warden.cookies['remember_user_token']
188
188
 
189
189
  get users_path
190
- assert_not warden.authenticated?(:user)
190
+ refute warden.authenticated?(:user)
191
191
  end
192
192
 
193
193
  test 'changing user password expires remember me token' do
@@ -197,7 +197,7 @@ class RememberMeTest < Devise::IntegrationTest
197
197
  user.save!
198
198
 
199
199
  get users_path
200
- assert_not warden.authenticated?(:user)
200
+ refute warden.authenticated?(:user)
201
201
  end
202
202
 
203
203
  test 'valid sign in calls after_remembered callback' do
@@ -56,7 +56,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
56
56
 
57
57
  get users_path
58
58
  assert_redirected_to users_path
59
- assert_not warden.authenticated?(:user)
59
+ refute warden.authenticated?(:user)
60
60
  assert warden.authenticated?(:admin)
61
61
  end
62
62
  end
@@ -70,8 +70,8 @@ class SessionTimeoutTest < Devise::IntegrationTest
70
70
  assert_not_nil last_request_at
71
71
 
72
72
  get root_path
73
- assert_not warden.authenticated?(:user)
74
- assert_not warden.authenticated?(:admin)
73
+ refute warden.authenticated?(:user)
74
+ refute warden.authenticated?(:admin)
75
75
  end
76
76
  end
77
77
 
@@ -108,7 +108,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
108
108
 
109
109
  assert_response :success
110
110
  assert_contain 'Sign in'
111
- assert_not warden.authenticated?(:user)
111
+ refute warden.authenticated?(:user)
112
112
  end
113
113
 
114
114
  test 'time out is not triggered on sign in' do
@@ -134,7 +134,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
134
134
  get expire_user_path(user)
135
135
  get users_path
136
136
  assert_redirected_to users_path
137
- assert_not warden.authenticated?(:user)
137
+ refute warden.authenticated?(:user)
138
138
  end
139
139
  end
140
140
 
@@ -115,7 +115,7 @@ class MappingTest < ActiveSupport::TestCase
115
115
  assert mapping.authenticatable?
116
116
  assert mapping.recoverable?
117
117
  assert mapping.lockable?
118
- assert_not mapping.omniauthable?
118
+ refute mapping.omniauthable?
119
119
  end
120
120
 
121
121
  test 'find mapping by path' do
@@ -28,9 +28,9 @@ class ConfirmableTest < ActiveSupport::TestCase
28
28
  end
29
29
 
30
30
  test 'should verify whether a user is confirmed or not' do
31
- assert_not new_user.confirmed?
31
+ refute new_user.confirmed?
32
32
  user = create_user
33
- assert_not user.confirmed?
33
+ refute user.confirmed?
34
34
  user.confirm
35
35
  assert user.confirmed?
36
36
  end
@@ -40,7 +40,7 @@ class ConfirmableTest < ActiveSupport::TestCase
40
40
  assert user.confirm
41
41
  assert_blank user.errors[:email]
42
42
 
43
- assert_not user.confirm
43
+ refute user.confirm
44
44
  assert_equal "was already confirmed, please try signing in", user.errors[:email].join
45
45
  end
46
46
 
@@ -54,13 +54,13 @@ class ConfirmableTest < ActiveSupport::TestCase
54
54
 
55
55
  test 'should return a new record with errors when a invalid token is given' do
56
56
  confirmed_user = User.confirm_by_token('invalid_confirmation_token')
57
- assert_not confirmed_user.persisted?
57
+ refute confirmed_user.persisted?
58
58
  assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
59
59
  end
60
60
 
61
61
  test 'should return a new record with errors when a blank token is given' do
62
62
  confirmed_user = User.confirm_by_token('')
63
- assert_not confirmed_user.persisted?
63
+ refute confirmed_user.persisted?
64
64
  assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
65
65
  end
66
66
 
@@ -114,7 +114,7 @@ class ConfirmableTest < ActiveSupport::TestCase
114
114
 
115
115
  assert_email_not_sent do
116
116
  user.save!
117
- assert_not user.confirmed?
117
+ refute user.confirmed?
118
118
  end
119
119
  end
120
120
 
@@ -134,7 +134,7 @@ class ConfirmableTest < ActiveSupport::TestCase
134
134
 
135
135
  test 'should return a new user if no email was found' do
136
136
  confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com")
137
- assert_not confirmation_user.persisted?
137
+ refute confirmation_user.persisted?
138
138
  end
139
139
 
140
140
  test 'should add error to new user email if no email was found' do
@@ -181,7 +181,7 @@ class ConfirmableTest < ActiveSupport::TestCase
181
181
  test 'should not be able to send instructions if the user is already confirmed' do
182
182
  user = create_user
183
183
  user.confirm
184
- assert_not user.resend_confirmation_instructions
184
+ refute user.resend_confirmation_instructions
185
185
  assert user.confirmed?
186
186
  assert_equal 'was already confirmed, please try signing in', user.errors[:email].join
187
187
  end
@@ -190,7 +190,7 @@ class ConfirmableTest < ActiveSupport::TestCase
190
190
  swap Devise, allow_unconfirmed_access_for: 1.day do
191
191
  user = create_user
192
192
  user.confirmation_sent_at = 2.days.ago
193
- assert_not user.active_for_authentication?
193
+ refute user.active_for_authentication?
194
194
 
195
195
  Devise.allow_unconfirmed_access_for = 3.days
196
196
  assert user.active_for_authentication?
@@ -206,14 +206,14 @@ class ConfirmableTest < ActiveSupport::TestCase
206
206
  assert user.active_for_authentication?
207
207
 
208
208
  user.confirmation_sent_at = 5.days.ago
209
- assert_not user.active_for_authentication?
209
+ refute user.active_for_authentication?
210
210
  end
211
211
  end
212
212
 
213
213
  test 'should be active when already confirmed' do
214
214
  user = create_user
215
- assert_not user.confirmed?
216
- assert_not user.active_for_authentication?
215
+ refute user.confirmed?
216
+ refute user.active_for_authentication?
217
217
 
218
218
  user.confirm
219
219
  assert user.confirmed?
@@ -224,7 +224,7 @@ class ConfirmableTest < ActiveSupport::TestCase
224
224
  Devise.allow_unconfirmed_access_for = 0.days
225
225
  user = create_user
226
226
  user.confirmation_sent_at = Time.zone.today
227
- assert_not user.active_for_authentication?
227
+ refute user.active_for_authentication?
228
228
  end
229
229
 
230
230
  test 'should be active when we set allow_unconfirmed_access_for to nil' do
@@ -239,7 +239,7 @@ class ConfirmableTest < ActiveSupport::TestCase
239
239
  user = create_user
240
240
  user.confirmation_sent_at = nil
241
241
  user.save
242
- assert_not user.reload.active_for_authentication?
242
+ refute user.reload.active_for_authentication?
243
243
  end
244
244
 
245
245
  test 'should be active without confirmation when confirmation is not required' do
@@ -272,7 +272,7 @@ class ConfirmableTest < ActiveSupport::TestCase
272
272
  swap Devise, confirmation_keys: [:username, :email] do
273
273
  user = create_user
274
274
  confirm_user = User.send_confirmation_instructions(email: user.email)
275
- assert_not confirm_user.persisted?
275
+ refute confirm_user.persisted?
276
276
  assert_equal "can't be blank", confirm_user.errors[:username].join
277
277
  end
278
278
  end
@@ -297,7 +297,7 @@ class ConfirmableTest < ActiveSupport::TestCase
297
297
 
298
298
  test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
299
299
  swap Devise, confirm_within: 3.days do
300
- assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
300
+ refute confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
301
301
  end
302
302
  end
303
303
 
@@ -337,14 +337,14 @@ class ConfirmableTest < ActiveSupport::TestCase
337
337
  self.username = self.username.to_s + 'updated'
338
338
  end
339
339
  old = user.username
340
- assert_not user.confirm
340
+ refute user.confirm
341
341
  assert_equal user.username, old
342
342
  end
343
343
 
344
344
  test 'should always perform validations upon confirm when ensure valid true' do
345
345
  admin = create_admin
346
346
  admin.stubs(:valid?).returns(false)
347
- assert_not admin.confirm(ensure_valid: true)
347
+ refute admin.confirm(ensure_valid: true)
348
348
  end
349
349
  end
350
350
 
@@ -370,7 +370,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
370
370
  admin.skip_reconfirmation!
371
371
  assert admin.update_attributes(email: 'new_test@example.com')
372
372
  assert admin.confirmed?
373
- assert_not admin.pending_reconfirmation?
373
+ refute admin.pending_reconfirmation?
374
374
  assert_equal original_token, admin.confirmation_token
375
375
  end
376
376
 
@@ -461,7 +461,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
461
461
 
462
462
  test 'should return a new admin if no email or unconfirmed_email was found' do
463
463
  confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com")
464
- assert_not confirmation_admin.persisted?
464
+ refute confirmation_admin.persisted?
465
465
  end
466
466
 
467
467
  test 'should add error to new admin email if no email or unconfirmed_email was found' do
@@ -479,18 +479,18 @@ class ReconfirmableTest < ActiveSupport::TestCase
479
479
  end
480
480
 
481
481
  test 'required_fields should contain the fields that Devise uses' do
482
- assert_same_content Devise::Models::Confirmable.required_fields(User), [
483
- :confirmation_sent_at,
482
+ assert_equal Devise::Models::Confirmable.required_fields(User), [
484
483
  :confirmation_token,
485
- :confirmed_at
484
+ :confirmed_at,
485
+ :confirmation_sent_at
486
486
  ]
487
487
  end
488
488
 
489
489
  test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do
490
- assert_same_content Devise::Models::Confirmable.required_fields(Admin), [
491
- :confirmation_sent_at,
490
+ assert_equal Devise::Models::Confirmable.required_fields(Admin), [
492
491
  :confirmation_token,
493
492
  :confirmed_at,
493
+ :confirmation_sent_at,
494
494
  :unconfirmed_email
495
495
  ]
496
496
  end
@@ -508,4 +508,12 @@ class ReconfirmableTest < ActiveSupport::TestCase
508
508
  admin = Admin::WithSaveInCallback.create(valid_attributes.except(:username))
509
509
  assert !admin.pending_reconfirmation?
510
510
  end
511
+
512
+ test 'should require reconfirmation after creating a record and updating the email' do
513
+ admin = create_admin
514
+ assert !admin.instance_variable_get(:@bypass_confirmation_postpone)
515
+ admin.email = "new_test@email.com"
516
+ admin.save
517
+ assert admin.pending_reconfirmation?
518
+ end
511
519
  end