devise 3.2.2 → 3.2.3

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 (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -1
  4. data/CHANGELOG.md +20 -9
  5. data/CONTRIBUTING.md +2 -2
  6. data/Gemfile +2 -4
  7. data/Gemfile.lock +2 -2
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +69 -30
  10. data/config/locales/en.yml +1 -1
  11. data/devise.gemspec +1 -1
  12. data/gemfiles/{Gemfile.rails-3.2.x → Gemfile.rails-3.2-stable} +3 -5
  13. data/gemfiles/Gemfile.rails-4.0-stable +29 -0
  14. data/gemfiles/Gemfile.rails-head +29 -0
  15. data/lib/devise.rb +3 -3
  16. data/lib/devise/controllers/helpers.rb +1 -1
  17. data/lib/devise/controllers/scoped_views.rb +1 -1
  18. data/lib/devise/controllers/sign_in_out.rb +1 -1
  19. data/lib/devise/hooks/activatable.rb +3 -3
  20. data/lib/devise/hooks/proxy.rb +1 -1
  21. data/lib/devise/hooks/rememberable.rb +1 -1
  22. data/lib/devise/models/authenticatable.rb +2 -2
  23. data/lib/devise/models/confirmable.rb +2 -2
  24. data/lib/devise/models/lockable.rb +7 -4
  25. data/lib/devise/models/rememberable.rb +1 -1
  26. data/lib/devise/models/timeoutable.rb +2 -2
  27. data/lib/devise/modules.rb +1 -1
  28. data/lib/devise/orm/active_record.rb +1 -1
  29. data/lib/devise/orm/mongoid.rb +1 -1
  30. data/lib/devise/rails.rb +7 -1
  31. data/lib/devise/rails/routes.rb +16 -4
  32. data/lib/devise/strategies/authenticatable.rb +4 -4
  33. data/lib/devise/strategies/base.rb +1 -1
  34. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  35. data/lib/devise/time_inflector.rb +1 -1
  36. data/lib/devise/version.rb +1 -1
  37. data/lib/generators/active_record/devise_generator.rb +2 -2
  38. data/lib/generators/devise/install_generator.rb +4 -0
  39. data/lib/generators/templates/README +2 -2
  40. data/lib/generators/templates/devise.rb +8 -4
  41. data/test/controllers/internal_helpers_test.rb +5 -2
  42. data/test/controllers/sessions_controller_test.rb +14 -10
  43. data/test/generators/mongoid_generator_test.rb +2 -2
  44. data/test/integration/recoverable_test.rb +7 -7
  45. data/test/integration/registerable_test.rb +9 -9
  46. data/test/integration/rememberable_test.rb +2 -2
  47. data/test/integration/trackable_test.rb +1 -1
  48. data/test/mapping_test.rb +3 -3
  49. data/test/models/confirmable_test.rb +1 -1
  50. data/test/models/database_authenticatable_test.rb +1 -1
  51. data/test/models/lockable_test.rb +24 -6
  52. data/test/models/recoverable_test.rb +3 -3
  53. data/test/omniauth/config_test.rb +1 -1
  54. data/test/orm/mongoid.rb +1 -1
  55. data/test/rails_app/app/active_record/shim.rb +1 -1
  56. data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
  57. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
  58. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
  59. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +1 -1
  60. data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
  61. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
  62. data/test/rails_app/app/views/home/index.html.erb +1 -1
  63. data/test/rails_app/app/views/home/join.html.erb +1 -1
  64. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
  65. data/test/rails_app/config/initializers/devise.rb +2 -2
  66. data/test/rails_app/config/routes.rb +2 -1
  67. data/test/routes_test.rb +12 -0
  68. data/test/support/action_controller/record_identifier.rb +10 -0
  69. data/test/support/mongoid.yml +6 -0
  70. data/test/test_helpers_test.rb +2 -2
  71. metadata +30 -37
  72. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
@@ -7,12 +7,12 @@ if DEVISE_ORM == :mongoid
7
7
  tests Mongoid::Generators::DeviseGenerator
8
8
  destination File.expand_path("../../tmp", __FILE__)
9
9
  setup :prepare_destination
10
-
10
+
11
11
  test "all files are properly created" do
12
12
  run_generator %w(monster)
13
13
  assert_file "app/models/monster.rb", /devise/
14
14
  end
15
-
15
+
16
16
  test "all files are properly deleted" do
17
17
  run_generator %w(monster)
18
18
  run_generator %w(monster), :behavior => :revoke
@@ -39,7 +39,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
39
39
  end
40
40
 
41
41
  assert_current_url '/users/sign_in'
42
- assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
42
+ assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'
43
43
  end
44
44
 
45
45
  test 'reset password with email should send an email from a custom mailer' do
@@ -78,7 +78,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
78
78
  end
79
79
 
80
80
  assert_current_url '/users/sign_in'
81
- assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
81
+ assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'
82
82
  end
83
83
 
84
84
  test 'reset password with email with extra whitespace should fail when email is NOT the list of strip whitespace keys' do
@@ -111,7 +111,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
111
111
  request_forgot_password
112
112
 
113
113
  assert_current_url '/users/sign_in'
114
- assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
114
+ assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'
115
115
  end
116
116
 
117
117
  test 'not authenticated user with invalid email should receive an error message' do
@@ -139,7 +139,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
139
139
  assert_redirected_to "/users/sign_in"
140
140
  end
141
141
 
142
- test 'not authenticated user with invalid reset password token should not be able to change his password' do
142
+ test 'not authenticated user with invalid reset password token should not be able to change their password' do
143
143
  user = create_user
144
144
  reset_password :reset_password_token => 'invalid_reset_password'
145
145
 
@@ -150,7 +150,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
150
150
  assert_not user.reload.valid_password?('987654321')
151
151
  end
152
152
 
153
- test 'not authenticated user with valid reset password token but invalid password should not be able to change his password' do
153
+ test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do
154
154
  user = create_user
155
155
  request_forgot_password
156
156
  reset_password do
@@ -165,7 +165,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
165
165
  assert_not user.reload.valid_password?('987654321')
166
166
  end
167
167
 
168
- test 'not authenticated user with valid data should be able to change his password' do
168
+ test 'not authenticated user with valid data should be able to change their password' do
169
169
  user = create_user
170
170
  request_forgot_password
171
171
  reset_password
@@ -175,7 +175,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
175
175
  assert user.reload.valid_password?('987654321')
176
176
  end
177
177
 
178
- test 'after entering invalid data user should still be able to change his password' do
178
+ test 'after entering invalid data user should still be able to change their password' do
179
179
  user = create_user
180
180
  request_forgot_password
181
181
 
@@ -140,7 +140,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
140
140
  assert_redirected_to root_path
141
141
  end
142
142
 
143
- test 'a signed in user should be able to edit his account' do
143
+ test 'a signed in user should be able to edit their account' do
144
144
  sign_in_as_user
145
145
  get edit_user_registration_path
146
146
 
@@ -154,7 +154,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
154
154
  assert_equal "user.new@example.com", User.first.email
155
155
  end
156
156
 
157
- test 'a signed in user should still be able to use the website after changing his password' do
157
+ test 'a signed in user should still be able to use the website after changing their password' do
158
158
  sign_in_as_user
159
159
  get edit_user_registration_path
160
160
 
@@ -168,7 +168,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
168
168
  assert warden.authenticated?(:user)
169
169
  end
170
170
 
171
- test 'a signed in user should not change his current user with invalid password' do
171
+ test 'a signed in user should not change their current user with invalid password' do
172
172
  sign_in_as_user
173
173
  get edit_user_registration_path
174
174
 
@@ -183,7 +183,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
183
183
  assert_equal "user@test.com", User.first.email
184
184
  end
185
185
 
186
- test 'a signed in user should be able to edit his password' do
186
+ test 'a signed in user should be able to edit their password' do
187
187
  sign_in_as_user
188
188
  get edit_user_registration_path
189
189
 
@@ -198,7 +198,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
198
198
  assert User.first.valid_password?('pass1234')
199
199
  end
200
200
 
201
- test 'a signed in user should not be able to edit his password with invalid confirmation' do
201
+ test 'a signed in user should not be able to edit their password with invalid confirmation' do
202
202
  sign_in_as_user
203
203
  get edit_user_registration_path
204
204
 
@@ -212,7 +212,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
212
212
  assert_not User.first.valid_password?('pas123')
213
213
  end
214
214
 
215
- test 'a signed in user should be able to cancel his account' do
215
+ test 'a signed in user should be able to cancel their account' do
216
216
  sign_in_as_user
217
217
  get edit_user_registration_path
218
218
 
@@ -286,7 +286,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
286
286
  assert_equal user.reload.email, 'user@test.com'
287
287
  end
288
288
 
289
- test 'a user cancel his account in XML format should return valid response' do
289
+ test 'a user cancel their account in XML format should return valid response' do
290
290
  sign_in_as_user
291
291
  delete user_registration_path(:format => 'xml')
292
292
  assert_response :success
@@ -295,7 +295,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
295
295
  end
296
296
 
297
297
  class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
298
- test 'a signed in admin should see a more appropriate flash message when editing his account if reconfirmable is enabled' do
298
+ test 'a signed in admin should see a more appropriate flash message when editing their account if reconfirmable is enabled' do
299
299
  sign_in_as_admin
300
300
  get edit_admin_registration_path
301
301
 
@@ -326,7 +326,7 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
326
326
  assert Admin.first.valid_password?('pas123')
327
327
  end
328
328
 
329
- test 'a signed in admin should not see a reconfirmation message if he did not change his email, despite having an unconfirmed email' do
329
+ test 'a signed in admin should not see a reconfirmation message if they did not change their email, despite having an unconfirmed email' do
330
330
  sign_in_as_admin
331
331
 
332
332
  get edit_admin_registration_path
@@ -25,7 +25,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest
25
25
  Time.parse(expires).utc
26
26
  end
27
27
 
28
- test 'do not remember the user if he has not checked remember me option' do
28
+ test 'do not remember the user if they have not checked remember me option' do
29
29
  sign_in_as_user
30
30
  assert_nil request.cookies["remember_user_cookie"]
31
31
  end
@@ -95,7 +95,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest
95
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
96
  end
97
97
 
98
- test 'remember the user before sign up and redirect him to his home' do
98
+ test 'remember the user before sign up and redirect them to their home' do
99
99
  create_user_and_remember
100
100
  get new_user_registration_path
101
101
  assert warden.authenticated?(:user)
@@ -63,7 +63,7 @@ class TrackableHooksTest < ActionDispatch::IntegrationTest
63
63
  end
64
64
 
65
65
  test "does not update anything if user has signed out along the way" do
66
- swap Devise, :allow_unconfirmed_access_for => 0 do
66
+ swap Devise, :allow_unconfirmed_access_for => 0.days do
67
67
  user = create_user(:confirm => false)
68
68
  sign_in_as_user
69
69
 
@@ -110,12 +110,12 @@ class MappingTest < ActiveSupport::TestCase
110
110
  assert mapping.lockable?
111
111
  assert_not mapping.omniauthable?
112
112
  end
113
-
113
+
114
114
  test 'find mapping by path' do
115
115
  assert_raise RuntimeError do
116
116
  Devise::Mapping.find_by_path!('/accounts/facebook/callback')
117
117
  end
118
-
118
+
119
119
  assert_nothing_raised do
120
120
  Devise::Mapping.find_by_path!('/:locale/accounts/login')
121
121
  end
@@ -123,5 +123,5 @@ class MappingTest < ActiveSupport::TestCase
123
123
  assert_nothing_raised do
124
124
  Devise::Mapping.find_by_path!('/accounts/facebook/callback', :path)
125
125
  end
126
- end
126
+ end
127
127
  end
@@ -155,7 +155,7 @@ class ConfirmableTest < ActiveSupport::TestCase
155
155
  assert_not_nil user.reload.confirmation_token
156
156
  end
157
157
 
158
- test 'should not resend email instructions if the user change his email' do
158
+ test 'should not resend email instructions if the user change their email' do
159
159
  user = create_user
160
160
  user.email = 'new_test@example.com'
161
161
  assert_email_not_sent do
@@ -231,7 +231,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
231
231
  assert !user.valid?
232
232
  end
233
233
 
234
- test 'required_fiels should be encryptable_password and the email field by default' do
234
+ test 'required_fields should be encryptable_password and the email field by default' do
235
235
  assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
236
236
  :email,
237
237
  :encrypted_password
@@ -9,7 +9,7 @@ class LockableTest < ActiveSupport::TestCase
9
9
  user = create_user
10
10
  user.confirm!
11
11
  swap Devise, :maximum_attempts => 2 do
12
- 3.times { user.valid_for_authentication?{ false } }
12
+ 2.times { user.valid_for_authentication?{ false } }
13
13
  assert user.reload.access_locked?
14
14
  end
15
15
  end
@@ -19,12 +19,12 @@ class LockableTest < ActiveSupport::TestCase
19
19
  user.confirm!
20
20
 
21
21
  swap Devise, :maximum_attempts => 2 do
22
- 3.times { user.valid_for_authentication?{ false } }
22
+ 2.times { user.valid_for_authentication?{ false } }
23
23
  assert user.reload.access_locked?
24
24
  end
25
25
 
26
26
  user.valid_for_authentication?{ true }
27
- assert_equal 4, user.reload.failed_attempts
27
+ assert_equal 3, user.reload.failed_attempts
28
28
  end
29
29
 
30
30
  test "should not touch failed_attempts if lock_strategy is none" do
@@ -130,6 +130,24 @@ class LockableTest < ActiveSupport::TestCase
130
130
  end
131
131
  end
132
132
 
133
+ test "doesn't send email when you pass option send_instructions to false" do
134
+ swap Devise, :unlock_strategy => :email do
135
+ user = create_user
136
+ assert_email_not_sent do
137
+ user.lock_access! send_instructions: false
138
+ end
139
+ end
140
+ end
141
+
142
+ test "sends email when you pass options other than send_instructions" do
143
+ swap Devise, :unlock_strategy => :email do
144
+ user = create_user
145
+ assert_email_sent do
146
+ user.lock_access! foo: :bar, bar: :foo
147
+ end
148
+ end
149
+ end
150
+
133
151
  test "should not send email with unlock instructions when :email is not an unlock strategy" do
134
152
  swap Devise, :unlock_strategy => :time do
135
153
  user = create_user
@@ -284,13 +302,13 @@ class LockableTest < ActiveSupport::TestCase
284
302
  swap Devise, :last_attempt_warning => :true do
285
303
  swap Devise, :lock_strategy => :failed_attempts do
286
304
  user = create_user
287
- user.failed_attempts = Devise.maximum_attempts - 1
305
+ user.failed_attempts = Devise.maximum_attempts - 2
288
306
  assert_equal :invalid, user.unauthenticated_message
289
307
 
290
- user.failed_attempts = Devise.maximum_attempts
308
+ user.failed_attempts = Devise.maximum_attempts - 1
291
309
  assert_equal :last_attempt, user.unauthenticated_message
292
310
 
293
- user.failed_attempts = Devise.maximum_attempts + 1
311
+ user.failed_attempts = Devise.maximum_attempts
294
312
  assert_equal :locked, user.unauthenticated_message
295
313
  end
296
314
  end
@@ -101,14 +101,14 @@ class RecoverableTest < ActiveSupport::TestCase
101
101
  assert_not_equal token, user.reload.reset_password_token
102
102
  end
103
103
 
104
- test 'should send email instructions to the user reset his password' do
104
+ test 'should send email instructions to the user reset their password' do
105
105
  user = create_user
106
106
  assert_email_sent do
107
107
  User.send_reset_password_instructions(:email => user.email)
108
108
  end
109
109
  end
110
110
 
111
- test 'should find a user to reset his password based on the raw token' do
111
+ test 'should find a user to reset their password based on the raw token' do
112
112
  user = create_user
113
113
  raw = user.send_reset_password_instructions
114
114
 
@@ -180,5 +180,5 @@ class RecoverableTest < ActiveSupport::TestCase
180
180
  :reset_password_sent_at,
181
181
  :reset_password_token
182
182
  ]
