dcu-devise 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/CHANGELOG.rdoc +378 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +260 -0
  4. data/Rakefile +53 -0
  5. data/TODO +2 -0
  6. data/app/controllers/confirmations_controller.rb +33 -0
  7. data/app/controllers/passwords_controller.rb +41 -0
  8. data/app/controllers/registrations_controller.rb +53 -0
  9. data/app/controllers/sessions_controller.rb +44 -0
  10. data/app/controllers/unlocks_controller.rb +41 -0
  11. data/app/models/devise_mailer.rb +68 -0
  12. data/app/views/confirmations/new.html.erb +12 -0
  13. data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
  14. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  15. data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
  16. data/app/views/passwords/edit.html.erb +16 -0
  17. data/app/views/passwords/new.html.erb +12 -0
  18. data/app/views/registrations/edit.html.erb +25 -0
  19. data/app/views/registrations/new.html.erb +17 -0
  20. data/app/views/sessions/new.html.erb +17 -0
  21. data/app/views/shared/_devise_links.erb +19 -0
  22. data/app/views/unlocks/new.html.erb +12 -0
  23. data/generators/devise/USAGE +5 -0
  24. data/generators/devise/devise_generator.rb +15 -0
  25. data/generators/devise/lib/route_devise.rb +32 -0
  26. data/generators/devise/templates/migration.rb +23 -0
  27. data/generators/devise/templates/model.rb +9 -0
  28. data/generators/devise_install/USAGE +3 -0
  29. data/generators/devise_install/devise_install_generator.rb +15 -0
  30. data/generators/devise_install/templates/README +23 -0
  31. data/generators/devise_install/templates/devise.rb +105 -0
  32. data/generators/devise_views/USAGE +3 -0
  33. data/generators/devise_views/devise_views_generator.rb +21 -0
  34. data/lib/devise.rb +264 -0
  35. data/lib/devise/controllers/helpers.rb +200 -0
  36. data/lib/devise/controllers/internal_helpers.rb +129 -0
  37. data/lib/devise/controllers/url_helpers.rb +41 -0
  38. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  39. data/lib/devise/encryptors/base.rb +20 -0
  40. data/lib/devise/encryptors/bcrypt.rb +21 -0
  41. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  42. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  43. data/lib/devise/encryptors/sha1.rb +27 -0
  44. data/lib/devise/encryptors/sha512.rb +27 -0
  45. data/lib/devise/failure_app.rb +65 -0
  46. data/lib/devise/hooks/activatable.rb +15 -0
  47. data/lib/devise/hooks/rememberable.rb +32 -0
  48. data/lib/devise/hooks/timeoutable.rb +18 -0
  49. data/lib/devise/hooks/trackable.rb +18 -0
  50. data/lib/devise/locales/en.yml +35 -0
  51. data/lib/devise/mapping.rb +128 -0
  52. data/lib/devise/models.rb +117 -0
  53. data/lib/devise/models/activatable.rb +16 -0
  54. data/lib/devise/models/confirmable.rb +162 -0
  55. data/lib/devise/models/database_authenticatable.rb +144 -0
  56. data/lib/devise/models/http_authenticatable.rb +21 -0
  57. data/lib/devise/models/lockable.rb +150 -0
  58. data/lib/devise/models/recoverable.rb +80 -0
  59. data/lib/devise/models/registerable.rb +8 -0
  60. data/lib/devise/models/rememberable.rb +92 -0
  61. data/lib/devise/models/timeoutable.rb +28 -0
  62. data/lib/devise/models/token_authenticatable.rb +89 -0
  63. data/lib/devise/models/trackable.rb +16 -0
  64. data/lib/devise/models/validatable.rb +39 -0
  65. data/lib/devise/orm/active_record.rb +41 -0
  66. data/lib/devise/orm/data_mapper.rb +83 -0
  67. data/lib/devise/orm/mongo_mapper.rb +47 -0
  68. data/lib/devise/rails.rb +14 -0
  69. data/lib/devise/rails/routes.rb +125 -0
  70. data/lib/devise/rails/warden_compat.rb +25 -0
  71. data/lib/devise/schema.rb +73 -0
  72. data/lib/devise/strategies/base.rb +16 -0
  73. data/lib/devise/strategies/database_authenticatable.rb +36 -0
  74. data/lib/devise/strategies/http_authenticatable.rb +59 -0
  75. data/lib/devise/strategies/rememberable.rb +37 -0
  76. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  77. data/lib/devise/test_helpers.rb +90 -0
  78. data/lib/devise/version.rb +3 -0
  79. data/rails/init.rb +2 -0
  80. data/test/controllers/helpers_test.rb +177 -0
  81. data/test/controllers/internal_helpers_test.rb +55 -0
  82. data/test/controllers/url_helpers_test.rb +47 -0
  83. data/test/devise_test.rb +74 -0
  84. data/test/encryptors_test.rb +31 -0
  85. data/test/failure_app_test.rb +44 -0
  86. data/test/integration/authenticatable_test.rb +271 -0
  87. data/test/integration/confirmable_test.rb +97 -0
  88. data/test/integration/http_authenticatable_test.rb +52 -0
  89. data/test/integration/lockable_test.rb +102 -0
  90. data/test/integration/rack_middleware_test.rb +47 -0
  91. data/test/integration/recoverable_test.rb +141 -0
  92. data/test/integration/registerable_test.rb +144 -0
  93. data/test/integration/rememberable_test.rb +71 -0
  94. data/test/integration/timeoutable_test.rb +68 -0
  95. data/test/integration/token_authenticatable_test.rb +55 -0
  96. data/test/integration/trackable_test.rb +64 -0
  97. data/test/mailers/confirmation_instructions_test.rb +86 -0
  98. data/test/mailers/reset_password_instructions_test.rb +68 -0
  99. data/test/mailers/unlock_instructions_test.rb +62 -0
  100. data/test/mapping_test.rb +148 -0
  101. data/test/models/authenticatable_test.rb +180 -0
  102. data/test/models/confirmable_test.rb +212 -0
  103. data/test/models/lockable_test.rb +202 -0
  104. data/test/models/recoverable_test.rb +138 -0
  105. data/test/models/rememberable_test.rb +135 -0
  106. data/test/models/timeoutable_test.rb +28 -0
  107. data/test/models/token_authenticatable_test.rb +51 -0
  108. data/test/models/trackable_test.rb +5 -0
  109. data/test/models/validatable_test.rb +106 -0
  110. data/test/models_test.rb +70 -0
  111. data/test/orm/active_record.rb +31 -0
  112. data/test/orm/mongo_mapper.rb +20 -0
  113. data/test/rails_app/app/active_record/admin.rb +7 -0
  114. data/test/rails_app/app/active_record/user.rb +7 -0
  115. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  116. data/test/rails_app/app/controllers/application_controller.rb +12 -0
  117. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  118. data/test/rails_app/app/controllers/users_controller.rb +16 -0
  119. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  120. data/test/rails_app/app/mongo_mapper/admin.rb +13 -0
  121. data/test/rails_app/app/mongo_mapper/user.rb +14 -0
  122. data/test/rails_app/config/boot.rb +110 -0
  123. data/test/rails_app/config/environment.rb +42 -0
  124. data/test/rails_app/config/environments/development.rb +17 -0
  125. data/test/rails_app/config/environments/production.rb +28 -0
  126. data/test/rails_app/config/environments/test.rb +28 -0
  127. data/test/rails_app/config/initializers/devise.rb +82 -0
  128. data/test/rails_app/config/initializers/inflections.rb +2 -0
  129. data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  130. data/test/rails_app/config/initializers/session_store.rb +15 -0
  131. data/test/rails_app/config/routes.rb +21 -0
  132. data/test/routes_test.rb +110 -0
  133. data/test/support/assertions_helper.rb +37 -0
  134. data/test/support/integration_tests_helper.rb +71 -0
  135. data/test/support/test_silencer.rb +5 -0
  136. data/test/support/tests_helper.rb +39 -0
  137. data/test/test_helper.rb +21 -0
  138. data/test/test_helpers_test.rb +57 -0
  139. metadata +213 -0
@@ -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,5 @@
1
+ require 'test/test_helper'
2
+
3
+ class TrackableTest < ActiveSupport::TestCase
4
+
5
+ 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