loyal_devise 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.travis.yml +14 -9
- data/.yardopts +9 -0
- data/CHANGELOG.rdoc +60 -5
- data/CONTRIBUTING.md +4 -2
- data/Gemfile +7 -7
- data/Gemfile.lock +107 -101
- data/MIT-LICENSE +1 -1
- data/README.md +110 -48
- data/Rakefile +1 -0
- data/app/controllers/devise/confirmations_controller.rb +2 -4
- data/app/controllers/devise/omniauth_callbacks_controller.rb +0 -1
- data/app/controllers/devise/passwords_controller.rb +16 -5
- data/app/controllers/devise/registrations_controller.rb +13 -7
- data/app/controllers/devise/sessions_controller.rb +6 -6
- data/app/controllers/devise/unlocks_controller.rb +3 -4
- data/app/controllers/devise_controller.rb +12 -33
- data/app/helpers/devise_helper.rb +0 -1
- data/app/mailers/devise/mailer.rb +7 -8
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +5 -1
- data/config/locales/en.yml +48 -48
- data/devise.gemspec +6 -6
- data/devise.png +0 -0
- data/gemfiles/{Gemfile.rails-3.1.x → Gemfile.rails-3.2.x} +8 -12
- data/gemfiles/Gemfile.rails-3.2.x.lock +156 -0
- data/lib/devise.rb +34 -11
- data/lib/devise/controllers/helpers.rb +33 -7
- data/lib/devise/controllers/rememberable.rb +6 -3
- data/lib/devise/controllers/scoped_views.rb +1 -2
- data/lib/devise/controllers/url_helpers.rb +0 -1
- data/lib/devise/delegator.rb +0 -1
- data/lib/devise/failure_app.rb +8 -2
- data/lib/devise/hooks/activatable.rb +1 -2
- data/lib/devise/hooks/forgetable.rb +0 -1
- data/lib/devise/hooks/lockable.rb +1 -2
- data/lib/devise/hooks/rememberable.rb +1 -2
- data/lib/devise/hooks/timeoutable.rb +0 -1
- data/lib/devise/hooks/trackable.rb +0 -1
- data/lib/devise/mailers/helpers.rb +18 -14
- data/lib/devise/mapping.rb +6 -7
- data/lib/devise/models.rb +0 -1
- data/lib/devise/models/authenticatable.rb +50 -27
- data/lib/devise/models/confirmable.rb +37 -16
- data/lib/devise/models/database_authenticatable.rb +17 -3
- data/lib/devise/models/lockable.rb +1 -2
- data/lib/devise/models/omniauthable.rb +1 -2
- data/lib/devise/models/recoverable.rb +10 -6
- data/lib/devise/models/registerable.rb +0 -1
- data/lib/devise/models/rememberable.rb +1 -2
- data/lib/devise/models/timeoutable.rb +1 -2
- data/lib/devise/models/token_authenticatable.rb +0 -1
- data/lib/devise/models/trackable.rb +0 -1
- data/lib/devise/models/validatable.rb +0 -1
- data/lib/devise/modules.rb +1 -2
- data/lib/devise/omniauth.rb +0 -1
- data/lib/devise/omniauth/config.rb +0 -1
- data/lib/devise/omniauth/url_helpers.rb +0 -1
- data/lib/devise/orm/active_record.rb +1 -2
- data/lib/devise/orm/mongoid.rb +1 -2
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -12
- data/lib/devise/parameter_sanitizer.rb +59 -0
- data/lib/devise/rails.rb +0 -1
- data/lib/devise/rails/routes.rb +22 -18
- data/lib/devise/rails/warden_compat.rb +0 -30
- data/lib/devise/strategies/authenticatable.rb +8 -6
- data/lib/devise/strategies/base.rb +1 -2
- data/lib/devise/strategies/database_authenticatable.rb +1 -2
- data/lib/devise/strategies/rememberable.rb +1 -2
- data/lib/devise/strategies/token_authenticatable.rb +38 -4
- data/lib/devise/test_helpers.rb +0 -1
- data/lib/devise/time_inflector.rb +1 -2
- data/lib/devise/version.rb +1 -2
- data/lib/generators/active_record/devise_generator.rb +1 -5
- data/lib/generators/active_record/templates/migration.rb +0 -1
- data/lib/generators/active_record/templates/migration_existing.rb +0 -1
- data/lib/generators/devise/devise_generator.rb +0 -1
- data/lib/generators/devise/install_generator.rb +0 -1
- data/lib/generators/devise/orm_helpers.rb +1 -2
- data/lib/generators/devise/views_generator.rb +8 -3
- data/lib/generators/mongoid/devise_generator.rb +1 -2
- data/lib/generators/templates/README +1 -1
- data/lib/generators/templates/devise.rb +10 -5
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +1 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +6 -1
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +1 -0
- data/loyal_devise.gemspec +27 -0
- data/test/controllers/custom_strategy_test.rb +0 -1
- data/test/controllers/helpers_test.rb +0 -1
- data/test/controllers/internal_helpers_test.rb +13 -4
- data/test/controllers/passwords_controller_test.rb +32 -0
- data/test/controllers/sessions_controller_test.rb +28 -1
- data/test/controllers/url_helpers_test.rb +0 -1
- data/test/delegator_test.rb +0 -1
- data/test/devise_test.rb +12 -2
- data/test/failure_app_test.rb +3 -4
- data/test/generators/active_record_generator_test.rb +1 -4
- data/test/generators/devise_generator_test.rb +0 -1
- data/test/generators/install_generator_test.rb +0 -1
- data/test/generators/mongoid_generator_test.rb +0 -1
- data/test/generators/views_generator_test.rb +16 -2
- data/test/helpers/devise_helper_test.rb +1 -2
- data/test/integration/authenticatable_test.rb +92 -27
- data/test/integration/confirmable_test.rb +7 -7
- data/test/integration/database_authenticatable_test.rb +8 -7
- data/test/integration/http_authenticatable_test.rb +19 -2
- data/test/integration/lockable_test.rb +1 -2
- data/test/integration/omniauthable_test.rb +2 -3
- data/test/integration/recoverable_test.rb +40 -12
- data/test/integration/registerable_test.rb +17 -14
- data/test/integration/rememberable_test.rb +16 -10
- data/test/integration/timeoutable_test.rb +11 -2
- data/test/integration/token_authenticatable_test.rb +45 -2
- data/test/integration/trackable_test.rb +1 -2
- data/test/mailers/confirmation_instructions_test.rb +11 -3
- data/test/mailers/reset_password_instructions_test.rb +11 -3
- data/test/mailers/unlock_instructions_test.rb +11 -2
- data/test/mapping_test.rb +0 -1
- data/test/models/authenticatable_test.rb +6 -1
- data/test/models/confirmable_test.rb +53 -2
- data/test/models/database_authenticatable_test.rb +57 -21
- data/test/models/lockable_test.rb +1 -2
- data/test/models/omniauthable_test.rb +0 -1
- data/test/models/recoverable_test.rb +21 -5
- data/test/models/registerable_test.rb +0 -1
- data/test/models/rememberable_test.rb +4 -4
- data/test/models/serializable_test.rb +8 -8
- data/test/models/timeoutable_test.rb +0 -1
- data/test/models/token_authenticatable_test.rb +0 -1
- data/test/models/trackable_test.rb +0 -1
- data/test/models/validatable_test.rb +16 -6
- data/test/models_test.rb +7 -24
- data/test/omniauth/config_test.rb +1 -2
- data/test/omniauth/url_helpers_test.rb +4 -2
- data/test/orm/active_record.rb +1 -1
- data/test/orm/mongoid.rb +2 -4
- data/test/parameter_sanitizer_test.rb +51 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/admin.rb +0 -1
- data/test/rails_app/app/active_record/shim.rb +1 -2
- data/test/rails_app/app/active_record/user.rb +0 -1
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -2
- data/test/rails_app/app/controllers/admins_controller.rb +0 -1
- data/test/rails_app/app/controllers/application_controller.rb +1 -1
- data/test/rails_app/app/controllers/home_controller.rb +0 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +1 -2
- data/test/rails_app/app/controllers/users_controller.rb +8 -1
- data/test/rails_app/app/helpers/application_helper.rb +0 -1
- data/test/rails_app/app/mailers/users/mailer.rb +4 -1
- data/test/rails_app/app/mongoid/admin.rb +4 -3
- data/test/rails_app/app/mongoid/shim.rb +3 -5
- data/test/rails_app/app/mongoid/user.rb +2 -3
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +1 -3
- data/test/rails_app/config/boot.rb +3 -4
- data/test/rails_app/config/environment.rb +2 -3
- data/test/rails_app/config/environments/development.rb +23 -8
- data/test/rails_app/config/environments/production.rb +68 -18
- data/test/rails_app/config/environments/test.rb +18 -16
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -1
- data/test/rails_app/config/initializers/devise.rb +0 -1
- data/test/rails_app/config/initializers/inflections.rb +0 -1
- data/test/rails_app/config/initializers/secret_token.rb +8 -3
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +20 -17
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -1
- data/test/rails_app/db/schema.rb +0 -1
- data/test/rails_app/lib/shared_admin.rb +0 -1
- data/test/rails_app/lib/shared_user.rb +0 -2
- data/test/routes_test.rb +22 -21
- data/test/support/assertions.rb +0 -1
- data/test/support/helpers.rb +1 -2
- data/test/support/integration.rb +0 -1
- data/test/support/webrat/integrations/rails.rb +0 -1
- data/test/test_helper.rb +8 -2
- data/test/test_helpers_test.rb +0 -1
- data/test/test_models.rb +26 -0
- metadata +65 -27
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/test/indifferent_hash.rb +0 -34
- data/test/rails_app/script/rails +0 -10
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
5
|
-
|
|
6
4
|
def setup
|
|
7
5
|
setup_mailer
|
|
8
6
|
Devise.mailer = 'Devise::Mailer'
|
|
@@ -50,6 +48,16 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
|
50
48
|
assert_equal ['custom@example.com'], mail.from
|
|
51
49
|
end
|
|
52
50
|
|
|
51
|
+
test 'setup sender from custom mailer defaults with proc' do
|
|
52
|
+
Devise.mailer = 'Users::FromProcMailer'
|
|
53
|
+
assert_equal ['custom@example.com'], mail.from
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
test 'custom mailer renders parent mailer template' do
|
|
57
|
+
Devise.mailer = 'Users::Mailer'
|
|
58
|
+
assert_not_blank mail.body.encoded
|
|
59
|
+
end
|
|
60
|
+
|
|
53
61
|
test 'setup reply to as copy from sender' do
|
|
54
62
|
assert_equal ['test@example.com'], mail.reply_to
|
|
55
63
|
end
|
|
@@ -67,7 +75,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
|
67
75
|
end
|
|
68
76
|
|
|
69
77
|
test 'body should have user info' do
|
|
70
|
-
assert_match
|
|
78
|
+
assert_match user.email, mail.body.encoded
|
|
71
79
|
end
|
|
72
80
|
|
|
73
81
|
test 'body should have link to confirm the account' do
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class UnlockInstructionsTest < ActionMailer::TestCase
|
|
@@ -50,6 +49,16 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
|
|
50
49
|
assert_equal ['custom@example.com'], mail.from
|
|
51
50
|
end
|
|
52
51
|
|
|
52
|
+
test 'setup sender from custom mailer defaults with proc' do
|
|
53
|
+
Devise.mailer = 'Users::FromProcMailer'
|
|
54
|
+
assert_equal ['custom@example.com'], mail.from
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test 'custom mailer renders parent mailer template' do
|
|
58
|
+
Devise.mailer = 'Users::Mailer'
|
|
59
|
+
assert_not_blank mail.body.encoded
|
|
60
|
+
end
|
|
61
|
+
|
|
53
62
|
test 'setup reply to as copy from sender' do
|
|
54
63
|
assert_equal ['test@example.com'], mail.reply_to
|
|
55
64
|
end
|
|
@@ -67,7 +76,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
|
|
67
76
|
end
|
|
68
77
|
|
|
69
78
|
test 'body should have user info' do
|
|
70
|
-
assert_match
|
|
79
|
+
assert_match user.email, mail.body.encoded
|
|
71
80
|
end
|
|
72
81
|
|
|
73
82
|
test 'body should have link to unlock the account' do
|
data/test/mapping_test.rb
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class AuthenticatableTest < ActiveSupport::TestCase
|
|
5
4
|
test 'required_fields should be an empty array' do
|
|
6
5
|
assert_equal Devise::Models::Validatable.required_fields(User), []
|
|
7
6
|
end
|
|
7
|
+
|
|
8
|
+
test 'find_first_by_auth_conditions allows custom filtering parameters' do
|
|
9
|
+
user = User.create!(:email => "example@example.com", :password => "123456")
|
|
10
|
+
assert_equal User.find_first_by_auth_conditions({ :email => "example@example.com" }), user
|
|
11
|
+
assert_nil User.find_first_by_auth_conditions({ :email => "example@example.com" }, :id => user.id.to_s.next)
|
|
12
|
+
end
|
|
8
13
|
end
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class ConfirmableTest < ActiveSupport::TestCase
|
|
@@ -105,6 +104,24 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
105
104
|
end
|
|
106
105
|
end
|
|
107
106
|
|
|
107
|
+
test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do
|
|
108
|
+
user = new_user
|
|
109
|
+
user.skip_confirmation_notification!
|
|
110
|
+
|
|
111
|
+
assert_email_not_sent do
|
|
112
|
+
user.save!
|
|
113
|
+
assert !user.confirmed?
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
test 'should not send confirmation when no email is provided' do
|
|
118
|
+
assert_email_not_sent do
|
|
119
|
+
user = new_user
|
|
120
|
+
user.email = ''
|
|
121
|
+
user.save(:validate => false)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
108
125
|
test 'should find a user to send confirmation instructions' do
|
|
109
126
|
user = create_user
|
|
110
127
|
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
|
@@ -205,6 +222,13 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
205
222
|
assert_not user.active_for_authentication?
|
|
206
223
|
end
|
|
207
224
|
|
|
225
|
+
test 'should be active when we set allow_unconfirmed_access_for to nil' do
|
|
226
|
+
Devise.allow_unconfirmed_access_for = nil
|
|
227
|
+
user = create_user
|
|
228
|
+
user.confirmation_sent_at = Date.today
|
|
229
|
+
assert user.active_for_authentication?
|
|
230
|
+
end
|
|
231
|
+
|
|
208
232
|
test 'should not be active without confirmation' do
|
|
209
233
|
user = create_user
|
|
210
234
|
user.confirmation_sent_at = nil
|
|
@@ -270,6 +294,24 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
270
294
|
assert_not_equal user.confirmation_token, old
|
|
271
295
|
end
|
|
272
296
|
end
|
|
297
|
+
|
|
298
|
+
test 'should generate a new token when a valid one does not exist' do
|
|
299
|
+
swap Devise, :confirm_within => 3.days do
|
|
300
|
+
user = create_user
|
|
301
|
+
user.update_attribute(:confirmation_sent_at, 4.days.ago)
|
|
302
|
+
old = user.confirmation_token
|
|
303
|
+
user.ensure_confirmation_token!
|
|
304
|
+
assert_not_equal user.confirmation_token, old
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
test 'should not generate a new token when a valid one exists' do
|
|
309
|
+
user = create_user
|
|
310
|
+
assert_not_nil user.confirmation_token
|
|
311
|
+
old = user.confirmation_token
|
|
312
|
+
user.ensure_confirmation_token!
|
|
313
|
+
assert_equal user.confirmation_token, old
|
|
314
|
+
end
|
|
273
315
|
end
|
|
274
316
|
|
|
275
317
|
class ReconfirmableTest < ActiveSupport::TestCase
|
|
@@ -295,7 +337,6 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
|
295
337
|
assert_nil admin.confirmation_token
|
|
296
338
|
end
|
|
297
339
|
|
|
298
|
-
|
|
299
340
|
test 'should regenerate confirmation token after changing email' do
|
|
300
341
|
admin = create_admin
|
|
301
342
|
assert admin.confirm!
|
|
@@ -311,6 +352,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
|
311
352
|
assert_email_sent "new_test@example.com" do
|
|
312
353
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
313
354
|
end
|
|
355
|
+
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
|
|
314
356
|
end
|
|
315
357
|
|
|
316
358
|
test 'should not send confirmation by email after changing password' do
|
|
@@ -321,6 +363,15 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
|
321
363
|
end
|
|
322
364
|
end
|
|
323
365
|
|
|
366
|
+
test 'should not send confirmation by email after changing to a blank email' do
|
|
367
|
+
admin = create_admin
|
|
368
|
+
assert admin.confirm!
|
|
369
|
+
assert_email_not_sent do
|
|
370
|
+
admin.email = ''
|
|
371
|
+
admin.save(:validate => false)
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
|
|
324
375
|
test 'should stay confirmed when email is changed' do
|
|
325
376
|
admin = create_admin
|
|
326
377
|
assert admin.confirm!
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
2
|
+
require 'test_models'
|
|
3
3
|
require 'digest/sha1'
|
|
4
4
|
|
|
5
5
|
class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
@@ -13,6 +13,17 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
|
13
13
|
assert_equal email.downcase, user.email
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
test 'should downcase case insensitive keys that refer to virtual attributes when saving' do
|
|
17
|
+
email = 'Foo@Bar1.com'
|
|
18
|
+
confirmation = 'Foo@Bar1.com'
|
|
19
|
+
attributes = valid_attributes(:email => email, :email_confirmation => confirmation)
|
|
20
|
+
user = UserWithVirtualAttributes.new(attributes)
|
|
21
|
+
|
|
22
|
+
assert_equal confirmation, user.email_confirmation
|
|
23
|
+
user.save!
|
|
24
|
+
assert_equal confirmation.downcase, user.email_confirmation
|
|
25
|
+
end
|
|
26
|
+
|
|
16
27
|
test 'should remove whitespace from strip whitespace keys when saving' do
|
|
17
28
|
# strip_whitespace_keys is set to :email by default.
|
|
18
29
|
email = ' foo@bar.com '
|
|
@@ -23,16 +34,34 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
|
23
34
|
assert_equal email.strip, user.email
|
|
24
35
|
end
|
|
25
36
|
|
|
37
|
+
test "doesn't throw exception when globally configured strip_whitespace_keys are not present on a model" do
|
|
38
|
+
swap Devise, :strip_whitespace_keys => [:fake_key] do
|
|
39
|
+
assert_nothing_raised { create_user }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test "doesn't throw exception when globally configured case_insensitive_keys are not present on a model" do
|
|
44
|
+
swap Devise, :case_insensitive_keys => [:fake_key] do
|
|
45
|
+
assert_nothing_raised { create_user }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
26
49
|
test "param filter should not convert booleans and integer to strings" do
|
|
27
|
-
conditions = {
|
|
28
|
-
conditions = Devise::
|
|
29
|
-
assert_equal( {
|
|
50
|
+
conditions = { "login" => "foo@bar.com", "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => (1..10) }
|
|
51
|
+
conditions = Devise::ParameterFilter.new([], []).filter(conditions)
|
|
52
|
+
assert_equal( { "login" => "foo@bar.com", "bool1" => "true", "bool2" => "false", "fixnum" => "123", "will_be_converted" => "1..10" }, conditions)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'param filter should filter case_insensitive_keys as insensitive' do
|
|
56
|
+
conditions = {'insensitive' => 'insensitive_VAL', 'sensitive' => 'sensitive_VAL'}
|
|
57
|
+
conditions = Devise::ParameterFilter.new(['insensitive'], []).filter(conditions)
|
|
58
|
+
assert_equal( {'insensitive' => 'insensitive_val', 'sensitive' => 'sensitive_VAL'}, conditions )
|
|
30
59
|
end
|
|
31
60
|
|
|
32
|
-
test
|
|
33
|
-
conditions = {
|
|
34
|
-
conditions = Devise::
|
|
35
|
-
assert_equal( {
|
|
61
|
+
test 'param filter should filter strip_whitespace_keys stripping whitespaces' do
|
|
62
|
+
conditions = {'strip_whitespace' => ' strip_whitespace_val ', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}
|
|
63
|
+
conditions = Devise::ParameterFilter.new([], ['strip_whitespace']).filter(conditions)
|
|
64
|
+
assert_equal( {'strip_whitespace' => 'strip_whitespace_val', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}, conditions )
|
|
36
65
|
end
|
|
37
66
|
|
|
38
67
|
test 'should respond to password and password confirmation' do
|
|
@@ -94,13 +123,6 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
|
94
123
|
assert user.reload.valid_password?('pass4321')
|
|
95
124
|
end
|
|
96
125
|
|
|
97
|
-
test 'should update password with valid current password and :as option' do
|
|
98
|
-
user = create_user
|
|
99
|
-
assert user.update_with_password(:current_password => '12345678',
|
|
100
|
-
:password => 'pass4321', :password_confirmation => 'pass4321', :as => :admin)
|
|
101
|
-
assert user.reload.valid_password?('pass4321')
|
|
102
|
-
end
|
|
103
|
-
|
|
104
126
|
test 'should add an error to current password when it is invalid' do
|
|
105
127
|
user = create_user
|
|
106
128
|
assert_not user.update_with_password(:current_password => 'other',
|
|
@@ -153,12 +175,6 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
|
153
175
|
assert_equal 'new@example.com', user.email
|
|
154
176
|
end
|
|
155
177
|
|
|
156
|
-
test 'should update the user without password with :as option' do
|
|
157
|
-
user = create_user
|
|
158
|
-
user.update_without_password(:email => 'new@example.com', :as => :admin)
|
|
159
|
-
assert_equal 'new@example.com', user.email
|
|
160
|
-
end
|
|
161
|
-
|
|
162
178
|
test 'should not update password without password' do
|
|
163
179
|
user = create_user
|
|
164
180
|
user.update_without_password(:password => 'pass4321', :password_confirmation => 'pass4321')
|
|
@@ -166,6 +182,26 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
|
166
182
|
assert user.valid_password?('12345678')
|
|
167
183
|
end
|
|
168
184
|
|
|
185
|
+
test 'should destroy user if current password is valid' do
|
|
186
|
+
user = create_user
|
|
187
|
+
assert user.destroy_with_password('12345678')
|
|
188
|
+
assert !user.persisted?
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
test 'should not destroy user with invalid password' do
|
|
192
|
+
user = create_user
|
|
193
|
+
assert_not user.destroy_with_password('other')
|
|
194
|
+
assert user.persisted?
|
|
195
|
+
assert_match "is invalid", user.errors[:current_password].join
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
test 'should not destroy user with blank password' do
|
|
199
|
+
user = create_user
|
|
200
|
+
assert_not user.destroy_with_password(nil)
|
|
201
|
+
assert user.persisted?
|
|
202
|
+
assert_match "can't be blank", user.errors[:current_password].join
|
|
203
|
+
end
|
|
204
|
+
|
|
169
205
|
test 'downcase_keys with validation' do
|
|
170
206
|
user = User.create(:email => "HEllO@example.com", :password => "123456")
|
|
171
207
|
user = User.create(:email => "HEllO@example.com", :password => "123456")
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class LockableTest < ActiveSupport::TestCase
|
|
@@ -60,7 +59,7 @@ class LockableTest < ActiveSupport::TestCase
|
|
|
60
59
|
assert_not user.active_for_authentication?
|
|
61
60
|
end
|
|
62
61
|
|
|
63
|
-
test "should unlock a user by cleaning locked_at,
|
|
62
|
+
test "should unlock a user by cleaning locked_at, failed_attempts and unlock_token" do
|
|
64
63
|
user = create_user
|
|
65
64
|
user.lock_access!
|
|
66
65
|
assert_not_nil user.reload.locked_at
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class RecoverableTest < ActiveSupport::TestCase
|
|
@@ -111,7 +110,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
|
111
110
|
|
|
112
111
|
test 'should find a user to reset his password based on reset_password_token' do
|
|
113
112
|
user = create_user
|
|
114
|
-
user.
|
|
113
|
+
user.ensure_reset_password_token!
|
|
115
114
|
|
|
116
115
|
reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token)
|
|
117
116
|
assert_equal reset_password_user, user
|
|
@@ -131,7 +130,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
|
131
130
|
|
|
132
131
|
test 'should return a new record with errors if password is blank' do
|
|
133
132
|
user = create_user
|
|
134
|
-
user.
|
|
133
|
+
user.ensure_reset_password_token!
|
|
135
134
|
|
|
136
135
|
reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token, :password => '')
|
|
137
136
|
assert_not reset_password_user.errors.empty?
|
|
@@ -141,7 +140,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
|
141
140
|
test 'should reset successfully user password given the new password and confirmation' do
|
|
142
141
|
user = create_user
|
|
143
142
|
old_password = user.password
|
|
144
|
-
user.
|
|
143
|
+
user.ensure_reset_password_token!
|
|
145
144
|
|
|
146
145
|
User.reset_password_by_token(
|
|
147
146
|
:reset_password_token => user.reset_password_token,
|
|
@@ -180,7 +179,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
|
180
179
|
swap Devise, :reset_password_within => 1.hour do
|
|
181
180
|
user = create_user
|
|
182
181
|
old_password = user.password
|
|
183
|
-
user.
|
|
182
|
+
user.ensure_reset_password_token!
|
|
184
183
|
user.reset_password_sent_at = 2.days.ago
|
|
185
184
|
user.save!
|
|
186
185
|
|
|
@@ -203,4 +202,21 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
|
203
202
|
:reset_password_token
|
|
204
203
|
]
|
|
205
204
|
end
|
|
205
|
+
|
|
206
|
+
test 'should generate a new token when a valid one does not exist' do
|
|
207
|
+
user = create_user
|
|
208
|
+
assert_nil user.reset_password_token
|
|
209
|
+
|
|
210
|
+
user.ensure_reset_password_token!
|
|
211
|
+
assert_not_nil user.reset_password_token
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
test 'should not generate a new token when a valid one exists' do
|
|
215
|
+
user = create_user
|
|
216
|
+
user.send :generate_reset_password_token!
|
|
217
|
+
assert_not_nil user.reset_password_token
|
|
218
|
+
old = user.reset_password_token
|
|
219
|
+
user.ensure_reset_password_token!
|
|
220
|
+
assert_equal user.reset_password_token, old
|
|
221
|
+
end
|
|
206
222
|
end
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class RememberableTest < ActiveSupport::TestCase
|
|
@@ -58,9 +57,10 @@ class RememberableTest < ActiveSupport::TestCase
|
|
|
58
57
|
|
|
59
58
|
test 'forget_me should not try to update resource if it has been destroyed' do
|
|
60
59
|
resource = create_resource
|
|
61
|
-
resource.destroy
|
|
62
60
|
resource.expects(:remember_created_at).never
|
|
63
61
|
resource.expects(:save).never
|
|
62
|
+
|
|
63
|
+
resource.destroy
|
|
64
64
|
resource.forget_me!
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -115,7 +115,7 @@ class RememberableTest < ActiveSupport::TestCase
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
test 'remember should not be expired if it was created
|
|
118
|
+
test 'remember should not be expired if it was created within the limit time' do
|
|
119
119
|
swap Devise, :remember_for => 30.days do
|
|
120
120
|
resource = create_resource
|
|
121
121
|
resource.remember_me!
|
|
@@ -167,7 +167,7 @@ class RememberableTest < ActiveSupport::TestCase
|
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
169
|
|
|
170
|
-
test 'should have the
|
|
170
|
+
test 'should have the required_fields array' do
|
|
171
171
|
assert_same_content Devise::Models::Rememberable.required_fields(User), [
|
|
172
172
|
:remember_created_at
|
|
173
173
|
]
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
1
|
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class SerializableTest < ActiveSupport::TestCase
|
|
@@ -7,22 +6,23 @@ class SerializableTest < ActiveSupport::TestCase
|
|
|
7
6
|
end
|
|
8
7
|
|
|
9
8
|
test 'should not include unsafe keys on XML' do
|
|
10
|
-
assert_match
|
|
11
|
-
assert_no_match
|
|
9
|
+
assert_match(/email/, @user.to_xml)
|
|
10
|
+
assert_no_match(/confirmation-token/, @user.to_xml)
|
|
12
11
|
end
|
|
13
12
|
|
|
14
13
|
test 'should not include unsafe keys on XML even if a new except is provided' do
|
|
15
|
-
assert_no_match
|
|
16
|
-
assert_no_match
|
|
14
|
+
assert_no_match(/email/, @user.to_xml(:except => :email))
|
|
15
|
+
assert_no_match(/confirmation-token/, @user.to_xml(:except => :email))
|
|
17
16
|
end
|
|
18
17
|
|
|
19
18
|
test 'should include unsafe keys on XML if a force_except is provided' do
|
|
20
|
-
assert_no_match
|
|
21
|
-
assert_match
|
|
19
|
+
assert_no_match(/<email/, @user.to_xml(:force_except => :email))
|
|
20
|
+
assert_match(/confirmation-token/, @user.to_xml(:force_except => :email))
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
test 'should not include unsafe keys on JSON' do
|
|
25
|
-
|
|
24
|
+
keys = from_json().keys.select{ |key| !key.include?("id") }
|
|
25
|
+
assert_equal %w(created_at email facebook_token updated_at username), keys.sort
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
test 'should not include unsafe keys on JSON even if a new except is provided' do
|