183
- end
183
+ end
184
184
  end
@@ -54,4 +54,4 @@ class OmniAuthConfigTest < ActiveSupport::TestCase
54
54
  config_class = config.strategy_class
55
55
  assert_equal MyStrategy, config_class
56
56
  end
57
- end
57
+ end
@@ -1,7 +1,7 @@
1
1
  require 'mongoid/version'
2
2
 
3
3
  Mongoid.configure do |config|
4
- config.connect_to("devise-test-suite")
4
+ config.load!('test/support/mongoid.yml')
5
5
  config.use_utc = true
6
6
  config.include_root_in_json = true
7
7
  end
@@ -1,2 +1,2 @@
1
1
  module Shim
2
- end
2
+ end
@@ -3,4 +3,4 @@ class Admins::SessionsController < Devise::SessionsController
3
3
  flash[:special] = "Welcome to #{controller_path.inspect} controller!"
4
4
  super
5
5
  end
6
- end
6
+ end
@@ -1,2 +1,2 @@
1
1
  class Publisher::RegistrationsController < ApplicationController
2
- end
2
+ end
@@ -1,2 +1,2 @@
1
1
  class Publisher::SessionsController < ApplicationController
2
- end
2
+ end
@@ -11,4 +11,4 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
11
11
  sign_in user
