devise 4.5.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (195) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +30 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +18 -0
  5. data/app/controllers/devise/passwords_controller.rb +1 -0
  6. data/app/controllers/devise/registrations_controller.rb +25 -7
  7. data/app/helpers/devise_helper.rb +10 -19
  8. data/app/views/devise/confirmations/new.html.erb +1 -1
  9. data/app/views/devise/passwords/edit.html.erb +1 -1
  10. data/app/views/devise/passwords/new.html.erb +1 -1
  11. data/app/views/devise/registrations/edit.html.erb +1 -1
  12. data/app/views/devise/registrations/new.html.erb +1 -1
  13. data/app/views/devise/sessions/new.html.erb +2 -2
  14. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  15. data/app/views/devise/shared/_links.html.erb +7 -7
  16. data/app/views/devise/unlocks/new.html.erb +1 -1
  17. data/config/locales/en.yml +1 -0
  18. data/lib/devise.rb +4 -0
  19. data/lib/devise/controllers/helpers.rb +1 -1
  20. data/lib/devise/failure_app.rb +28 -3
  21. data/lib/devise/models/authenticatable.rb +7 -15
  22. data/lib/devise/models/confirmable.rb +4 -1
  23. data/lib/devise/models/database_authenticatable.rb +41 -6
  24. data/lib/devise/models/lockable.rb +2 -2
  25. data/lib/devise/models/registerable.rb +2 -0
  26. data/lib/devise/strategies/database_authenticatable.rb +3 -0
  27. data/lib/devise/test/controller_helpers.rb +1 -1
  28. data/lib/devise/version.rb +1 -1
  29. data/lib/generators/active_record/devise_generator.rb +4 -4
  30. data/lib/generators/devise/controllers_generator.rb +1 -1
  31. data/lib/generators/templates/devise.rb +12 -3
  32. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
  33. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  34. metadata +5 -305
  35. data/.gitignore +0 -10
  36. data/.travis.yml +0 -69
  37. data/.yardopts +0 -9
  38. data/CODE_OF_CONDUCT.md +0 -22
  39. data/CONTRIBUTING.md +0 -79
  40. data/Gemfile +0 -39
  41. data/Gemfile.lock +0 -202
  42. data/ISSUE_TEMPLATE.md +0 -19
  43. data/Rakefile +0 -37
  44. data/bin/test +0 -13
  45. data/devise.gemspec +0 -28
  46. data/devise.png +0 -0
  47. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  48. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  49. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  50. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  51. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  52. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  53. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  54. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  55. data/guides/bug_report_templates/integration_test.rb +0 -106
  56. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  57. data/test/controllers/custom_strategy_test.rb +0 -66
  58. data/test/controllers/helper_methods_test.rb +0 -24
  59. data/test/controllers/helpers_test.rb +0 -318
  60. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  61. data/test/controllers/internal_helpers_test.rb +0 -129
  62. data/test/controllers/load_hooks_controller_test.rb +0 -21
  63. data/test/controllers/passwords_controller_test.rb +0 -34
  64. data/test/controllers/sessions_controller_test.rb +0 -108
  65. data/test/controllers/url_helpers_test.rb +0 -67
  66. data/test/delegator_test.rb +0 -21
  67. data/test/devise_test.rb +0 -109
  68. data/test/failure_app_test.rb +0 -346
  69. data/test/generators/active_record_generator_test.rb +0 -130
  70. data/test/generators/controllers_generator_test.rb +0 -50
  71. data/test/generators/devise_generator_test.rb +0 -41
  72. data/test/generators/install_generator_test.rb +0 -26
  73. data/test/generators/mongoid_generator_test.rb +0 -25
  74. data/test/generators/views_generator_test.rb +0 -105
  75. data/test/helpers/devise_helper_test.rb +0 -51
  76. data/test/integration/authenticatable_test.rb +0 -706
  77. data/test/integration/confirmable_test.rb +0 -326
  78. data/test/integration/database_authenticatable_test.rb +0 -110
  79. data/test/integration/http_authenticatable_test.rb +0 -114
  80. data/test/integration/lockable_test.rb +0 -242
  81. data/test/integration/mounted_engine_test.rb +0 -38
  82. data/test/integration/omniauthable_test.rb +0 -148
  83. data/test/integration/recoverable_test.rb +0 -349
  84. data/test/integration/registerable_test.rb +0 -365
  85. data/test/integration/rememberable_test.rb +0 -219
  86. data/test/integration/timeoutable_test.rb +0 -186
  87. data/test/integration/trackable_test.rb +0 -99
  88. data/test/mailers/confirmation_instructions_test.rb +0 -117
  89. data/test/mailers/email_changed_test.rb +0 -132
  90. data/test/mailers/mailer_test.rb +0 -20
  91. data/test/mailers/reset_password_instructions_test.rb +0 -98
  92. data/test/mailers/unlock_instructions_test.rb +0 -93
  93. data/test/mapping_test.rb +0 -136
  94. data/test/models/authenticatable_test.rb +0 -25
  95. data/test/models/confirmable_test.rb +0 -549
  96. data/test/models/database_authenticatable_test.rb +0 -290
  97. data/test/models/lockable_test.rb +0 -352
  98. data/test/models/omniauthable_test.rb +0 -9
  99. data/test/models/recoverable_test.rb +0 -263
  100. data/test/models/registerable_test.rb +0 -9
  101. data/test/models/rememberable_test.rb +0 -184
  102. data/test/models/serializable_test.rb +0 -60
  103. data/test/models/timeoutable_test.rb +0 -53
  104. data/test/models/trackable_test.rb +0 -80
  105. data/test/models/validatable_test.rb +0 -121
  106. data/test/models_test.rb +0 -155
  107. data/test/omniauth/config_test.rb +0 -61
  108. data/test/omniauth/url_helpers_test.rb +0 -53
  109. data/test/orm/active_record.rb +0 -24
  110. data/test/orm/mongoid.rb +0 -15
  111. data/test/parameter_sanitizer_test.rb +0 -105
  112. data/test/rails_app/Rakefile +0 -6
  113. data/test/rails_app/app/active_record/admin.rb +0 -8
  114. data/test/rails_app/app/active_record/shim.rb +0 -4
  115. data/test/rails_app/app/active_record/user.rb +0 -20
  116. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  117. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  118. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  119. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  120. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  121. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  122. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  123. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  124. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  125. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  126. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  127. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  128. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  129. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  130. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  131. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  132. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  133. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  134. data/test/rails_app/app/mongoid/admin.rb +0 -31
  135. data/test/rails_app/app/mongoid/shim.rb +0 -25
  136. data/test/rails_app/app/mongoid/user.rb +0 -50
  137. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  138. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  139. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  140. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  141. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  142. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  143. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  144. data/test/rails_app/app/views/home/index.html.erb +0 -1
  145. data/test/rails_app/app/views/home/join.html.erb +0 -1
  146. data/test/rails_app/app/views/home/private.html.erb +0 -1
  147. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  148. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  149. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  150. data/test/rails_app/app/views/users/index.html.erb +0 -1
  151. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  152. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  153. data/test/rails_app/bin/bundle +0 -3
  154. data/test/rails_app/bin/rails +0 -4
  155. data/test/rails_app/bin/rake +0 -4
  156. data/test/rails_app/config.ru +0 -4
  157. data/test/rails_app/config/application.rb +0 -48
  158. data/test/rails_app/config/boot.rb +0 -27
  159. data/test/rails_app/config/database.yml +0 -18
  160. data/test/rails_app/config/environment.rb +0 -7
  161. data/test/rails_app/config/environments/development.rb +0 -32
  162. data/test/rails_app/config/environments/production.rb +0 -88
  163. data/test/rails_app/config/environments/test.rb +0 -47
  164. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  165. data/test/rails_app/config/initializers/devise.rb +0 -187
  166. data/test/rails_app/config/initializers/inflections.rb +0 -4
  167. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  168. data/test/rails_app/config/initializers/session_store.rb +0 -3
  169. data/test/rails_app/config/routes.rb +0 -128
  170. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  171. data/test/rails_app/db/schema.rb +0 -57
  172. data/test/rails_app/lib/lazy_load_test_module.rb +0 -5
  173. data/test/rails_app/lib/shared_admin.rb +0 -23
  174. data/test/rails_app/lib/shared_user.rb +0 -32
  175. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  176. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  177. data/test/rails_app/public/404.html +0 -26
  178. data/test/rails_app/public/422.html +0 -26
  179. data/test/rails_app/public/500.html +0 -26
  180. data/test/rails_app/public/favicon.ico +0 -0
  181. data/test/rails_test.rb +0 -11
  182. data/test/routes_test.rb +0 -281
  183. data/test/secret_key_finder_test.rb +0 -121
  184. data/test/support/action_controller/record_identifier.rb +0 -12
  185. data/test/support/assertions.rb +0 -30
  186. data/test/support/helpers.rb +0 -83
  187. data/test/support/http_method_compatibility.rb +0 -53
  188. data/test/support/integration.rb +0 -95
  189. data/test/support/locale/en.yml +0 -8
  190. data/test/support/mongoid.yml +0 -6
  191. data/test/support/webrat/integrations/rails.rb +0 -35
  192. data/test/test/controller_helpers_test.rb +0 -193
  193. data/test/test/integration_helpers_test.rb +0 -34
  194. data/test/test_helper.rb +0 -36
  195. data/test/test_models.rb +0 -35
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class SerializableTest < ActiveSupport::TestCase
6
- setup do
7
- @user = create_user
8
- end
9
-
10
- test 'should not include unsafe keys on XML' do
11
- assert_match(/email/, @user.to_xml)
12
- assert_no_match(/confirmation-token/, @user.to_xml)
13
- end
14
-
15
- test 'should not include unsafe keys on XML even if a new except is provided' do
16
- assert_no_match(/email/, @user.to_xml(except: :email))
17
- assert_no_match(/confirmation-token/, @user.to_xml(except: :email))
18
- end
19
-
20
- test 'should include unsafe keys on XML if a force_except is provided' do
21
- assert_no_match(/<email/, @user.to_xml(force_except: :email))
22
- assert_match(/confirmation-token/, @user.to_xml(force_except: :email))
23
- end
24
-
25
- test 'should not include unsafe keys on JSON' do
26
- keys = from_json().keys.select{ |key| !key.include?("id") }
27
- assert_equal %w(created_at email facebook_token updated_at username), keys.sort
28
- end
29
-
30
- test 'should not include unsafe keys on JSON even if a new except is provided' do
31
- assert_no_key "email", from_json(except: :email)
32
- assert_no_key "confirmation_token", from_json(except: :email)
33
- end
34
-
35
- test 'should include unsafe keys on JSON if a force_except is provided' do
36
- assert_no_key "email", from_json(force_except: :email)
37
- assert_key "confirmation_token", from_json(force_except: :email)
38
- end
39
-
40
- test 'should not include unsafe keys in inspect' do
41
- assert_match(/email/, @user.inspect)
42
- assert_no_match(/confirmation_token/, @user.inspect)
43
- end
44
-
45
- test 'should accept frozen options' do
46
- assert_key "username", @user.as_json({only: :username}.freeze)["user"]
47
- end
48
-
49
- def assert_key(key, subject)
50
- assert subject.key?(key), "Expected #{subject.inspect} to have key #{key.inspect}"
51
- end
52
-
53
- def assert_no_key(key, subject)
54
- assert !subject.key?(key), "Expected #{subject.inspect} to not have key #{key.inspect}"
55
- end
56
-
57
- def from_json(options=nil)
58
- ActiveSupport::JSON.decode(@user.to_json(options))["user"]
59
- end
60
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TimeoutableTest < ActiveSupport::TestCase
6
-
7
- test 'should be expired' do
8
- assert new_user.timedout?(31.minutes.ago)
9
- end
10
-
11
- test 'should not be expired' do
12
- refute new_user.timedout?(29.minutes.ago)
13
- end
14
-
15
- test 'should not be expired when params is nil' do
16
- refute new_user.timedout?(nil)
17
- end
18
-
19
- test 'should use timeout_in method' do
20
- user = new_user
21
- user.instance_eval { def timeout_in; 10.minutes end }
22
-
23
- assert user.timedout?(12.minutes.ago)
24
- refute user.timedout?(8.minutes.ago)
25
- end
26
-
27
- test 'should not be expired when timeout_in method returns nil' do
28
- user = new_user
29
- user.instance_eval { def timeout_in; nil end }
30
- refute user.timedout?(10.hours.ago)
31
- end
32
-
33
- test 'fallback to Devise config option' do
34
- swap Devise, timeout_in: 1.minute do
35
- user = new_user
36
- assert user.timedout?(2.minutes.ago)
37
- refute user.timedout?(30.seconds.ago)
38
-
39
- Devise.timeout_in = 5.minutes
40
- refute user.timedout?(2.minutes.ago)
41
- assert user.timedout?(6.minutes.ago)
42
- end
43
- end
44
-
45
- test 'required_fields should contain the fields that Devise uses' do
46
- assert_equal Devise::Models::Timeoutable.required_fields(User), []
47
- end
48
-
49
- test 'should not raise error if remember_created_at is not empty and rememberable is disabled' do
50
- user = create_admin(remember_created_at: Time.current)
51
- assert user.timedout?(31.minutes.ago)
52
- end
53
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TrackableTest < ActiveSupport::TestCase
6
- test 'required_fields should contain the fields that Devise uses' do
7
- assert_equal Devise::Models::Trackable.required_fields(User), [
8
- :current_sign_in_at,
9
- :current_sign_in_ip,
10
- :last_sign_in_at,
11
- :last_sign_in_ip,
12
- :sign_in_count
13
- ]
14
- end
15
-
16
- test 'update_tracked_fields should only set attributes but not save the record' do
17
- user = create_user
18
- request = mock
19
- request.stubs(:remote_ip).returns("127.0.0.1")
20
-
21
- assert_nil user.current_sign_in_ip
22
- assert_nil user.last_sign_in_ip
23
- assert_nil user.current_sign_in_at
24
- assert_nil user.last_sign_in_at
25
- assert_equal 0, user.sign_in_count
26
-
27
- user.update_tracked_fields(request)
28
-
29
- assert_equal "127.0.0.1", user.current_sign_in_ip
30
- assert_equal "127.0.0.1", user.last_sign_in_ip
31
- assert_not_nil user.current_sign_in_at
32
- assert_not_nil user.last_sign_in_at
33
- assert_equal 1, user.sign_in_count
34
-
35
- user.reload
36
-
37
- assert_nil user.current_sign_in_ip
38
- assert_nil user.last_sign_in_ip
39
- assert_nil user.current_sign_in_at
40
- assert_nil user.last_sign_in_at
41
- assert_equal 0, user.sign_in_count
42
- end
43
-
44
- test "update_tracked_fields! should not persist invalid records" do
45
- user = UserWithValidations.new
46
- request = mock
47
- request.stubs(:remote_ip).returns("127.0.0.1")
48
-
49
- assert_not user.update_tracked_fields!(request)
50
- assert_not user.persisted?
51
- end
52
-
53
- test "update_tracked_fields! should not run model validations" do
54
- user = User.new
55
- request = mock
56
- request.stubs(:remote_ip).returns("127.0.0.1")
57
-
58
- user.expects(:after_validation_callback).never
59
-
60
- assert_not user.update_tracked_fields!(request)
61
- end
62
-
63
- test 'extract_ip_from should be overridable' do
64
- class UserWithOverride < User
65
- protected
66
- def extract_ip_from(request)
67
- "127.0.0.2"
68
- end
69
- end
70
-
71
- request = mock
72
- request.stubs(:remote_ip).returns("127.0.0.1")
73
- user = UserWithOverride.new
74
-
75
- user.update_tracked_fields(request)
76
-
77
- assert_equal "127.0.0.2", user.current_sign_in_ip
78
- assert_equal "127.0.0.2", user.last_sign_in_ip
79
- end
80
- end
@@ -1,121 +0,0 @@
1
- # encoding: UTF-8
2
- # frozen_string_literal: true
3
-
4
- require 'test_helper'
5
-
6
- class ValidatableTest < ActiveSupport::TestCase
7
- test 'should require email to be set' do
8
- user = new_user(email: nil)
9
- assert user.invalid?
10
- assert user.errors[:email]
11
- assert_equal 'can\'t be blank', user.errors[:email].join
12
- end
13
-
14
- test 'should require uniqueness of email if email has changed, allowing blank' do
15
- existing_user = create_user
16
-
17
- user = new_user(email: '')
18
- assert user.invalid?
19
- assert_no_match(/taken/, user.errors[:email].join)
20
-
21
- user.email = existing_user.email
22
- assert user.invalid?
23
- assert_match(/taken/, user.errors[:email].join)
24
-
25
- user.save(validate: false)
26
- assert user.valid?
27
- end
28
-
29
- test 'should require correct email format if email has changed, allowing blank' do
30
- user = new_user(email: '')
31
- assert user.invalid?
32
- assert_not_equal 'is invalid', user.errors[:email].join
33
-
34
- %w{invalid_email_format 123 $$$ () ☃}.each do |email|
35
- user.email = email
36
- assert user.invalid?, "should be invalid with email #{email}"
37
- assert_equal 'is invalid', user.errors[:email].join
38
- end
39
-
40
- user.save(validate: false)
41
- assert user.valid?
42
- end
43
-
44
- test 'should accept valid emails' do
45
- %w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email|
46
- user = new_user(email: email)
47
- assert user.valid?, "should be valid with email #{email}"
48
- assert_blank user.errors[:email]
49
- end
50
- end
51
-
52
- test 'should require password to be set when creating a new record' do
53
- user = new_user(password: '', password_confirmation: '')
54
- assert user.invalid?
55
- assert_equal 'can\'t be blank', user.errors[:password].join
56
- end
57
-
58
- test 'should require confirmation to be set when creating a new record' do
59
- user = new_user(password: 'new_password', password_confirmation: 'blabla')
60
- assert user.invalid?
61
-
62
- assert_equal 'doesn\'t match Password', user.errors[:password_confirmation].join
63
- end
64
-
65
- test 'should require password when updating/resetting password' do
66
- user = create_user
67
-
68
- user.password = ''
69
- user.password_confirmation = ''
70
-
71
- assert user.invalid?
72
- assert_equal 'can\'t be blank', user.errors[:password].join
73
- end
74
-
75
- test 'should require confirmation when updating/resetting password' do
76
- user = create_user
77
- user.password_confirmation = 'another_password'
78
- assert user.invalid?
79
-
80
- assert_equal 'doesn\'t match Password', user.errors[:password_confirmation].join
81
- end
82
-
83
- test 'should require a password with minimum of 7 characters' do
84
- user = new_user(password: '12345', password_confirmation: '12345')
85
- assert user.invalid?
86
- assert_equal 'is too short (minimum is 7 characters)', user.errors[:password].join
87
- end
88
-
89
- test 'should require a password with maximum of 72 characters long' do
90
- user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
91
- assert user.invalid?
92
- assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
93
- end
94
-
95
- test 'should not require password length when it\'s not changed' do
96
- user = create_user.reload
97
- user.password = user.password_confirmation = nil
98
- assert user.valid?
99
-
100
- user.password_confirmation = 'confirmation'
101
- assert user.invalid?
102
- refute (user.errors[:password].join =~ /is too long/)
103
- end
104
-
105
- test 'should complain about length even if password is not required' do
106
- user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
107
- user.stubs(:password_required?).returns(false)
108
- assert user.invalid?
109
- assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
110
- end
111
-
112
- test 'should not be included in objects with invalid API' do
113
- assert_raise RuntimeError do
114
- Class.new.send :include, Devise::Models::Validatable
115
- end
116
- end
117
-
118
- test 'required_fields should be an empty array' do
119
- assert_equal Devise::Models::Validatable.required_fields(User), []
120
- end
121
- end
@@ -1,155 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'test_models'
5
-
6
- class ActiveRecordTest < ActiveSupport::TestCase
7
- def include_module?(klass, mod)
8
- klass.devise_modules.include?(mod) &&
9
- klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
10
- end
11
-
12
- def assert_include_modules(klass, *modules)
13
- modules.each do |mod|
14
- assert include_module?(klass, mod)
15
- end
16
-
17
- (Devise::ALL - modules).each do |mod|
18
- refute include_module?(klass, mod)
19
- end
20
- end
21
-
22
- test 'can cherry pick modules' do
23
- assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
24
- end
25
-
26
- test 'validations options are not applied too late' do
27
- validators = WithValidation.validators_on :password
28
- length = validators.find { |v| v.kind == :length }
29
- assert_equal 2, length.options[:minimum]
30
- assert_equal 6, length.options[:maximum]
31
- end
32
-
33
- test 'validations are applied just once' do
34
- validators = Several.validators_on :password
35
- assert_equal 1, validators.select{ |v| v.kind == :length }.length
36
- end
37
-
38
- test 'chosen modules are inheritable' do
39
- assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
40
- end
41
-
42
- test 'order of module inclusion' do
43
- correct_module_order = [:database_authenticatable, :recoverable, :registerable, :confirmable, :lockable, :timeoutable]
44
- incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :confirmable]
45
-
46
- assert_include_modules Admin, *incorrect_module_order
47
-
48
- # get module constants from symbol list
49
- module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }
50
-
51
- # confirm that they adhere to the order in ALL
52
- # get included modules, filter out the noise, and reverse the order
53
- assert_equal module_constants, (Admin.included_modules & module_constants).reverse
54
- end
55
-
56
- test 'raise error on invalid module' do
57
- assert_raise NameError do
58
- # Mix valid an invalid modules.
59
- Configurable.class_eval { devise :database_authenticatable, :doesnotexit }
60
- end
61
- end
62
-
63
- test 'set a default value for stretches' do
64
- assert_equal 15, Configurable.stretches
65
- end
66
-
67
- test 'set a default value for pepper' do
68
- assert_equal 'abcdef', Configurable.pepper
69
- end
70
-
71
- test 'set a default value for allow_unconfirmed_access_for' do
72
- assert_equal 5.days, Configurable.allow_unconfirmed_access_for
73
- end
74
-
75
- test 'set a default value for remember_for' do
76
- assert_equal 7.days, Configurable.remember_for
77
- end
78
-
79
- test 'set a default value for timeout_in' do
80
- assert_equal 15.minutes, Configurable.timeout_in
81
- end
82
-
83
- test 'set a default value for unlock_in' do
84
- assert_equal 10.days, Configurable.unlock_in
85
- end
86
-
87
- test 'set null fields on migrations' do
88
- # Ignore email sending since no email exists.
89
- klass = Class.new(Admin) do
90
- def send_devise_notification(*); end
91
- end
92
-
93
- klass.create!
94
- end
95
- end
96
-
97
- module StubModelFilters
98
- def stub_filter(name)
99
- define_singleton_method(name) { |*| nil }
100
- end
101
- end
102
-
103
- class CheckFieldsTest < ActiveSupport::TestCase
104
- test 'checks if the class respond_to the required fields' do
105
- Player = Class.new do
106
- extend Devise::Models
107
- extend StubModelFilters
108
-
109
- stub_filter :before_validation
110
- stub_filter :after_update
111
-
112
- devise :database_authenticatable
113
-
114
- attr_accessor :encrypted_password, :email
115
- end
116
-
117
- assert_nothing_raised do
118
- Devise::Models.check_fields!(Player)
119
- end
120
- end
121
-
122
- test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\'t respond_to one of the attributes' do
123
- Clown = Class.new do
124
- extend Devise::Models
125
- extend StubModelFilters
126
-
127
- stub_filter :before_validation
128
- stub_filter :after_update
129
-
130
- devise :database_authenticatable
131
-
132
- attr_accessor :encrypted_password
133
- end
134
-
135
- assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: email" do
136
- Devise::Models.check_fields!(Clown)
137
- end
138
- end
139
-
140
- test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do
141
- Magician = Class.new do
142
- extend Devise::Models
143
- extend StubModelFilters
144
-
145
- stub_filter :before_validation
146
- stub_filter :after_update
147
-
148
- devise :database_authenticatable
149
- end
150
-
151
- assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: encrypted_password, email" do
152
- Devise::Models.check_fields!(Magician)
153
- end
154
- end
155
- end