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,186 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class SessionTimeoutTest < Devise::IntegrationTest
6
-
7
- def last_request_at
8
- @controller.user_session['last_request_at']
9
- end
10
-
11
- test 'set last request at in user session after each request' do
12
- sign_in_as_user
13
- assert_not_nil last_request_at
14
-
15
- @controller.user_session.delete('last_request_at')
16
- get users_path
17
- assert_not_nil last_request_at
18
- end
19
-
20
- test 'set last request at in user session after each request is skipped if tracking is disabled' do
21
- sign_in_as_user
22
- old_last_request = last_request_at
23
- assert_not_nil last_request_at
24
-
25
- get users_path, headers: { 'devise.skip_trackable' => true }
26
- assert_equal old_last_request, last_request_at
27
- end
28
-
29
- test 'does not set last request at in user session after each request if timeoutable is disabled' do
30
- sign_in_as_user
31
- old_last_request = last_request_at
32
- assert_not_nil last_request_at
33
-
34
- new_time = 2.seconds.from_now
35
- Time.stubs(:now).returns(new_time)
36
-
37
- get users_path, headers: { 'devise.skip_timeoutable' => true }
38
- assert_equal old_last_request, last_request_at
39
- end
40
-
41
- test 'does not time out user session before default limit time' do
42
- sign_in_as_user
43
- assert_response :success
44
- assert warden.authenticated?(:user)
45
-
46
- get users_path
47
- assert_response :success
48
- assert warden.authenticated?(:user)
49
- end
50
-
51
- test 'time out user session after default limit time when sign_out_all_scopes is false' do
52
- swap Devise, sign_out_all_scopes: false do
53
- sign_in_as_admin
54
-
55
- user = sign_in_as_user
56
- get expire_user_path(user)
57
- assert_not_nil last_request_at
58
-
59
- get users_path
60
- assert_redirected_to users_path
61
- refute warden.authenticated?(:user)
62
- assert warden.authenticated?(:admin)
63
- end
64
- end
65
-
66
- test 'time out all sessions after default limit time when sign_out_all_scopes is true' do
67
- swap Devise, sign_out_all_scopes: true do
68
- sign_in_as_admin
69
-
70
- user = sign_in_as_user
71
- get expire_user_path(user)
72
- assert_not_nil last_request_at
73
-
74
- get root_path
75
- refute warden.authenticated?(:user)
76
- refute warden.authenticated?(:admin)
77
- end
78
- end
79
-
80
- test 'time out user session after deault limit time and redirect to latest get request' do
81
- user = sign_in_as_user
82
- visit edit_form_user_path(user)
83
-
84
- click_button 'Update'
85
- sign_in_as_user
86
-
87
- assert_equal edit_form_user_url(user), current_url
88
- end
89
-
90
- test 'time out is not triggered on sign out' do
91
- user = sign_in_as_user
92
- get expire_user_path(user)
93
-
94
- delete destroy_user_session_path
95
-
96
- assert_response :redirect
97
- assert_redirected_to root_path
98
- follow_redirect!
99
- assert_contain 'Signed out successfully'
100
- end
101
-
102
- test 'expired session is not extended by sign in page' do
103
- user = sign_in_as_user
104
- get expire_user_path(user)
105
- assert warden.authenticated?(:user)
106
-
107
- get "/users/sign_in"
108
- assert_redirected_to "/users/sign_in"
109
- follow_redirect!
110
-
111
- assert_response :success
112
- assert_contain 'Sign in'
113
- refute warden.authenticated?(:user)
114
- end
115
-
116
- test 'time out is not triggered on sign in' do
117
- user = sign_in_as_user
118
- get expire_user_path(user)
119
-
120
- post "/users/sign_in", params: { email: user.email, password: "123456" }
121
-
122
- assert_response :redirect
123
- follow_redirect!
124
- assert_contain 'You are signed in'
125
- end
126
-
127
- test 'user configured timeout limit' do
128
- swap Devise, timeout_in: 8.minutes do
129
- user = sign_in_as_user
130
-
131
- get users_path
132
- assert_not_nil last_request_at
133
- assert_response :success
134
- assert warden.authenticated?(:user)
135
-
136
- get expire_user_path(user)
137
- get users_path
138
- assert_redirected_to users_path
139
- refute warden.authenticated?(:user)
140
- end
141
- end
142
-
143
- test 'error message with i18n' do
144
- store_translations :en, devise: {
145
- failure: { user: { timeout: 'Session expired!' } }
146
- } do
147
- user = sign_in_as_user
148
-
149
- get expire_user_path(user)
150
- get root_path
151
- follow_redirect!
152
- assert_contain 'Session expired!'
153
- end
154
- end
155
-
156
- test 'error message with i18n with double redirect' do
157
- store_translations :en, devise: {
158
- failure: { user: { timeout: 'Session expired!' } }
159
- } do
160
- user = sign_in_as_user
161
-
162
- get expire_user_path(user)
163
- get users_path
164
- follow_redirect!
165
- follow_redirect!
166
- assert_contain 'Session expired!'
167
- end
168
- end
169
-
170
- test 'time out not triggered if remembered' do
171
- user = sign_in_as_user remember_me: true
172
- get expire_user_path(user)
173
- assert_not_nil last_request_at
174
-
175
- get users_path
176
- assert_response :success
177
- assert warden.authenticated?(:user)
178
- end
179
-
180
- test 'does not crash when the last_request_at is a String' do
181
- user = sign_in_as_user
182
-
183
- get edit_form_user_path(user, last_request_at: Time.now.utc.to_s)
184
- get users_path
185
- end
186
- end
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TrackableHooksTest < Devise::IntegrationTest
6
- test "trackable should not run model validations" do
7
- sign_in_as_user
8
-
9
- refute User.validations_performed
10
- end
11
-
12
- test "current and last sign in timestamps are updated on each sign in" do
13
- user = create_user
14
- assert_nil user.current_sign_in_at
15
- assert_nil user.last_sign_in_at
16
-
17
- sign_in_as_user
18
- user.reload
19
-
20
- assert user.current_sign_in_at.acts_like?(:time)
21
- assert user.last_sign_in_at.acts_like?(:time)
22
-
23
- assert_equal user.current_sign_in_at, user.last_sign_in_at
24
- assert user.current_sign_in_at >= user.created_at
25
-
26
- delete destroy_user_session_path
27
- new_time = 2.seconds.from_now
28
- Time.stubs(:now).returns(new_time)
29
-
30
- sign_in_as_user
31
- user.reload
32
- assert user.current_sign_in_at > user.last_sign_in_at
33
- end
34
-
35
- test "current and last sign in remote ip are updated on each sign in" do
36
- user = create_user
37
- assert_nil user.current_sign_in_ip
38
- assert_nil user.last_sign_in_ip
39
-
40
- sign_in_as_user
41
- user.reload
42
-
43
- assert_equal "127.0.0.1", user.current_sign_in_ip
44
- assert_equal "127.0.0.1", user.last_sign_in_ip
45
- end
46
-
47
- test "current remote ip returns original ip behind a non transparent proxy" do
48
- user = create_user
49
-
50
- arbitrary_ip = '200.121.1.69'
51
- sign_in_as_user do
52
- header 'HTTP_X_FORWARDED_FOR', arbitrary_ip
53
- end
54
- user.reload
55
- assert_equal arbitrary_ip, user.current_sign_in_ip
56
- end
57
-
58
- test "increase sign in count" do
59
- user = create_user
60
- assert_equal 0, user.sign_in_count
61
-
62
- sign_in_as_user
63
- user.reload
64
- assert_equal 1, user.sign_in_count
65
-
66
- delete destroy_user_session_path
67
- sign_in_as_user
68
- user.reload
69
- assert_equal 2, user.sign_in_count
70
- end
71
-
72
- test "does not update anything if user has signed out along the way" do
73
- swap Devise, allow_unconfirmed_access_for: 0.days do
74
- user = create_user(confirm: false)
75
- sign_in_as_user
76
-
77
- user.reload
78
- assert_nil user.current_sign_in_at
79
- assert_nil user.last_sign_in_at
80
- end
81
- end
82
-
83
- test "do not track if devise.skip_trackable is set" do
84
- user = create_user
85
- sign_in_as_user do
86
- header 'devise.skip_trackable', '1'
87
- end
88
- user.reload
89
- assert_equal 0, user.sign_in_count
90
- delete destroy_user_session_path
91
-
92
- sign_in_as_user do
93
- header 'devise.skip_trackable', false
94
- end
95
- user.reload
96
- assert_equal 1, user.sign_in_count
97
- end
98
-
99
- end
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ConfirmationInstructionsTest < 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 ||= create_user
20
- end
21
-
22
- def mail
23
- @mail ||= begin
24
- user
25
- ActionMailer::Base.deliveries.first
26
- end
27
- end
28
-
29
- test 'email sent after creating the user' do
30
- assert_not_nil mail
31
- end
32
-
33
- test 'content type should be set to html' do
34
- assert mail.content_type.include?('text/html')
35
- end
36
-
37
- test 'send confirmation instructions to the user email' do
38
- mail
39
- assert_equal [user.email], mail.to
40
- end
41
-
42
- test 'set up sender from configuration' do
43
- assert_equal ['test@example.com'], mail.from
44
- end
45
-
46
- test 'set up sender from custom mailer defaults' do
47
- Devise.mailer = 'Users::Mailer'
48
- assert_equal ['custom@example.com'], mail.from
49
- end
50
-
51
- test 'set up sender from custom mailer defaults with proc' do
52
- Devise.mailer = 'Users::FromProcMailer'
53
- assert_equal ['custom@example.com'], mail.from
54
- end
55
-
56
- test 'custom mailer renders parent mailer template' do
57
- Devise.mailer = 'Users::Mailer'
58
- assert_present mail.body.encoded
59
- end
60
-
61
- test 'set up reply to as copy from sender' do
62
- assert_equal ['test@example.com'], mail.reply_to
63
- end
64
-
65
- test 'set up reply to as different if set in defaults' do
66
- Devise.mailer = 'Users::ReplyToMailer'
67
- assert_equal ['custom@example.com'], mail.from
68
- assert_equal ['custom_reply_to@example.com'], mail.reply_to
69
- end
70
-
71
- test 'set up subject from I18n' do
72
- store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do
73
- assert_equal 'Account Confirmation', mail.subject
74
- end
75
- end
76
-
77
- test 'subject namespaced by model' do
78
- store_translations :en, devise: { mailer: { confirmation_instructions: { user_subject: 'User Account Confirmation' } } } do
79
- assert_equal 'User Account Confirmation', mail.subject
80
- end
81
- end
82
-
83
- test 'body should have user info' do
84
- assert_match user.email, mail.body.encoded
85
- end
86
-
87
- test 'body should have link to confirm the account' do
88
- host, port = ActionMailer::Base.default_url_options.values_at :host, :port
89
-
90
- if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/confirmation\?confirmation_token=([^"]+)">}
91
- assert_equal $1, user.confirmation_token
92
- else
93
- flunk "expected confirmation url regex to match"
94
- end
95
- end
96
-
97
- test 'renders a scoped if scoped_views is set to true' do
98
- swap Devise, scoped_views: true do
99
- assert_equal user.email, mail.body.decoded
100
- end
101
- end
102
-
103
- test 'renders a scoped if scoped_views is set in the mailer class' do
104
- begin
105
- Devise::Mailer.scoped_views = true
106
- assert_equal user.email, mail.body.decoded
107
- ensure
108
- Devise::Mailer.send :remove_instance_variable, :@scoped_views
109
- end
110
- end
111
-
112
- test 'mailer sender accepts a proc' do
113
- swap Devise, mailer_sender: proc { "another@example.com" } do
114
- assert_equal ['another@example.com'], mail.from
115
- end
116
- end
117
- end
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class EmailChangedTest < ActionMailer::TestCase
6
- def setup
7
- setup_mailer
8
- Devise.mailer = 'Devise::Mailer'
9
- Devise.mailer_sender = 'test@example.com'
10
- Devise.send_email_changed_notification = true
11
- end
12
-
13
- def teardown
14
- Devise.mailer = 'Devise::Mailer'
15
- Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
16
- Devise.send_email_changed_notification = false
17
- end
18
-
19
- def user
20
- @user ||= create_user.tap { |u|
21
- @original_user_email = u.email
22
- u.update!(email: 'new-email@example.com')
23
- }
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 changing the user email' 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 email changed to the original user email' do
42
- mail
43
- assert_equal [@original_user_email], mail.to
44
- end
45
-
46
- test 'set up sender from configuration' do
47
- assert_equal ['test@example.com'], mail.from
48
- end
49
-
50
- test 'set up sender from custom mailer defaults' do
51
- Devise.mailer = 'Users::Mailer'
52
- assert_equal ['custom@example.com'], mail.from
53
- end
54
-
55
- test 'set up sender from custom mailer defaults with proc' do
56
- Devise.mailer = 'Users::FromProcMailer'
57
- assert_equal ['custom@example.com'], mail.from
58
- end
59
-
60
- test 'custom mailer renders parent mailer template' do
61
- Devise.mailer = 'Users::Mailer'
62
- assert_present mail.body.encoded
63
- end
64
-
65
- test 'set up reply to as copy from sender' do
66
- assert_equal ['test@example.com'], mail.reply_to
67
- end
68
-
69
- test 'set up reply to as different if set in defaults' do
70
- Devise.mailer = 'Users::ReplyToMailer'
71
- assert_equal ['custom@example.com'], mail.from
72
- assert_equal ['custom_reply_to@example.com'], mail.reply_to
73
- end
74
-
75
- test 'set up subject from I18n' do
76
- store_translations :en, devise: { mailer: { email_changed: { subject: 'Email Has Changed' } } } do
77
- assert_equal 'Email Has Changed', mail.subject
78
- end
79
- end
80
-
81
- test 'subject namespaced by model' do
82
- store_translations :en, devise: { mailer: { email_changed: { user_subject: 'User Email Has Changed' } } } do
83
- assert_equal 'User Email Has Changed', mail.subject
84
- end
85
- end
86
-
87
- test 'body should have user info' do
88
- body = mail.body.encoded
89
- assert_match "Hello #{@original_user_email}", body
90
- assert_match "has been changed to #{user.email}", body
91
- end
92
- end
93
-
94
- class EmailChangedReconfirmationTest < ActionMailer::TestCase
95
- def setup
96
- setup_mailer
97
- Devise.mailer = 'Devise::Mailer'
98
- Devise.mailer_sender = 'test@example.com'
99
- Devise.send_email_changed_notification = true
100
- end
101
-
102
- def teardown
103
- Devise.mailer = 'Devise::Mailer'
104
- Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
105
- Devise.send_email_changed_notification = false
106
- end
107
-
108
- def admin
109
- @admin ||= create_admin.tap { |u|
110
- @original_admin_email = u.email
111
- u.update!(email: 'new-email@example.com')
112
- }
113
- end
114
-
115
- def mail
116
- @mail ||= begin
117
- admin
118
- ActionMailer::Base.deliveries[-2]
119
- end
120
- end
121
-
122
- test 'send email changed to the original user email' do
123
- mail
124
- assert_equal [@original_admin_email], mail.to
125
- end
126
-
127
- test 'body should have unconfirmed user info' do
128
- body = mail.body.encoded
129
- assert_match admin.email, body
130
- assert_match "is being changed to #{admin.unconfirmed_email}", body
131
- end
132
- end