12
12
  render :text => ""
13
13
  end
14
- end
14
+ end
@@ -1,2 +1,2 @@
1
1
  Welcome to "sessions/new" view!
2
- <%= render :file => "devise/sessions/new" %>
2
+ <%= render :file => "devise/sessions/new" %>
@@ -1 +1 @@
1
- Admin dashboard
1
+ Admin dashboard
@@ -1 +1 @@
1
- Home!
1
+ Home!
@@ -1 +1 @@
1
- Join
1
+ Join
@@ -1 +1 @@
1
- User dashboard
1
+ User dashboard
@@ -66,8 +66,8 @@ Devise.setup do |config|
66
66
  config.stretches = Rails.env.test? ? 1 : 10
67
67
 
68
68
  # ==> Configuration for :confirmable
69
- # The time you want to give your user to confirm his account. During this time
70
- # he will be able to access your application without confirming. Default is nil.
69
+ # The time you want to give your user to confirm their account. During this time
70
+ # they will be able to access your application without confirming. Default is nil.
71
71
  # When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming.
72
72
  # You can use this to let your user access some features of your application
73
73
  # without confirming the account, but blocking it after a certain period
@@ -86,7 +86,8 @@ Rails.application.routes.draw do
86
86
  :sign_in => "login", :sign_out => "logout",
