devise_ennder 1.0.1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +397 -0
- data/INSTALL +94 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +272 -0
- data/Rakefile +53 -0
- data/TODO +2 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +41 -0
- data/app/controllers/registrations_controller.rb +62 -0
- data/app/controllers/sessions_controller.rb +42 -0
- data/app/controllers/unlocks_controller.rb +41 -0
- data/app/models/devise_mailer.rb +68 -0
- data/app/models/user.rb +9 -0
- data/app/views/confirmations/new.html.erb +14 -0
- data/app/views/devise_mailer/confirmation_instructions.html.erb +6 -0
- data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
- data/app/views/passwords/edit.html.erb +16 -0
- data/app/views/passwords/new.html.erb +12 -0
- data/app/views/registrations/edit.html.erb +25 -0
- data/app/views/registrations/new.html.erb +17 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/app/views/shared/_devise_links.erb +19 -0
- data/app/views/shared/_user_nav.html.erb +15 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/config/locales/devise.en.yml +62 -0
- data/config/locales/devise.fr.yml +60 -0
- data/config/locales/en.yml +6 -0
- data/config/locales/fr.yml +18 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20100506013336_devise_create_users.rb +23 -0
- data/lib/devise/controllers/helpers.rb +212 -0
- data/lib/devise/controllers/internal_helpers.rb +129 -0
- data/lib/devise/controllers/url_helpers.rb +41 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/bcrypt.rb +21 -0
- data/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +27 -0
- data/lib/devise/encryptors/sha512.rb +27 -0
- data/lib/devise/failure_app.rb +70 -0
- data/lib/devise/hooks/activatable.rb +15 -0
- data/lib/devise/hooks/rememberable.rb +33 -0
- data/lib/devise/hooks/timeoutable.rb +18 -0
- data/lib/devise/hooks/trackable.rb +18 -0
- data/lib/devise/locales/en.yml +35 -0
- data/lib/devise/mapping.rb +130 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/confirmable.rb +167 -0
- data/lib/devise/models/database_authenticatable.rb +144 -0
- data/lib/devise/models/http_authenticatable.rb +23 -0
- data/lib/devise/models/lockable.rb +150 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +92 -0
- data/lib/devise/models/timeoutable.rb +28 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +16 -0
- data/lib/devise/models/validatable.rb +39 -0
- data/lib/devise/models.rb +117 -0
- data/lib/devise/orm/active_record.rb +41 -0
- data/lib/devise/orm/data_mapper.rb +83 -0
- data/lib/devise/orm/mongo_mapper.rb +52 -0
- data/lib/devise/rails/routes.rb +133 -0
- data/lib/devise/rails/warden_compat.rb +60 -0
- data/lib/devise/rails.rb +14 -0
- data/lib/devise/schema.rb +73 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/database_authenticatable.rb +36 -0
- data/lib/devise/strategies/http_authenticatable.rb +59 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +90 -0
- data/lib/devise/version.rb +3 -0
- data/lib/devise.rb +269 -0
- data/lib/devise_ennder.rb +3 -0
- data/lib/tasks/devise_ennder_tasks.rake +11 -0
- data/test/controllers/helpers_test.rb +184 -0
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +74 -0
- data/test/encryptors_test.rb +31 -0
- data/test/failure_app_test.rb +44 -0
- data/test/integration/authenticatable_test.rb +332 -0
- data/test/integration/confirmable_test.rb +97 -0
- data/test/integration/http_authenticatable_test.rb +52 -0
- data/test/integration/lockable_test.rb +102 -0
- data/test/integration/rack_middleware_test.rb +47 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +144 -0
- data/test/integration/rememberable_test.rb +72 -0
- data/test/integration/timeoutable_test.rb +68 -0
- data/test/integration/token_authenticatable_test.rb +55 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +86 -0
- data/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/mapping_test.rb +158 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +228 -0
- data/test/models/lockable_test.rb +202 -0
- data/test/models/recoverable_test.rb +138 -0
- data/test/models/rememberable_test.rb +135 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +51 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +106 -0
- data/test/models_test.rb +70 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +12 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongo_mapper/admin.rb +13 -0
- data/test/rails_app/app/mongo_mapper/user.rb +14 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/devise.rb +82 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +25 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/confirmations_controller.rb +33 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/passwords_controller.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/registrations_controller.rb +53 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/sessions_controller.rb +42 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/unlocks_controller.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/app/models/devise_mailer.rb +68 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/devise_generator.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/lib/route_devise.rb +32 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/templates/migration.rb +23 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/templates/model.rb +9 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise_install/devise_install_generator.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise_install/templates/devise.rb +105 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise_views/devise_views_generator.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/helpers.rb +212 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/internal_helpers.rb +129 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/url_helpers.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/base.rb +20 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/bcrypt.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha1.rb +27 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha512.rb +27 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/failure_app.rb +70 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/activatable.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/rememberable.rb +33 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/timeoutable.rb +18 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/trackable.rb +18 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/mapping.rb +130 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/activatable.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/confirmable.rb +167 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/database_authenticatable.rb +144 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/http_authenticatable.rb +23 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/lockable.rb +150 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/recoverable.rb +80 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/registerable.rb +8 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/rememberable.rb +92 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/timeoutable.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/token_authenticatable.rb +89 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/trackable.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/validatable.rb +39 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models.rb +117 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/orm/active_record.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/orm/data_mapper.rb +83 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/orm/mongo_mapper.rb +52 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/rails/routes.rb +133 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/rails/warden_compat.rb +60 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/rails.rb +14 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/schema.rb +73 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/base.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/database_authenticatable.rb +36 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/http_authenticatable.rb +59 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb +37 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/test_helpers.rb +90 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/version.rb +3 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise.rb +266 -0
- data/test/rails_app/vendor/plugins/devise/rails/init.rb +2 -0
- data/test/rails_app/vendor/plugins/devise/test/controllers/helpers_test.rb +184 -0
- data/test/rails_app/vendor/plugins/devise/test/controllers/internal_helpers_test.rb +55 -0
- data/test/rails_app/vendor/plugins/devise/test/controllers/url_helpers_test.rb +47 -0
- data/test/rails_app/vendor/plugins/devise/test/devise_test.rb +74 -0
- data/test/rails_app/vendor/plugins/devise/test/encryptors_test.rb +31 -0
- data/test/rails_app/vendor/plugins/devise/test/failure_app_test.rb +44 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/authenticatable_test.rb +332 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/confirmable_test.rb +97 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb +52 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/lockable_test.rb +102 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/rack_middleware_test.rb +47 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/recoverable_test.rb +141 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/registerable_test.rb +144 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/rememberable_test.rb +72 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/timeoutable_test.rb +68 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/token_authenticatable_test.rb +55 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/trackable_test.rb +64 -0
- data/test/rails_app/vendor/plugins/devise/test/mailers/confirmation_instructions_test.rb +86 -0
- data/test/rails_app/vendor/plugins/devise/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/rails_app/vendor/plugins/devise/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/rails_app/vendor/plugins/devise/test/mapping_test.rb +158 -0
- data/test/rails_app/vendor/plugins/devise/test/models/authenticatable_test.rb +180 -0
- data/test/rails_app/vendor/plugins/devise/test/models/confirmable_test.rb +228 -0
- data/test/rails_app/vendor/plugins/devise/test/models/lockable_test.rb +202 -0
- data/test/rails_app/vendor/plugins/devise/test/models/recoverable_test.rb +138 -0
- data/test/rails_app/vendor/plugins/devise/test/models/rememberable_test.rb +135 -0
- data/test/rails_app/vendor/plugins/devise/test/models/timeoutable_test.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb +51 -0
- data/test/rails_app/vendor/plugins/devise/test/models/trackable_test.rb +5 -0
- data/test/rails_app/vendor/plugins/devise/test/models/validatable_test.rb +106 -0
- data/test/rails_app/vendor/plugins/devise/test/models_test.rb +70 -0
- data/test/rails_app/vendor/plugins/devise/test/orm/active_record.rb +31 -0
- data/test/rails_app/vendor/plugins/devise/test/orm/mongo_mapper.rb +20 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/application_controller.rb +12 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/admin.rb +13 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/user.rb +14 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/devise.rb +82 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/routes.rb +25 -0
- data/test/rails_app/vendor/plugins/devise/test/routes_test.rb +131 -0
- data/test/rails_app/vendor/plugins/devise/test/support/assertions_helper.rb +37 -0
- data/test/rails_app/vendor/plugins/devise/test/support/integration_tests_helper.rb +71 -0
- data/test/rails_app/vendor/plugins/devise/test/support/test_silencer.rb +5 -0
- data/test/rails_app/vendor/plugins/devise/test/support/tests_helper.rb +39 -0
- data/test/rails_app/vendor/plugins/devise/test/test_helper.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/test/test_helpers_test.rb +57 -0
- data/test/routes_test.rb +131 -0
- data/test/support/assertions_helper.rb +37 -0
- data/test/support/integration_tests_helper.rb +71 -0
- data/test/support/test_silencer.rb +5 -0
- data/test/support/tests_helper.rb +39 -0
- data/test/test_helper.rb +21 -0
- data/test/test_helpers_test.rb +57 -0
- metadata +515 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class LockableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_mailer
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should increment failed attempts on unsuccessful authentication" do
|
10
|
+
user = create_user
|
11
|
+
assert_equal 0, user.failed_attempts
|
12
|
+
authenticated_user = User.authenticate(:email => user.email, :password => "anotherpassword")
|
13
|
+
assert_equal 1, user.reload.failed_attempts
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should lock account base on maximum_attempts" do
|
17
|
+
user = create_user
|
18
|
+
attempts = Devise.maximum_attempts + 1
|
19
|
+
attempts.times { authenticated_user = User.authenticate(:email => user.email, :password => "anotherpassword") }
|
20
|
+
assert user.reload.access_locked?
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should respect maximum attempts configuration" do
|
24
|
+
user = create_user
|
25
|
+
swap Devise, :maximum_attempts => 2 do
|
26
|
+
3.times { authenticated_user = User.authenticate(:email => user.email, :password => "anotherpassword") }
|
27
|
+
assert user.reload.access_locked?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test "should clear failed_attempts on successfull sign in" do
|
32
|
+
user = create_user
|
33
|
+
User.authenticate(:email => user.email, :password => "anotherpassword")
|
34
|
+
assert_equal 1, user.reload.failed_attempts
|
35
|
+
User.authenticate(:email => user.email, :password => "123456")
|
36
|
+
assert_equal 0, user.reload.failed_attempts
|
37
|
+
end
|
38
|
+
|
39
|
+
test "should verify whether a user is locked or not" do
|
40
|
+
user = create_user
|
41
|
+
assert_not user.access_locked?
|
42
|
+
user.lock_access!
|
43
|
+
assert user.access_locked?
|
44
|
+
end
|
45
|
+
|
46
|
+
test "active? should be the opposite of locked?" do
|
47
|
+
user = create_user
|
48
|
+
user.confirm!
|
49
|
+
assert user.active?
|
50
|
+
user.lock_access!
|
51
|
+
assert_not user.active?
|
52
|
+
end
|
53
|
+
|
54
|
+
test "should unlock an user by cleaning locked_at, falied_attempts and unlock_token" do
|
55
|
+
user = create_user
|
56
|
+
user.lock_access!
|
57
|
+
assert_not_nil user.reload.locked_at
|
58
|
+
assert_not_nil user.reload.unlock_token
|
59
|
+
|
60
|
+
user.unlock_access!
|
61
|
+
assert_nil user.reload.locked_at
|
62
|
+
assert_nil user.reload.unlock_token
|
63
|
+
assert 0, user.reload.failed_attempts
|
64
|
+
end
|
65
|
+
|
66
|
+
test "should not lock a locked account" do
|
67
|
+
user = create_user
|
68
|
+
user.lock_access!
|
69
|
+
assert_no_difference "ActionMailer::Base.deliveries.size" do
|
70
|
+
user.lock_access!
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'should not unlock an unlocked user' do
|
75
|
+
user = create_user
|
76
|
+
|
77
|
+
assert_not user.unlock_access!
|
78
|
+
assert_match /not locked/, user.errors[:email]
|
79
|
+
end
|
80
|
+
|
81
|
+
test "new user should not be locked and should have zero failed_attempts" do
|
82
|
+
assert_not new_user.access_locked?
|
83
|
+
assert_equal 0, create_user.failed_attempts
|
84
|
+
end
|
85
|
+
|
86
|
+
test "should unlock user after unlock_in period" do
|
87
|
+
swap Devise, :unlock_in => 3.hours do
|
88
|
+
user = new_user
|
89
|
+
user.locked_at = 2.hours.ago
|
90
|
+
assert user.access_locked?
|
91
|
+
|
92
|
+
Devise.unlock_in = 1.hour
|
93
|
+
assert_not user.access_locked?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
test "should not unlock in 'unlock_in' if :time unlock strategy is not set" do
|
98
|
+
swap Devise, :unlock_strategy => :email do
|
99
|
+
user = new_user
|
100
|
+
user.locked_at = 2.hours.ago
|
101
|
+
assert user.access_locked?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
test "should set unlock_token when locking" do
|
106
|
+
user = create_user
|
107
|
+
assert_nil user.unlock_token
|
108
|
+
user.lock_access!
|
109
|
+
assert_not_nil user.unlock_token
|
110
|
+
end
|
111
|
+
|
112
|
+
test "should never generate the same unlock token for different users" do
|
113
|
+
unlock_tokens = []
|
114
|
+
3.times do
|
115
|
+
user = create_user
|
116
|
+
user.lock_access!
|
117
|
+
token = user.unlock_token
|
118
|
+
assert !unlock_tokens.include?(token)
|
119
|
+
unlock_tokens << token
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
test "should not generate unlock_token when :email is not an unlock strategy" do
|
124
|
+
swap Devise, :unlock_strategy => :time do
|
125
|
+
user = create_user
|
126
|
+
user.lock_access!
|
127
|
+
assert_nil user.unlock_token
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
test "should send email with unlock instructions when :email is an unlock strategy" do
|
132
|
+
swap Devise, :unlock_strategy => :email do
|
133
|
+
user = create_user
|
134
|
+
assert_email_sent do
|
135
|
+
user.lock_access!
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
test "should not send email with unlock instructions when :email is not an unlock strategy" do
|
141
|
+
swap Devise, :unlock_strategy => :time do
|
142
|
+
user = create_user
|
143
|
+
assert_email_not_sent do
|
144
|
+
user.lock_access!
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'should find and unlock an user automatically' do
|
150
|
+
user = create_user
|
151
|
+
user.lock_access!
|
152
|
+
locked_user = User.unlock_access_by_token(user.unlock_token)
|
153
|
+
assert_equal locked_user, user
|
154
|
+
assert_not user.reload.access_locked?
|
155
|
+
end
|
156
|
+
|
157
|
+
test 'should return a new record with errors when a invalid token is given' do
|
158
|
+
locked_user = User.unlock_access_by_token('invalid_token')
|
159
|
+
assert locked_user.new_record?
|
160
|
+
assert_match /invalid/, locked_user.errors[:unlock_token]
|
161
|
+
end
|
162
|
+
|
163
|
+
test 'should return a new record with errors when a blank token is given' do
|
164
|
+
locked_user = User.unlock_access_by_token('')
|
165
|
+
assert locked_user.new_record?
|
166
|
+
assert_match /blank/, locked_user.errors[:unlock_token]
|
167
|
+
end
|
168
|
+
|
169
|
+
test 'should authenticate a unlocked user' do
|
170
|
+
user = create_user
|
171
|
+
user.lock_access!
|
172
|
+
user.unlock_access!
|
173
|
+
authenticated_user = User.authenticate(:email => user.email, :password => user.password)
|
174
|
+
assert_equal authenticated_user, user
|
175
|
+
end
|
176
|
+
|
177
|
+
test 'should find a user to send unlock instructions' do
|
178
|
+
user = create_user
|
179
|
+
user.lock_access!
|
180
|
+
unlock_user = User.send_unlock_instructions(:email => user.email)
|
181
|
+
assert_equal unlock_user, user
|
182
|
+
end
|
183
|
+
|
184
|
+
test 'should return a new user if no email was found' do
|
185
|
+
unlock_user = User.send_unlock_instructions(:email => "invalid@email.com")
|
186
|
+
assert unlock_user.new_record?
|
187
|
+
end
|
188
|
+
|
189
|
+
test 'should add error to new user email if no email was found' do
|
190
|
+
unlock_user = User.send_unlock_instructions(:email => "invalid@email.com")
|
191
|
+
assert unlock_user.errors[:email]
|
192
|
+
assert_equal 'not found', unlock_user.errors[:email]
|
193
|
+
end
|
194
|
+
|
195
|
+
test 'should not be able to send instructions if the user is not locked' do
|
196
|
+
user = create_user
|
197
|
+
assert_not user.resend_unlock_token
|
198
|
+
assert_not user.access_locked?
|
199
|
+
assert_equal 'not locked', user.errors[:email]
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class RecoverableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_mailer
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should not generate reset password token after creating a record' do
|
10
|
+
assert_nil new_user.reset_password_token
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'should regenerate reset password token each time' do
|
14
|
+
user = create_user
|
15
|
+
3.times do
|
16
|
+
token = user.reset_password_token
|
17
|
+
user.send_reset_password_instructions
|
18
|
+
assert_not_equal token, user.reset_password_token
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should never generate the same reset password token for different users' do
|
23
|
+
reset_password_tokens = []
|
24
|
+
3.times do
|
25
|
+
user = create_user
|
26
|
+
user.send_reset_password_instructions
|
27
|
+
token = user.reset_password_token
|
28
|
+
assert !reset_password_tokens.include?(token)
|
29
|
+
reset_password_tokens << token
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'should reset password and password confirmation from params' do
|
34
|
+
user = create_user
|
35
|
+
user.reset_password!('123456789', '987654321')
|
36
|
+
assert_equal '123456789', user.password
|
37
|
+
assert_equal '987654321', user.password_confirmation
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'should reset password and save the record' do
|
41
|
+
assert create_user.reset_password!('123456789', '123456789')
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'should clear reset password token while reseting the password' do
|
45
|
+
user = create_user
|
46
|
+
assert_nil user.reset_password_token
|
47
|
+
|
48
|
+
user.send_reset_password_instructions
|
49
|
+
assert_present user.reset_password_token
|
50
|
+
assert user.reset_password!('123456789', '123456789')
|
51
|
+
assert_nil user.reset_password_token
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'should not clear reset password token if record is invalid' do
|
55
|
+
user = create_user
|
56
|
+
user.send_reset_password_instructions
|
57
|
+
assert_present user.reset_password_token
|
58
|
+
assert_not user.reset_password!('123456789', '987654321')
|
59
|
+
assert_present user.reset_password_token
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'should not reset password with invalid data' do
|
63
|
+
user = create_user
|
64
|
+
user.stubs(:valid?).returns(false)
|
65
|
+
assert_not user.reset_password!('123456789', '987654321')
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'should reset reset password token and send instructions by email' do
|
69
|
+
user = create_user
|
70
|
+
assert_email_sent do
|
71
|
+
token = user.reset_password_token
|
72
|
+
user.send_reset_password_instructions
|
73
|
+
assert_not_equal token, user.reset_password_token
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'should find a user to send instructions by email' do
|
78
|
+
user = create_user
|
79
|
+
reset_password_user = User.send_reset_password_instructions(:email => user.email)
|
80
|
+
assert_equal reset_password_user, user
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'should return a new record with errors if user was not found by e-mail' do
|
84
|
+
reset_password_user = User.send_reset_password_instructions(:email => "invalid@email.com")
|
85
|
+
assert reset_password_user.new_record?
|
86
|
+
assert_match /not found/, reset_password_user.errors[:email]
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'should reset reset_password_token before send the reset instructions email' do
|
90
|
+
user = create_user
|
91
|
+
token = user.reset_password_token
|
92
|
+
reset_password_user = User.send_reset_password_instructions(:email => user.email)
|
93
|
+
assert_not_equal token, user.reload.reset_password_token
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'should send email instructions to the user reset his password' do
|
97
|
+
user = create_user
|
98
|
+
assert_email_sent do
|
99
|
+
User.send_reset_password_instructions(:email => user.email)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'should find a user to reset his password based on reset_password_token' do
|
104
|
+
user = create_user
|
105
|
+
user.send :generate_reset_password_token!
|
106
|
+
|
107
|
+
reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token)
|
108
|
+
assert_equal reset_password_user, user
|
109
|
+
end
|
110
|
+
|
111
|
+
test 'should a new record with errors if no reset_password_token is found' do
|
112
|
+
reset_password_user = User.reset_password_by_token(:reset_password_token => 'invalid_token')
|
113
|
+
assert reset_password_user.new_record?
|
114
|
+
assert_match /invalid/, reset_password_user.errors[:reset_password_token]
|
115
|
+
end
|
116
|
+
|
117
|
+
test 'should a new record with errors if reset_password_token is blank' do
|
118
|
+
reset_password_user = User.reset_password_by_token(:reset_password_token => '')
|
119
|
+
assert reset_password_user.new_record?
|
120
|
+
assert_match /blank/, reset_password_user.errors[:reset_password_token]
|
121
|
+
end
|
122
|
+
|
123
|
+
test 'should reset successfully user password given the new password and confirmation' do
|
124
|
+
user = create_user
|
125
|
+
old_password = user.password
|
126
|
+
user.send :generate_reset_password_token!
|
127
|
+
|
128
|
+
reset_password_user = User.reset_password_by_token(
|
129
|
+
:reset_password_token => user.reset_password_token,
|
130
|
+
:password => 'new_password',
|
131
|
+
:password_confirmation => 'new_password'
|
132
|
+
)
|
133
|
+
user.reload
|
134
|
+
|
135
|
+
assert_not user.valid_password?(old_password)
|
136
|
+
assert user.valid_password?('new_password')
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class RememberableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Devise.remember_for = 1
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should respond to remember_me attribute' do
|
10
|
+
user = new_user
|
11
|
+
assert user.respond_to?(:remember_me)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'remember_me should generate a new token and save the record without validating' do
|
15
|
+
user = create_user
|
16
|
+
user.expects(:valid?).never
|
17
|
+
token = user.remember_token
|
18
|
+
user.remember_me!
|
19
|
+
assert_not_equal token, user.remember_token
|
20
|
+
assert_not user.changed?
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'forget_me should clear remember token and save the record without validating' do
|
24
|
+
user = create_user
|
25
|
+
user.remember_me!
|
26
|
+
assert user.remember_token?
|
27
|
+
user.expects(:valid?).never
|
28
|
+
user.forget_me!
|
29
|
+
assert_not user.remember_token?
|
30
|
+
assert_not user.changed?
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'forget_me should clear remember_created_at' do
|
34
|
+
user = create_user
|
35
|
+
user.remember_me!
|
36
|
+
assert user.remember_created_at?
|
37
|
+
user.forget_me!
|
38
|
+
assert_not user.remember_created_at?
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'forget should do nothing if no remember token exists' do
|
42
|
+
user = create_user
|
43
|
+
user.expects(:save).never
|
44
|
+
user.forget_me!
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'valid remember token' do
|
48
|
+
user = create_user
|
49
|
+
assert_not user.valid_remember_token?(user.remember_token)
|
50
|
+
user.remember_me!
|
51
|
+
assert user.valid_remember_token?(user.remember_token)
|
52
|
+
user.forget_me!
|
53
|
+
assert_not user.valid_remember_token?(user.remember_token)
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'valid remember token should also verify if remember is not expired' do
|
57
|
+
user = create_user
|
58
|
+
user.remember_me!
|
59
|
+
user.remember_created_at = 3.days.ago
|
60
|
+
user.save
|
61
|
+
assert_not user.valid_remember_token?(user.remember_token)
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'serialize into cookie' do
|
65
|
+
user = create_user
|
66
|
+
user.remember_me!
|
67
|
+
assert_equal "#{user.id}::#{user.remember_token}", User.serialize_into_cookie(user)
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'serialize from cookie' do
|
71
|
+
user = create_user
|
72
|
+
user.remember_me!
|
73
|
+
assert_equal user, User.serialize_from_cookie("#{user.id}::#{user.remember_token}")
|
74
|
+
end
|
75
|
+
|
76
|
+
# MongoMapper cries if an invalid ID is given, so this does not need to be tested
|
77
|
+
unless DEVISE_ORM == :mongo_mapper
|
78
|
+
test 'serialize should return nil if no user is found' do
|
79
|
+
assert_nil User.serialize_from_cookie('0::123')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'remember me return nil if is a valid user with invalid token' do
|
84
|
+
user = create_user
|
85
|
+
assert_nil User.serialize_from_cookie("#{user.id}::#{user.remember_token}123")
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'remember for should fallback to devise remember for default configuration' do
|
89
|
+
swap Devise, :remember_for => 1.day do
|
90
|
+
user = create_user
|
91
|
+
user.remember_me!
|
92
|
+
assert_not user.remember_expired?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'remember expires at should sum date of creation with remember for configuration' do
|
97
|
+
swap Devise, :remember_for => 3.days do
|
98
|
+
user = create_user
|
99
|
+
user.remember_me!
|
100
|
+
assert_equal 3.days.from_now.to_date, user.remember_expires_at.to_date
|
101
|
+
|
102
|
+
Devise.remember_for = 5.days
|
103
|
+
assert_equal 5.days.from_now.to_date, user.remember_expires_at.to_date
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'remember should be expired if remember_for is zero' do
|
108
|
+
swap Devise, :remember_for => 0.days do
|
109
|
+
Devise.remember_for = 0.days
|
110
|
+
user = create_user
|
111
|
+
user.remember_me!
|
112
|
+
assert user.remember_expired?
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
test 'remember should be expired if it was created before limit time' do
|
117
|
+
swap Devise, :remember_for => 1.day do
|
118
|
+
user = create_user
|
119
|
+
user.remember_me!
|
120
|
+
user.remember_created_at = 2.days.ago
|
121
|
+
user.save
|
122
|
+
assert user.remember_expired?
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'remember should not be expired if it was created whitin the limit time' do
|
127
|
+
swap Devise, :remember_for => 30.days do
|
128
|
+
user = create_user
|
129
|
+
user.remember_me!
|
130
|
+
user.remember_created_at = (30.days.ago + 2.minutes)
|
131
|
+
user.save
|
132
|
+
assert_not user.remember_expired?
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TimeoutableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'should be expired' do
|
6
|
+
assert new_user.timedout?(31.minutes.ago)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should not be expired' do
|
10
|
+
assert_not new_user.timedout?(29.minutes.ago)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'should not be expired when params is nil' do
|
14
|
+
assert_not new_user.timedout?(nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'fallback to Devise config option' do
|
18
|
+
swap Devise, :timeout_in => 1.minute do
|
19
|
+
user = new_user
|
20
|
+
assert user.timedout?(2.minutes.ago)
|
21
|
+
assert_not user.timedout?(30.seconds.ago)
|
22
|
+
|
23
|
+
Devise.timeout_in = 5.minutes
|
24
|
+
assert_not user.timedout?(2.minutes.ago)
|
25
|
+
assert user.timedout?(6.minutes.ago)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TokenAuthenticatableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'should generate friendly authentication token on create' do
|
6
|
+
User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
|
7
|
+
user = create_user
|
8
|
+
assert_present user.authentication_token
|
9
|
+
assert_equal VALID_AUTHENTICATION_TOKEN, user.authentication_token
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'should reset authentication token' do
|
13
|
+
user = new_user
|
14
|
+
user.reset_authentication_token
|
15
|
+
previous_token = user.authentication_token
|
16
|
+
user.reset_authentication_token
|
17
|
+
assert_not_equal previous_token, user.authentication_token
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'should ensure authentication token' do
|
21
|
+
user = new_user
|
22
|
+
user.ensure_authentication_token
|
23
|
+
previous_token = user.authentication_token
|
24
|
+
user.ensure_authentication_token
|
25
|
+
assert_equal previous_token, user.authentication_token
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'should test for a valid authentication token' do
|
29
|
+
User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
|
30
|
+
user = create_user
|
31
|
+
assert user.valid_authentication_token?(VALID_AUTHENTICATION_TOKEN)
|
32
|
+
assert_not user.valid_authentication_token?(VALID_AUTHENTICATION_TOKEN.reverse)
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'should authenticate a valid user with authentication token and return it' do
|
36
|
+
User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
|
37
|
+
user = create_user
|
38
|
+
user.confirm!
|
39
|
+
authenticated_user = User.authenticate_with_token(:auth_token => user.authentication_token)
|
40
|
+
assert_equal authenticated_user, user
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'should return nil when authenticating an invalid user by authentication token' do
|
44
|
+
User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
|
45
|
+
user = create_user
|
46
|
+
user.confirm!
|
47
|
+
authenticated_user = User.authenticate_with_token(:auth_token => user.authentication_token.reverse)
|
48
|
+
assert_nil authenticated_user
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class ValidatableTest < ActiveSupport::TestCase
|
4
|
+
extend Devise::TestSilencer if [:mongo_mapper, :data_mapper].include?(DEVISE_ORM)
|
5
|
+
|
6
|
+
test 'should require email to be set' do
|
7
|
+
user = new_user(:email => nil)
|
8
|
+
assert user.invalid?
|
9
|
+
assert user.errors[:email]
|
10
|
+
assert_equal 'can\'t be blank', user.errors[:email]
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'should require uniqueness of email, allowing blank' do
|
14
|
+
existing_user = create_user
|
15
|
+
user = new_user(:email => '')
|
16
|
+
assert user.invalid?
|
17
|
+
assert_not_equal 'has already been taken', user.errors[:email]
|
18
|
+
user.email = existing_user.email
|
19
|
+
assert user.invalid?
|
20
|
+
assert user.errors[:email]
|
21
|
+
assert_equal 1, [*user.errors[:email]].size
|
22
|
+
assert_equal 'has already been taken', user.errors[:email]
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'should require correct email format, allowing blank' do
|
26
|
+
user = new_user(:email => '')
|
27
|
+
assert user.invalid?
|
28
|
+
assert_not_equal 'is invalid', user.errors[:email]
|
29
|
+
%w(invalid_email_format email@invalid invalid$character@mail.com other@not 123).each do |email|
|
30
|
+
user.email = email
|
31
|
+
assert user.invalid?, 'should be invalid with email ' << email
|
32
|
+
assert user.errors[:email]
|
33
|
+
assert_equal 1, [*user.errors[:email]].size
|
34
|
+
assert_equal 'is invalid', user.errors[:email]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'should accept valid emails' do
|
39
|
+
%w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test).each do |email|
|
40
|
+
user = new_user(:email => email)
|
41
|
+
assert user.valid?, 'should be valid with email ' << email
|
42
|
+
assert_nil user.errors[:email]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'should require password to be set when creating a new record' do
|
47
|
+
user = new_user(:password => '', :password_confirmation => '')
|
48
|
+
assert user.invalid?
|
49
|
+
assert user.errors[:password]
|
50
|
+
assert_equal 'can\'t be blank', user.errors[:password]
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'should require confirmation to be set when creating a new record' do
|
54
|
+
user = new_user(:password => 'new_password', :password_confirmation => 'blabla')
|
55
|
+
assert user.invalid?
|
56
|
+
assert user.errors[:password]
|
57
|
+
assert_equal 'doesn\'t match confirmation', user.errors[:password]
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'should require password when updating/reseting password' do
|
61
|
+
user = create_user
|
62
|
+
user.password = ''
|
63
|
+
user.password_confirmation = ''
|
64
|
+
assert user.invalid?
|
65
|
+
assert user.errors[:password]
|
66
|
+
assert_equal 'can\'t be blank', user.errors[:password]
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'should require confirmation when updating/reseting password' do
|
70
|
+
user = create_user
|
71
|
+
user.password_confirmation = 'another_password'
|
72
|
+
assert user.invalid?
|
73
|
+
assert user.errors[:password]
|
74
|
+
assert_equal 'doesn\'t match confirmation', user.errors[:password]
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'should require a password with minimum of 6 characters' do
|
78
|
+
user = new_user(:password => '12345', :password_confirmation => '12345')
|
79
|
+
assert user.invalid?
|
80
|
+
assert user.errors[:password]
|
81
|
+
assert_equal 'is too short (minimum is 6 characters)', user.errors[:password]
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'should require a password with maximum of 20 characters long' do
|
85
|
+
user = new_user(:password => 'x'*21, :password_confirmation => 'x'*21)
|
86
|
+
assert user.invalid?
|
87
|
+
assert user.errors[:password]
|
88
|
+
assert_equal 'is too long (maximum is 20 characters)', user.errors[:password]
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'should not require password length when it\'s not changed' do
|
92
|
+
user = create_user.reload
|
93
|
+
user.password = user.password_confirmation = nil
|
94
|
+
assert user.valid?
|
95
|
+
user.password_confirmation = 'confirmation'
|
96
|
+
assert user.invalid?
|
97
|
+
assert user.errors[:password]
|
98
|
+
assert_not user.errors[:password].to_a.include?('is too short (minimum is 6 characters)')
|
99
|
+
end
|
100
|
+
|
101
|
+
test 'shuold not be included in objects with invalid API' do
|
102
|
+
assert_raise RuntimeError do
|
103
|
+
Class.new.send :include, Devise::Models::Validatable
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|