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,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class MailerTest < ActionMailer::TestCase
6
- test "pass given block to #mail call" do
7
- class TestMailer < Devise::Mailer
8
- def confirmation_instructions(record, token, opts = {})
9
- @token = token
10
- devise_mail(record, :confirmation_instructions, opts) do |format|
11
- format.html(content_transfer_encoding: "7bit")
12
- end
13
- end
14
- end
15
-
16
- mail = TestMailer.confirmation_instructions(create_user, "confirmation-token")
17
-
18
- assert mail.content_transfer_encoding, "7bit"
19
- end
20
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ResetPasswordInstructionsTest < ActionMailer::TestCase
6
- def setup
7
- setup_mailer
8
- Devise.mailer = 'Devise::Mailer'
9
- Devise.mailer_sender = 'test@example.com'
10
- end
11
-
12
- def teardown
13
- Devise.mailer = 'Devise::Mailer'
14
- Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
15
- end
16
-
17
- def user
18
- @user ||= begin
19
- user = create_user
20
- user.send_reset_password_instructions
21
- user
22
- end
23
- end
24
-
25
- def mail
26
- @mail ||= begin
27
- user
28
- ActionMailer::Base.deliveries.last
29
- end
30
- end
31
-
32
- test 'email sent after reseting the user password' do
33
- assert_not_nil mail
34
- end
35
-
36
- test 'content type should be set to html' do
37
- assert mail.content_type.include?('text/html')
38
- end
39
-
40
- test 'send confirmation instructions to the user email' do
41
- assert_equal [user.email], mail.to
42
- end
43
-
44
- test 'set up sender from configuration' do
45
- assert_equal ['test@example.com'], mail.from
46
- end
47
-
48
- test 'set up sender from custom mailer defaults' do
49
- Devise.mailer = 'Users::Mailer'
50
- assert_equal ['custom@example.com'], mail.from
51
- end
52
-
53
- test 'set up sender from custom mailer defaults with proc' do
54
- Devise.mailer = 'Users::FromProcMailer'
55
- assert_equal ['custom@example.com'], mail.from
56
- end
57
-
58
- test 'custom mailer renders parent mailer template' do
59
- Devise.mailer = 'Users::Mailer'
60
- assert_present mail.body.encoded
61
- end
62
-
63
- test 'set up reply to as copy from sender' do
64
- assert_equal ['test@example.com'], mail.reply_to
65
- end
66
-
67
- test 'set up subject from I18n' do
68
- store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do
69
- assert_equal 'Reset instructions', mail.subject
70
- end
71
- end
72
-
73
- test 'subject namespaced by model' do
74
- store_translations :en, devise: { mailer: { reset_password_instructions: { user_subject: 'User Reset Instructions' } } } do
75
- assert_equal 'User Reset Instructions', mail.subject
76
- end
77
- end
78
-
79
- test 'body should have user info' do
80
- assert_match user.email, mail.body.encoded
81
- end
82
-
83
- test 'body should have link to confirm the account' do
84
- host, port = ActionMailer::Base.default_url_options.values_at :host, :port
85
-
86
- if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/password/edit\?reset_password_token=([^"]+)">}
87
- assert_equal Devise.token_generator.digest(user.class, :reset_password_token, $1), user.reset_password_token
88
- else
89
- flunk "expected reset password url regex to match"
90
- end
91
- end
92
-
93
- test 'mailer sender accepts a proc' do
94
- swap Devise, mailer_sender: proc { "another@example.com" } do
95
- assert_equal ['another@example.com'], mail.from
96
- end
97
- end
98
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class UnlockInstructionsTest < ActionMailer::TestCase
6
-
7
- def setup
8
- setup_mailer
9
- Devise.mailer = 'Devise::Mailer'
10
- Devise.mailer_sender = 'test@example.com'
11
- end
12
-
13
- def teardown
14
- Devise.mailer = 'Devise::Mailer'
15
- Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
16
- end
17
-
18
- def user
19
- @user ||= begin
20
- user = create_user
21
- user.lock_access!
22
- user
23
- end
24
- end
25
-
26
- def mail
27
- @mail ||= begin
28
- user
29
- ActionMailer::Base.deliveries.last
30
- end
31
- end
32
-
33
- test 'email sent after locking the user' do
34
- assert_not_nil mail
35
- end
36
-
37
- test 'content type should be set to html' do
38
- assert mail.content_type.include?('text/html')
39
- end
40
-
41
- test 'send unlock instructions to the user email' do
42
- assert_equal [user.email], mail.to
43
- end
44
-
45
- test 'set up sender from configuration' do
46
- assert_equal ['test@example.com'], mail.from
47
- end
48
-
49
- test 'set up sender from custom mailer defaults' do
50
- Devise.mailer = 'Users::Mailer'
51
- assert_equal ['custom@example.com'], mail.from
52
- end
53
-
54
- test 'set up sender from custom mailer defaults with proc' do
55
- Devise.mailer = 'Users::FromProcMailer'
56
- assert_equal ['custom@example.com'], mail.from
57
- end
58
-
59
- test 'custom mailer renders parent mailer template' do
60
- Devise.mailer = 'Users::Mailer'
61
- assert_present mail.body.encoded
62
- end
63
-
64
- test 'set up reply to as copy from sender' do
65
- assert_equal ['test@example.com'], mail.reply_to
66
- end
67
-
68
- test 'set up subject from I18n' do
69
- store_translations :en, devise: { mailer: { unlock_instructions: { subject: 'Yo unlock instructions' } } } do
70
- assert_equal 'Yo unlock instructions', mail.subject
71
- end
72
- end
73
-
74
- test 'subject namespaced by model' do
75
- store_translations :en, devise: { mailer: { unlock_instructions: { user_subject: 'User Unlock Instructions' } } } do
76
- assert_equal 'User Unlock Instructions', mail.subject
77
- end
78
- end
79
-
80
- test 'body should have user info' do
81
- assert_match user.email, mail.body.encoded
82
- end
83
-
84
- test 'body should have link to unlock the account' do
85
- host, port = ActionMailer::Base.default_url_options.values_at :host, :port
86
-
87
- if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/unlock\?unlock_token=([^"]+)">}
88
- assert_equal Devise.token_generator.digest(user.class, :unlock_token, $1), user.unlock_token
89
- else
90
- flunk "expected unlock url regex to match"
91
- end
92
- end
93
- end
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class FakeRequest < Struct.new(:path_info, :params)
6
- end
7
-
8
- class MappingTest < ActiveSupport::TestCase
9
- def fake_request(path, params={})
10
- FakeRequest.new(path, params)
11
- end
12
-
13
- test 'store options' do
14
- mapping = Devise.mappings[:user]
15
- assert_equal User, mapping.to
16
- assert_equal User.devise_modules, mapping.modules
17
- assert_equal "users", mapping.scoped_path
18
- assert_equal :user, mapping.singular
19
- assert_equal "users", mapping.path
20
- assert_equal "/users", mapping.fullpath
21
- end
22
-
23
- test 'store options with namespace' do
24
- mapping = Devise.mappings[:publisher_account]
25
- assert_equal Admin, mapping.to
26
- assert_equal "publisher/accounts", mapping.scoped_path
27
- assert_equal :publisher_account, mapping.singular
28
- assert_equal "accounts", mapping.path
29
- assert_equal "/publisher/accounts", mapping.fullpath
30
- end
31
-
32
- test 'allows path to be given' do
33
- assert_equal "admin_area", Devise.mappings[:admin].path
34
- end
35
-
36
- test 'allows to skip all routes' do
37
- assert_equal [], Devise.mappings[:skip_admin].used_routes
38
- end
39
-
40
- test 'sign_out_via defaults to :delete' do
41
- assert_equal :delete, Devise.mappings[:user].sign_out_via
42
- end
43
-
44
- test 'allows custom sign_out_via to be given' do
45
- assert_equal :delete, Devise.mappings[:sign_out_via_delete].sign_out_via
46
- assert_equal :post, Devise.mappings[:sign_out_via_post].sign_out_via
47
- assert_equal [:delete, :post], Devise.mappings[:sign_out_via_delete_or_post].sign_out_via
48
- end
49
-
50
- test 'allows custom singular to be given' do
51
- assert_equal "accounts", Devise.mappings[:manager].path
52
- end
53
-
54
- test 'has strategies depending on the model declaration' do
55
- assert_equal [:rememberable, :database_authenticatable], Devise.mappings[:user].strategies
56
- assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies
57
- end
58
-
59
- test 'has no input strategies depending on the model declaration' do
60
- assert_equal [:rememberable], Devise.mappings[:user].no_input_strategies
61
- assert_equal [], Devise.mappings[:admin].no_input_strategies
62
- end
63
-
64
- test 'find scope for a given object' do
65
- assert_equal :user, Devise::Mapping.find_scope!(User)
66
- assert_equal :user, Devise::Mapping.find_scope!(:user)
67
- assert_equal :user, Devise::Mapping.find_scope!("user")
68
- assert_equal :user, Devise::Mapping.find_scope!(User.new)
69
- end
70
-
71
- test 'find scope works with single table inheritance' do
72
- assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))
73
- assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
74
- end
75
-
76
- test 'find scope uses devise_scope' do
77
- user = User.new
78
- def user.devise_scope; :special_scope; end
79
- assert_equal :special_scope, Devise::Mapping.find_scope!(user)
80
- end
81
-
82
- test 'find scope raises an error if cannot be found' do
83
- assert_raise RuntimeError do
84
- Devise::Mapping.find_scope!(String)
85
- end
86
- end
87
-
88
- test 'return default path names' do
89
- mapping = Devise.mappings[:user]
90
- assert_equal 'sign_in', mapping.path_names[:sign_in]
91
- assert_equal 'sign_out', mapping.path_names[:sign_out]
92
- assert_equal 'password', mapping.path_names[:password]
93
- assert_equal 'confirmation', mapping.path_names[:confirmation]
94
- assert_equal 'sign_up', mapping.path_names[:sign_up]
95
- assert_equal 'unlock', mapping.path_names[:unlock]
96
- end
97
-
98
- test 'allow custom path names to be given' do
99
- mapping = Devise.mappings[:manager]
100
- assert_equal 'login', mapping.path_names[:sign_in]
101
- assert_equal 'logout', mapping.path_names[:sign_out]
102
- assert_equal 'secret', mapping.path_names[:password]
103
- assert_equal 'verification', mapping.path_names[:confirmation]
104
- assert_equal 'register', mapping.path_names[:sign_up]
105
- assert_equal 'unblock', mapping.path_names[:unlock]
106
- end
107
-
108
- test 'magic predicates' do
109
- mapping = Devise.mappings[:user]
110
- assert mapping.authenticatable?
111
- assert mapping.confirmable?
112
- assert mapping.recoverable?
113
- assert mapping.rememberable?
114
- assert mapping.registerable?
115
-
116
- mapping = Devise.mappings[:admin]
117
- assert mapping.authenticatable?
118
- assert mapping.recoverable?
119
- assert mapping.lockable?
120
- refute mapping.omniauthable?
121
- end
122
-
123
- test 'find mapping by path' do
124
- assert_raise RuntimeError do
125
- Devise::Mapping.find_by_path!('/accounts/facebook/callback')
126
- end
127
-
128
- assert_nothing_raised do
129
- Devise::Mapping.find_by_path!('/:locale/accounts/login')
130
- end
131
-
132
- assert_nothing_raised do
133
- Devise::Mapping.find_by_path!('/accounts/facebook/callback', :path)
134
- end
135
- end
136
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class AuthenticatableTest < ActiveSupport::TestCase
6
- test 'required_fields should be an empty array' do
7
- assert_equal Devise::Models::Validatable.required_fields(User), []
8
- end
9
-
10
- test 'find_first_by_auth_conditions allows custom filtering parameters' do
11
- user = User.create!(email: "example@example.com", password: "1234567")
12
- assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user
13
- assert_nil User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id.to_s.next)
14
- end
15
-
16
- if defined?(ActionController::Parameters)
17
- test 'does not passes an ActionController::Parameters to find_first_by_auth_conditions through find_or_initialize_with_errors' do
18
- user = create_user(email: 'example@example.com')
19
- attributes = ActionController::Parameters.new(email: 'example@example.com')
20
-
21
- User.expects(:find_first_by_auth_conditions).with('email' => 'example@example.com').returns(user)
22
- User.find_or_initialize_with_errors([:email], attributes)
23
- end
24
- end
25
- end
@@ -1,549 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ConfirmableTest < ActiveSupport::TestCase
6
-
7
- def setup
8
- setup_mailer
9
- end
10
-
11
- test 'should set callbacks to send the mail' do
12
- if DEVISE_ORM == :active_record
13
- defined_callbacks = User._commit_callbacks.map(&:filter)
14
- assert_includes defined_callbacks, :send_on_create_confirmation_instructions
15
- assert_includes defined_callbacks, :send_reconfirmation_instructions
16
- elsif DEVISE_ORM == :mongoid
17
- assert_includes User._create_callbacks.map(&:filter), :send_on_create_confirmation_instructions
18
- assert_includes User._update_callbacks.map(&:filter), :send_reconfirmation_instructions
19
- end
20
- end
21
-
22
- test 'should generate confirmation token after creating a record' do
23
- assert_nil new_user.confirmation_token
24
- assert_not_nil create_user.confirmation_token
25
- end
26
-
27
- test 'should never generate the same confirmation token for different users' do
28
- confirmation_tokens = []
29
- 3.times do
30
- token = create_user.confirmation_token
31
- assert !confirmation_tokens.include?(token)
32
- confirmation_tokens << token
33
- end
34
- end
35
-
36
- test 'should confirm a user by updating confirmed at' do
37
- user = create_user
38
- assert_nil user.confirmed_at
39
- assert user.confirm
40
- assert_not_nil user.confirmed_at
41
- end
42
-
43
- test 'should verify whether a user is confirmed or not' do
44
- refute new_user.confirmed?
45
- user = create_user
46
- refute user.confirmed?
47
- user.confirm
48
- assert user.confirmed?
49
- end
50
-
51
- test 'should not confirm a user already confirmed' do
52
- user = create_user
53
- assert user.confirm
54
- assert_blank user.errors[:email]
55
-
56
- refute user.confirm
57
- assert_equal "was already confirmed, please try signing in", user.errors[:email].join
58
- end
59
-
60
- test 'should find and confirm a user automatically based on the raw token' do
61
- user = create_user
62
- raw = user.raw_confirmation_token
63
- confirmed_user = User.confirm_by_token(raw)
64
- assert_equal confirmed_user, user
65
- assert user.reload.confirmed?
66
- end
67
-
68
- test 'should return a new record with errors when a invalid token is given' do
69
- confirmed_user = User.confirm_by_token('invalid_confirmation_token')
70
- refute confirmed_user.persisted?
71
- assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
72
- end
73
-
74
- test 'should return a new record with errors when a blank token is given' do
75
- confirmed_user = User.confirm_by_token('')
76
- refute confirmed_user.persisted?
77
- assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
78
- end
79
-
80
- test 'should generate errors for a user email if user is already confirmed' do
81
- user = create_user
82
- user.confirmed_at = Time.now
83
- user.save
84
- confirmed_user = User.confirm_by_token(user.raw_confirmation_token)
85
- assert confirmed_user.confirmed?
86
- assert_equal "was already confirmed, please try signing in", confirmed_user.errors[:email].join
87
- end
88
-
89
- test 'should show error when a token has already been used' do
90
- user = create_user
91
- raw = user.raw_confirmation_token
92
- User.confirm_by_token(raw)
93
- assert user.reload.confirmed?
94
-
95
- confirmed_user = User.confirm_by_token(raw)
96
- assert_equal "was already confirmed, please try signing in", confirmed_user.errors[:email].join
97
- end
98
-
99
- test 'should send confirmation instructions by email' do
100
- assert_email_sent "mynewuser@example.com" do
101
- create_user email: "mynewuser@example.com"
102
- end
103
- end
104
-
105
- test 'should not send confirmation when trying to save an invalid user' do
106
- assert_email_not_sent do
107
- user = new_user
108
- user.stubs(:valid?).returns(false)
109
- user.save
110
- end
111
- end
112
-
113
- test 'should not generate a new token neither send e-mail if skip_confirmation! is invoked' do
114
- user = new_user
115
- user.skip_confirmation!
116
-
117
- assert_email_not_sent do
118
- user.save!
119
- assert_nil user.confirmation_token
120
- assert_not_nil user.confirmed_at
121
- end
122
- end
123
-
124
- test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do
125
- user = new_user
126
- user.skip_confirmation_notification!
127
-
128
- assert_email_not_sent do
129
- user.save!
130
- refute user.confirmed?
131
- end
132
- end
133
-
134
- test 'should not send confirmation when no email is provided' do
135
- assert_email_not_sent do
136
- user = new_user
137
- user.email = ''
138
- user.save(validate: false)
139
- end
140
- end
141
-
142
- test 'should find a user to send confirmation instructions' do
143
- user = create_user
144
- confirmation_user = User.send_confirmation_instructions(email: user.email)
145
- assert_equal confirmation_user, user
146
- end
147
-
148
- test 'should return a new user if no email was found' do
149
- confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com")
150
- refute confirmation_user.persisted?
151
- end
152
-
153
- test 'should add error to new user email if no email was found' do
154
- confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com")
155
- assert confirmation_user.errors[:email]
156
- assert_equal "not found", confirmation_user.errors[:email].join
157
- end
158
-
159
- test 'should send email instructions for the user confirm its email' do
160
- user = create_user
161
- assert_email_sent user.email do
162
- User.send_confirmation_instructions(email: user.email)
163
- end
164
- end
165
-
166
- test 'should always have confirmation token when email is sent' do
167
- user = new_user
168
- user.instance_eval { def confirmation_required?; false end }
169
- user.save
170
- user.send_confirmation_instructions
171
- assert_not_nil user.reload.confirmation_token
172
- end
173
-
174
- test 'should not resend email instructions if the user change their email' do
175
- user = create_user
176
- user.email = 'new_test@example.com'
177
- assert_email_not_sent do
178
- user.save!
179
- end
180
- end
181
-
182
- test 'should not reset confirmation status or token when updating email' do
183
- user = create_user
184
- original_token = user.confirmation_token
185
- user.confirm
186
- user.email = 'new_test@example.com'
187
- user.save!
188
-
189
- user.reload
190
- assert user.confirmed?
191
- assert_equal original_token, user.confirmation_token
192
- end
193
-
194
- test 'should not be able to send instructions if the user is already confirmed' do
195
- user = create_user
196
- user.confirm
197
- refute user.resend_confirmation_instructions
198
- assert user.confirmed?
199
- assert_equal 'was already confirmed, please try signing in', user.errors[:email].join
200
- end
201
-
202
- test 'confirm time should fallback to devise confirm in default configuration' do
203
- swap Devise, allow_unconfirmed_access_for: 1.day do
204
- user = create_user
205
- user.confirmation_sent_at = 2.days.ago
206
- refute user.active_for_authentication?
207
-
208
- Devise.allow_unconfirmed_access_for = 3.days
209
- assert user.active_for_authentication?
210
- end
211
- end
212
-
213
- test 'should be active when confirmation sent at is not overpast' do
214
- swap Devise, allow_unconfirmed_access_for: 5.days do
215
- Devise.allow_unconfirmed_access_for = 5.days
216
- user = create_user
217
-
218
- user.confirmation_sent_at = 4.days.ago
219
- assert user.active_for_authentication?
220
-
221
- user.confirmation_sent_at = 5.days.ago
222
- refute user.active_for_authentication?
223
- end
224
- end
225
-
226
- test 'should be active when already confirmed' do
227
- user = create_user
228
- refute user.confirmed?
229
- refute user.active_for_authentication?
230
-
231
- user.confirm
232
- assert user.confirmed?
233
- assert user.active_for_authentication?
234
- end
235
-
236
- test 'should not be active when confirm in is zero' do
237
- Devise.allow_unconfirmed_access_for = 0.days
238
- user = create_user
239
- user.confirmation_sent_at = Time.zone.today
240
- refute user.active_for_authentication?
241
- end
242
-
243
- test 'should be active when we set allow_unconfirmed_access_for to nil' do
244
- swap Devise, allow_unconfirmed_access_for: nil do
245
- user = create_user
246
- user.confirmation_sent_at = Time.zone.today
247
- assert user.active_for_authentication?
248
- end
249
- end
250
-
251
- test 'should not be active without confirmation' do
252
- user = create_user
253
- user.confirmation_sent_at = nil
254
- user.save
255
- refute user.reload.active_for_authentication?
256
- end
257
-
258
- test 'should be active without confirmation when confirmation is not required' do
259
- user = create_user
260
- user.instance_eval { def confirmation_required?; false end }
261
- user.confirmation_sent_at = nil
262
- user.save
263
- assert user.reload.active_for_authentication?
264
- end
265
-
266
- test 'should not break when a user tries to reset their password in the case where confirmation is not required and confirm_within is set' do
267
- swap Devise, confirm_within: 3.days do
268
- user = create_user
269
- user.instance_eval { def confirmation_required?; false end }
270
- user.confirmation_sent_at = nil
271
- user.save
272
- assert user.reload.confirm
273
- end
274
- end
275
-
276
- test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do
277
- swap Devise, authentication_keys: [:username, :email] do
278
- user = create_user
279
- confirm_user = User.send_confirmation_instructions(email: user.email, username: user.username)
280
- assert_equal confirm_user, user
281
- end
282
- end
283
-
284
- test 'should require all confirmation_keys' do
285
- swap Devise, confirmation_keys: [:username, :email] do
286
- user = create_user
287
- confirm_user = User.send_confirmation_instructions(email: user.email)
288
- refute confirm_user.persisted?
289
- assert_equal "can't be blank", confirm_user.errors[:username].join
290
- end
291
- end
292
-
293
- def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
294
- user = create_user
295
- user.update_attribute(:confirmation_sent_at, confirmation_sent_at)
296
- confirmed_user = User.confirm_by_token(user.raw_confirmation_token)
297
- assert_equal confirmed_user, user
298
- user.reload.confirmed?
299
- end
300
-
301
- test 'should accept confirmation email token even after 5 years when no expiration is set' do
302
- assert confirm_user_by_token_with_confirmation_sent_at(5.years.ago)
303
- end
304
-
305
- test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do
306
- swap Devise, confirm_within: 3.days do
307
- assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago)
308
- end
309
- end
310
-
311
- test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
312
- swap Devise, confirm_within: 3.days do
313
- refute confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
314
- end
315
- end
316
-
317
- test 'do not generate a new token on resend' do
318
- user = create_user
319
- old = user.confirmation_token
320
- user = User.find(user.id)
321
- user.resend_confirmation_instructions
322
- assert_equal user.confirmation_token, old
323
- end
324
-
325
- test 'generate a new token after first has expired' do
326
- swap Devise, confirm_within: 3.days do
327
- user = create_user
328
- old = user.confirmation_token
329
- user.update_attribute(:confirmation_sent_at, 4.days.ago)
330
- user = User.find(user.id)
331
- user.resend_confirmation_instructions
332
- assert_not_equal user.confirmation_token, old
333
- end
334
- end
335
-
336
- test 'should call after_confirmation if confirmed' do
337
- user = create_user
338
- user.define_singleton_method :after_confirmation do
339
- self.username = self.username.to_s + 'updated'
340
- end
341
- old = user.username
342
- assert user.confirm
343
- assert_not_equal user.username, old
344
- end
345
-
346
- test 'should not call after_confirmation if not confirmed' do
347
- user = create_user
348
- assert user.confirm
349
- user.define_singleton_method :after_confirmation do
350
- self.username = self.username.to_s + 'updated'
351
- end
352
- old = user.username
353
- refute user.confirm
354
- assert_equal user.username, old
355
- end
356
-
357
- test 'should always perform validations upon confirm when ensure valid true' do
358
- admin = create_admin
359
- admin.stubs(:valid?).returns(false)
360
- refute admin.confirm(ensure_valid: true)
361
- end
362
- end
363
-
364
- class ReconfirmableTest < ActiveSupport::TestCase
365
- test 'should not worry about validations on confirm even with reconfirmable' do
366
- admin = create_admin
367
- admin.reset_password_token = "a"
368
- assert admin.confirm
369
- end
370
-
371
- test 'should generate confirmation token after changing email' do
372
- admin = create_admin
373
- assert admin.confirm
374
- residual_token = admin.confirmation_token
375
- assert admin.update(email: 'new_test@example.com')
376
- assert_not_equal residual_token, admin.confirmation_token
377
- end
378
-
379
- test 'should not regenerate confirmation token or require reconfirmation if skipping reconfirmation after changing email' do
380
- admin = create_admin
381
- original_token = admin.confirmation_token
382
- assert admin.confirm
383
- admin.skip_reconfirmation!
384
- assert admin.update(email: 'new_test@example.com')
385
- assert admin.confirmed?
386
- refute admin.pending_reconfirmation?
387
- assert_equal original_token, admin.confirmation_token
388
- end
389
-
390
- test 'should skip sending reconfirmation email when email is changed and skip_confirmation_notification! is invoked' do
391
- admin = create_admin
392
- admin.skip_confirmation_notification!
393
-
394
- assert_email_not_sent do
395
- admin.update(email: 'new_test@example.com')
396
- end
397
- end
398
-
399
- test 'should regenerate confirmation token after changing email' do
400
- admin = create_admin
401
- assert admin.confirm
402
- assert admin.update(email: 'old_test@example.com')
403
- token = admin.confirmation_token
404
- assert admin.update(email: 'new_test@example.com')
405
- assert_not_equal token, admin.confirmation_token
406
- end
407
-
408
- test 'should send confirmation instructions by email after changing email' do
409
- admin = create_admin
410
- assert admin.confirm
411
- assert_email_sent "new_test@example.com" do
412
- assert admin.update(email: 'new_test@example.com')
413
- end
414
- assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
415
- end
416
-
417
- test 'should send confirmation instructions by email after changing email from nil' do
418
- admin = create_admin(email: nil)
419
- assert_email_sent "new_test@example.com" do
420
- assert admin.update(email: 'new_test@example.com')
421
- end
422
- assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
423
- end
424
-
425
- test 'should not send confirmation by email after changing password' do
426
- admin = create_admin
427
- assert admin.confirm
428
- assert_email_not_sent do
429
- assert admin.update(password: 'newpass', password_confirmation: 'newpass')
430
- end
431
- end
432
-
433
- test 'should not send confirmation by email after changing to a blank email' do
434
- admin = create_admin
435
- assert admin.confirm
436
- assert_email_not_sent do
437
- admin.email = ''
438
- admin.save(validate: false)
439
- end
440
- end
441
-
442
- test 'should stay confirmed when email is changed' do
443
- admin = create_admin
444
- assert admin.confirm
445
- assert admin.update(email: 'new_test@example.com')
446
- assert admin.confirmed?
447
- end
448
-
449
- test 'should update email only when it is confirmed' do
450
- admin = create_admin
451
- assert admin.confirm
452
- assert admin.update(email: 'new_test@example.com')
453
- assert_not_equal 'new_test@example.com', admin.email
454
- assert admin.confirm
455
- assert_equal 'new_test@example.com', admin.email
456
- end
457
-
458
- test 'should not allow admin to get past confirmation email by resubmitting their new address' do
459
- admin = create_admin
460
- assert admin.confirm
461
- assert admin.update(email: 'new_test@example.com')
462
- assert_not_equal 'new_test@example.com', admin.email
463
- assert admin.update(email: 'new_test@example.com')
464
- assert_not_equal 'new_test@example.com', admin.email
465
- end
466
-
467
- test 'should find a admin by send confirmation instructions with unconfirmed_email' do
468
- admin = create_admin
469
- assert admin.confirm
470
- assert admin.update(email: 'new_test@example.com')
471
- confirmation_admin = Admin.send_confirmation_instructions(email: admin.unconfirmed_email)
472
- assert_equal confirmation_admin, admin
473
- end
474
-
475
- test 'should return a new admin if no email or unconfirmed_email was found' do
476
- confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com")
477
- refute confirmation_admin.persisted?
478
- end
479
-
480
- test 'should add error to new admin email if no email or unconfirmed_email was found' do
481
- confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com")
482
- assert confirmation_admin.errors[:email]
483
- assert_equal "not found", confirmation_admin.errors[:email].join
484
- end
485
-
486
- test 'should find admin with email in unconfirmed_emails' do
487
- admin = create_admin
488
- admin.unconfirmed_email = "new_test@email.com"
489
- assert admin.save
490
- admin = Admin.find_by_unconfirmed_email_with_errors(email: "new_test@email.com")
491
- assert admin.persisted?
492
- end
493
-
494
- test 'required_fields should contain the fields that Devise uses' do
495
- assert_equal Devise::Models::Confirmable.required_fields(User), [
496
- :confirmation_token,
497
- :confirmed_at,
498
- :confirmation_sent_at
499
- ]
500
- end
501
-
502
- test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do
503
- assert_equal Devise::Models::Confirmable.required_fields(Admin), [
504
- :confirmation_token,
505
- :confirmed_at,
506
- :confirmation_sent_at,
507
- :unconfirmed_email
508
- ]
509
- end
510
-
511
- test 'should not require reconfirmation after creating a record' do
512
- admin = create_admin
513
- assert !admin.pending_reconfirmation?
514
- end
515
-
516
- test 'should not require reconfirmation after creating a record with #save called in callback' do
517
- class Admin::WithSaveInCallback < Admin
518
- after_create :save
519
- end
520
-
521
- admin = Admin::WithSaveInCallback.create(valid_attributes.except(:username))
522
- assert !admin.pending_reconfirmation?
523
- end
524
-
525
- test 'should require reconfirmation after creating a record and updating the email' do
526
- admin = create_admin
527
- assert !admin.instance_variable_get(:@bypass_confirmation_postpone)
528
- admin.email = "new_test@email.com"
529
- admin.save
530
- assert admin.pending_reconfirmation?
531
- end
532
-
533
- test 'should notify previous email on email change when configured' do
534
- swap Devise, send_email_changed_notification: true do
535
- admin = create_admin
536
- original_email = admin.email
537
-
538
- assert_difference 'ActionMailer::Base.deliveries.size', 2 do
539
- assert admin.update(email: 'new-email@example.com')
540
- end
541
- assert_equal original_email, ActionMailer::Base.deliveries[-2]['to'].to_s
542
- assert_equal 'new-email@example.com', ActionMailer::Base.deliveries[-1]['to'].to_s
543
-
544
- assert_email_not_sent do
545
- assert admin.confirm
546
- end
547
- end
548
- end
549
- end