87
87
  :password => "secret", :confirmation => "verification",
88
88
  :unlock => "unblock", :sign_up => "register",
89
- :registration => "management", :cancel => "giveup"
89
+ :registration => "management",
90
+ :cancel => "giveup", :edit => "edit/profile"
90
91
  }, :failure_app => lambda { |env| [404, {"Content-Type" => "text/plain"}, ["Oops, not found"]] }, :module => :devise
91
92
  end
92
93
 
@@ -157,6 +157,10 @@ class CustomizedRoutingTest < ActionController::TestCase
157
157
  assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register')
158
158
  end
159
159
 
160
+ test 'map account with custom path name for edit registration' do
161
+ assert_recognizes({:controller => 'devise/registrations', :action => 'edit', :locale => 'en'}, '/en/accounts/management/edit/profile')
162
+ end
163
+
160
164
  test 'map account with custom path name for cancel registration' do
161
165
  assert_recognizes({:controller => 'devise/registrations', :action => 'cancel', :locale => 'en'}, '/en/accounts/management/giveup')
162
166
  end
@@ -235,6 +239,14 @@ class CustomizedRoutingTest < ActionController::TestCase
235
239
  test 'map with format false is not permanent' do
236
240
  assert_equal "/set.xml", @routes.url_helpers.set_path(:xml)
237
241
  end
242
+
243
+ test 'checks if mapping has proper configuration for omniauth callback' do
244
+ assert_raise ArgumentError do
245
+ @routes.dup.eval_block do
246
+ devise_for :admin, controllers: {omniauth_callbacks: "users/omniauth_callbacks"}
247
+ end
248
+ end
249
+ end
238
250
  end
239
251
 
240
252
  class ScopedRoutingTest < ActionController::TestCase
@@ -0,0 +1,10 @@
1
+ # Since webrat uses ActionController::RecordIdentifier class that was moved to
2
+ # ActionView namespace in Rails 4.1+
3
+
4
+ unless defined?(ActionController::RecordIdentifier)
5
+ require 'action_view/record_identifier'
6
+
7
+ module ActionController
8
+ RecordIdentifier = ActionView::RecordIdentifier
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ database: devise-test-suite
5
+ hosts:
6
+ - localhost:<%= ENV['MONGODB_PORT'] || '27017' %>