devise 4.4.3 → 4.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -2
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +50 -21
  5. data/app/controllers/devise/passwords_controller.rb +1 -0
  6. data/app/controllers/devise/registrations_controller.rb +26 -8
  7. data/app/controllers/devise_controller.rb +1 -1
  8. data/app/helpers/devise_helper.rb +10 -19
  9. data/app/views/devise/confirmations/new.html.erb +1 -1
  10. data/app/views/devise/passwords/edit.html.erb +3 -3
  11. data/app/views/devise/passwords/new.html.erb +1 -1
  12. data/app/views/devise/registrations/edit.html.erb +4 -4
  13. data/app/views/devise/registrations/new.html.erb +3 -3
  14. data/app/views/devise/sessions/new.html.erb +3 -3
  15. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  16. data/app/views/devise/shared/_links.html.erb +7 -7
  17. data/app/views/devise/unlocks/new.html.erb +1 -1
  18. data/config/locales/en.yml +2 -1
  19. data/lib/devise/controllers/helpers.rb +1 -1
  20. data/lib/devise/controllers/sign_in_out.rb +3 -0
  21. data/lib/devise/failure_app.rb +24 -3
  22. data/lib/devise/models/authenticatable.rb +38 -40
  23. data/lib/devise/models/confirmable.rb +16 -1
  24. data/lib/devise/models/database_authenticatable.rb +45 -11
  25. data/lib/devise/models/lockable.rb +2 -2
  26. data/lib/devise/models/registerable.rb +2 -0
  27. data/lib/devise/models/trackable.rb +8 -1
  28. data/lib/devise/models/validatable.rb +1 -1
  29. data/lib/devise/parameter_filter.rb +2 -0
  30. data/lib/devise/parameter_sanitizer.rb +13 -1
  31. data/lib/devise/rails/routes.rb +2 -2
  32. data/lib/devise/secret_key_finder.rb +2 -0
  33. data/lib/devise/strategies/authenticatable.rb +1 -1
  34. data/lib/devise/strategies/database_authenticatable.rb +6 -1
  35. data/lib/devise/test/controller_helpers.rb +1 -1
  36. data/lib/devise/version.rb +1 -1
  37. data/lib/devise.rb +4 -0
  38. data/lib/generators/active_record/devise_generator.rb +9 -9
  39. data/lib/generators/devise/controllers_generator.rb +1 -1
  40. data/lib/generators/devise/orm_helpers.rb +2 -2
  41. data/lib/generators/mongoid/devise_generator.rb +5 -5
  42. data/lib/generators/templates/devise.rb +19 -3
  43. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
  44. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
  45. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
  46. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -3
  47. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
  48. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
  49. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
  50. metadata +5 -310
  51. data/.gitignore +0 -10
  52. data/.travis.yml +0 -68
  53. data/.yardopts +0 -9
  54. data/CODE_OF_CONDUCT.md +0 -22
  55. data/CONTRIBUTING.md +0 -79
  56. data/Gemfile +0 -39
  57. data/Gemfile.lock +0 -193
  58. data/ISSUE_TEMPLATE.md +0 -19
  59. data/Rakefile +0 -37
  60. data/bin/test +0 -13
  61. data/devise.gemspec +0 -28
  62. data/devise.png +0 -0
  63. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  64. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  65. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  66. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  67. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  68. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  69. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  70. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  71. data/guides/bug_report_templates/integration_test.rb +0 -106
  72. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  73. data/test/controllers/custom_strategy_test.rb +0 -66
  74. data/test/controllers/helper_methods_test.rb +0 -24
  75. data/test/controllers/helpers_test.rb +0 -318
  76. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  77. data/test/controllers/internal_helpers_test.rb +0 -129
  78. data/test/controllers/load_hooks_controller_test.rb +0 -21
  79. data/test/controllers/passwords_controller_test.rb +0 -34
  80. data/test/controllers/sessions_controller_test.rb +0 -108
  81. data/test/controllers/url_helpers_test.rb +0 -67
  82. data/test/delegator_test.rb +0 -21
  83. data/test/devise_test.rb +0 -109
  84. data/test/failure_app_test.rb +0 -340
  85. data/test/generators/active_record_generator_test.rb +0 -130
  86. data/test/generators/controllers_generator_test.rb +0 -50
  87. data/test/generators/devise_generator_test.rb +0 -41
  88. data/test/generators/install_generator_test.rb +0 -26
  89. data/test/generators/mongoid_generator_test.rb +0 -25
  90. data/test/generators/views_generator_test.rb +0 -105
  91. data/test/helpers/devise_helper_test.rb +0 -51
  92. data/test/integration/authenticatable_test.rb +0 -706
  93. data/test/integration/confirmable_test.rb +0 -326
  94. data/test/integration/database_authenticatable_test.rb +0 -97
  95. data/test/integration/http_authenticatable_test.rb +0 -114
  96. data/test/integration/lockable_test.rb +0 -242
  97. data/test/integration/mounted_engine_test.rb +0 -38
  98. data/test/integration/omniauthable_test.rb +0 -148
  99. data/test/integration/recoverable_test.rb +0 -349
  100. data/test/integration/registerable_test.rb +0 -365
  101. data/test/integration/rememberable_test.rb +0 -219
  102. data/test/integration/timeoutable_test.rb +0 -186
  103. data/test/integration/trackable_test.rb +0 -99
  104. data/test/mailers/confirmation_instructions_test.rb +0 -117
  105. data/test/mailers/email_changed_test.rb +0 -132
  106. data/test/mailers/mailer_test.rb +0 -20
  107. data/test/mailers/reset_password_instructions_test.rb +0 -98
  108. data/test/mailers/unlock_instructions_test.rb +0 -93
  109. data/test/mapping_test.rb +0 -136
  110. data/test/models/authenticatable_test.rb +0 -25
  111. data/test/models/confirmable_test.rb +0 -549
  112. data/test/models/database_authenticatable_test.rb +0 -283
  113. data/test/models/lockable_test.rb +0 -352
  114. data/test/models/omniauthable_test.rb +0 -9
  115. data/test/models/recoverable_test.rb +0 -263
  116. data/test/models/registerable_test.rb +0 -9
  117. data/test/models/rememberable_test.rb +0 -184
  118. data/test/models/serializable_test.rb +0 -60
  119. data/test/models/timeoutable_test.rb +0 -53
  120. data/test/models/trackable_test.rb +0 -62
  121. data/test/models/validatable_test.rb +0 -121
  122. data/test/models_test.rb +0 -155
  123. data/test/omniauth/config_test.rb +0 -61
  124. data/test/omniauth/url_helpers_test.rb +0 -53
  125. data/test/orm/active_record.rb +0 -24
  126. data/test/orm/mongoid.rb +0 -15
  127. data/test/parameter_sanitizer_test.rb +0 -77
  128. data/test/rails_app/Rakefile +0 -6
  129. data/test/rails_app/app/active_record/admin.rb +0 -8
  130. data/test/rails_app/app/active_record/shim.rb +0 -4
  131. data/test/rails_app/app/active_record/user.rb +0 -20
  132. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  133. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  134. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  135. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  136. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  137. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  138. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  139. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  140. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  141. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  142. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  143. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  144. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  145. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  146. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  147. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  148. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  149. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  150. data/test/rails_app/app/mongoid/admin.rb +0 -31
  151. data/test/rails_app/app/mongoid/shim.rb +0 -25
  152. data/test/rails_app/app/mongoid/user.rb +0 -50
  153. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  154. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  155. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  156. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  157. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  158. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  159. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  160. data/test/rails_app/app/views/home/index.html.erb +0 -1
  161. data/test/rails_app/app/views/home/join.html.erb +0 -1
  162. data/test/rails_app/app/views/home/private.html.erb +0 -1
  163. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  164. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  165. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  166. data/test/rails_app/app/views/users/index.html.erb +0 -1
  167. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  168. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  169. data/test/rails_app/bin/bundle +0 -3
  170. data/test/rails_app/bin/rails +0 -4
  171. data/test/rails_app/bin/rake +0 -4
  172. data/test/rails_app/config/application.rb +0 -48
  173. data/test/rails_app/config/boot.rb +0 -27
  174. data/test/rails_app/config/database.yml +0 -18
  175. data/test/rails_app/config/environment.rb +0 -7
  176. data/test/rails_app/config/environments/development.rb +0 -32
  177. data/test/rails_app/config/environments/production.rb +0 -88
  178. data/test/rails_app/config/environments/test.rb +0 -47
  179. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  180. data/test/rails_app/config/initializers/devise.rb +0 -182
  181. data/test/rails_app/config/initializers/inflections.rb +0 -4
  182. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  183. data/test/rails_app/config/initializers/session_store.rb +0 -3
  184. data/test/rails_app/config/routes.rb +0 -128
  185. data/test/rails_app/config.ru +0 -4
  186. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  187. data/test/rails_app/db/schema.rb +0 -57
  188. data/test/rails_app/lib/shared_admin.rb +0 -23
  189. data/test/rails_app/lib/shared_user.rb +0 -32
  190. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  191. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  192. data/test/rails_app/public/404.html +0 -26
  193. data/test/rails_app/public/422.html +0 -26
  194. data/test/rails_app/public/500.html +0 -26
  195. data/test/rails_app/public/favicon.ico +0 -0
  196. data/test/rails_test.rb +0 -11
  197. data/test/routes_test.rb +0 -281
  198. data/test/secret_key_finder_test.rb +0 -97
  199. data/test/support/action_controller/record_identifier.rb +0 -12
  200. data/test/support/assertions.rb +0 -30
  201. data/test/support/helpers.rb +0 -83
  202. data/test/support/http_method_compatibility.rb +0 -53
  203. data/test/support/integration.rb +0 -95
  204. data/test/support/locale/en.yml +0 -8
  205. data/test/support/mongoid.yml +0 -6
  206. data/test/support/webrat/integrations/rails.rb +0 -35
  207. data/test/test/controller_helpers_test.rb +0 -193
  208. data/test/test/integration_helpers_test.rb +0 -34
  209. data/test/test_helper.rb +0 -36
  210. data/test/test_models.rb +0 -35
@@ -1,349 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class PasswordTest < Devise::IntegrationTest
6
-
7
- def visit_new_password_path
8
- visit new_user_session_path
9
- click_link 'Forgot your password?'
10
- end
11
-
12
- def request_forgot_password(&block)
13
- visit_new_password_path
14
- assert_response :success
15
- refute warden.authenticated?(:user)
16
-
17
- fill_in 'email', with: 'user@test.com'
18
- yield if block_given?
19
-
20
- Devise.stubs(:friendly_token).returns("abcdef")
21
- click_button 'Send me reset password instructions'
22
- end
23
-
24
- def reset_password(options={}, &block)
25
- unless options[:visit] == false
26
- visit edit_user_password_path(reset_password_token: options[:reset_password_token] || "abcdef")
27
- assert_response :success
28
- end
29
-
30
- fill_in 'New password', with: '987654321'
31
- fill_in 'Confirm new password', with: '987654321'
32
- yield if block_given?
33
- click_button 'Change my password'
34
- end
35
-
36
- test 'reset password with email of different case should succeed when email is in the list of case insensitive keys' do
37
- create_user(email: 'Foo@Bar.com')
38
-
39
- request_forgot_password do
40
- fill_in 'email', with: 'foo@bar.com'
41
- end
42
-
43
- assert_current_url '/users/sign_in'
44
- assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'
45
- end
46
-
47
- test 'reset password with email should send an email from a custom mailer' do
48
- create_user(email: 'Foo@Bar.com')
49
-
50
- User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
51
- request_forgot_password do
52
- fill_in 'email', with: 'foo@bar.com'
53
- end
54
-
55
- mail = ActionMailer::Base.deliveries.last
56
- assert_equal ['custom@example.com'], mail.from
57
- assert_match edit_user_password_path(reset_password_token: 'abcdef'), mail.body.encoded
58
- end
59
-
60
- test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do
61
- swap Devise, case_insensitive_keys: [] do
62
- create_user(email: 'Foo@Bar.com')
63
-
64
- request_forgot_password do
65
- fill_in 'email', with: 'foo@bar.com'
66
- end
67
-
68
- assert_response :success
69
- assert_current_url '/users/password'
70
- assert_have_selector "input[type=email][value='foo@bar.com']"
71
- assert_contain 'not found'
72
- end
73
- end
74
-
75
- test 'reset password with email with extra whitespace should succeed when email is in the list of strip whitespace keys' do
76
- create_user(email: 'foo@bar.com')
77
-
78
- request_forgot_password do
79
- fill_in 'email', with: ' foo@bar.com '
80
- end
81
-
82
- assert_current_url '/users/sign_in'
83
- assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'
84
- end
85
-
86
- test 'reset password with email with extra whitespace should fail when email is NOT the list of strip whitespace keys' do
87
- swap Devise, strip_whitespace_keys: [] do
88
- create_user(email: 'foo@bar.com')
89
-
90
- request_forgot_password do
91
- fill_in 'email', with: ' foo@bar.com '
92
- end
93
-
94
- assert_response :success
95
- assert_current_url '/users/password'
96
- assert_have_selector "input[type=email][value=' foo@bar.com ']"
97
- assert_contain 'not found'
98
- end
99
- end
100
-
101
- test 'authenticated user should not be able to visit forgot password page' do
102
- sign_in_as_user
103
- assert warden.authenticated?(:user)
104
-
105
- get new_user_password_path
106
-
107
- assert_response :redirect
108
- assert_redirected_to root_path
109
- end
110
-
111
- test 'not authenticated user should be able to request a forgot password' do
112
- create_user
113
- request_forgot_password
114
-
115
- assert_current_url '/users/sign_in'
116
- assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'
117
- end
118
-
119
- test 'not authenticated user with invalid email should receive an error message' do
120
- request_forgot_password do
121
- fill_in 'email', with: 'invalid.test@test.com'
122
- end
123
-
124
- assert_response :success
125
- assert_current_url '/users/password'
126
- assert_have_selector "input[type=email][value='invalid.test@test.com']"
127
- assert_contain 'not found'
128
- end
129
-
130
- test 'authenticated user should not be able to visit edit password page' do
131
- sign_in_as_user
132
- get edit_user_password_path
133
- assert_response :redirect
134
- assert_redirected_to root_path
135
- assert warden.authenticated?(:user)
136
- end
137
-
138
- test 'not authenticated user without a reset password token should not be able to visit the page' do
139
- get edit_user_password_path
140
- assert_response :redirect
141
- assert_redirected_to "/users/sign_in"
142
- end
143
-
144
- test 'not authenticated user with invalid reset password token should not be able to change their password' do
145
- user = create_user
146
- reset_password reset_password_token: 'invalid_reset_password'
147
-
148
- assert_response :success
149
- assert_current_url '/users/password'
150
- assert_have_selector '#error_explanation'
151
- assert_contain %r{Reset password token(.*)invalid}
152
- refute user.reload.valid_password?('987654321')
153
- end
154
-
155
- test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do
156
- user = create_user
157
- request_forgot_password
158
- reset_password do
159
- fill_in 'Confirm new password', with: 'other_password'
160
- end
161
-
162
- assert_response :success
163
- assert_current_url '/users/password'
164
- assert_have_selector '#error_explanation'
165
- assert_contain "Password confirmation doesn't match Password"
166
- refute user.reload.valid_password?('987654321')
167
- end
168
-
169
- test 'not authenticated user with valid data should be able to change their password' do
170
- user = create_user
171
- request_forgot_password
172
- reset_password
173
-
174
- assert_current_url '/'
175
- assert_contain 'Your password has been changed successfully. You are now signed in.'
176
- assert user.reload.valid_password?('987654321')
177
- end
178
-
179
- test 'after entering invalid data user should still be able to change their password' do
180
- user = create_user
181
- request_forgot_password
182
-
183
- reset_password { fill_in 'Confirm new password', with: 'other_password' }
184
- assert_response :success
185
- assert_have_selector '#error_explanation'
186
- refute user.reload.valid_password?('987654321')
187
-
188
- reset_password visit: false
189
- assert_contain 'Your password has been changed successfully.'
190
- assert user.reload.valid_password?('987654321')
191
- end
192
-
193
- test 'sign in user automatically after changing its password' do
194
- create_user
195
- request_forgot_password
196
- reset_password
197
-
198
- assert warden.authenticated?(:user)
199
- end
200
-
201
- test 'does not sign in user automatically after changing its password if config.sign_in_after_reset_password is false' do
202
- swap Devise, sign_in_after_reset_password: false do
203
- create_user
204
- request_forgot_password
205
- reset_password
206
-
207
- assert_contain 'Your password has been changed successfully.'
208
- assert_not_contain 'You are now signed in.'
209
- assert_equal new_user_session_path, @request.path
210
- assert !warden.authenticated?(:user)
211
- end
212
- end
213
-
214
- test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
215
- [:none, :time].each do |strategy|
216
- swap Devise, unlock_strategy: strategy do
217
- create_user(locked: true)
218
- request_forgot_password
219
- reset_password
220
-
221
- assert_contain 'Your password has been changed successfully.'
222
- assert_not_contain 'You are now signed in.'
223
- assert_equal new_user_session_path, @request.path
224
- assert !warden.authenticated?(:user)
225
- end
226
- end
227
- end
228
-
229
- test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :email' do
230
- swap Devise, unlock_strategy: :email do
231
- user = create_user(locked: true)
232
- request_forgot_password
233
- reset_password
234
-
235
- assert_contain 'Your password has been changed successfully.'
236
- assert !user.reload.access_locked?
237
- assert warden.authenticated?(:user)
238
- end
239
- end
240
-
241
- test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :both' do
242
- swap Devise, unlock_strategy: :both do
243
- user = create_user(locked: true)
244
- request_forgot_password
245
- reset_password
246
-
247
- assert_contain 'Your password has been changed successfully.'
248
- assert !user.reload.access_locked?
249
- assert warden.authenticated?(:user)
250
- end
251
- end
252
-
253
- test 'reset password request with valid E-Mail in XML format should return valid response' do
254
- create_user
255
- post user_password_path(format: 'xml'), params: { user: {email: "user@test.com"} }
256
- assert_response :success
257
- assert_equal response.body, { }.to_xml
258
- end
259
-
260
- test 'reset password request with invalid E-Mail in XML format should return valid response' do
261
- create_user
262
- post user_password_path(format: 'xml'), params: { user: {email: "invalid.test@test.com"} }
263
- assert_response :unprocessable_entity
264
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
265
- end
266
-
267
- test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do
268
- swap Devise, paranoid: true do
269
- create_user
270
- post user_password_path(format: 'xml'), params: { user: {email: "invalid@test.com"} }
271
- assert_response :success
272
- assert_equal response.body, { }.to_xml
273
- end
274
- end
275
-
276
- test 'change password with valid parameters in XML format should return valid response' do
277
- create_user
278
- request_forgot_password
279
- put user_password_path(format: 'xml'), params: { user: {
280
- reset_password_token: 'abcdef', password: '987654321', password_confirmation: '987654321'
281
- }
282
- }
283
- assert_response :success
284
- assert warden.authenticated?(:user)
285
- end
286
-
287
- test 'change password with invalid token in XML format should return invalid response' do
288
- create_user
289
- request_forgot_password
290
- put user_password_path(format: 'xml'), params: { user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} }
291
- assert_response :unprocessable_entity
292
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
293
- end
294
-
295
- test 'change password with invalid new password in XML format should return invalid response' do
296
- user = create_user
297
- request_forgot_password
298
- put user_password_path(format: 'xml'), params: { user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} }
299
- assert_response :unprocessable_entity
300
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
301
- end
302
-
303
- test "when using json requests to ask a confirmable request, should not return the object" do
304
- user = create_user(confirm: false)
305
-
306
- post user_password_path(format: :json), params: { user: { email: user.email } }
307
-
308
- assert_response :success
309
- assert_equal response.body, "{}"
310
- end
311
-
312
- test "when in paranoid mode and with an invalid e-mail, asking to reset a password should display a message that does not indicates that the e-mail does not exists in the database" do
313
- swap Devise, paranoid: true do
314
- visit_new_password_path
315
- fill_in "email", with: "arandomemail@test.com"
316
- click_button 'Send me reset password instructions'
317
-
318
- assert_not_contain "1 error prohibited this user from being saved:"
319
- assert_not_contain "Email not found"
320
- assert_contain "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
321
- assert_current_url "/users/sign_in"
322
- end
323
- end
324
-
325
- test "when in paranoid mode and with a valid e-mail, asking to reset password should display a message that does not indicates that the email exists in the database and redirect to the failure route" do
326
- swap Devise, paranoid: true do
327
- user = create_user
328
- visit_new_password_path
329
- fill_in 'email', with: user.email
330
- click_button 'Send me reset password instructions'
331
-
332
- assert_contain "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
333
- assert_current_url "/users/sign_in"
334
- end
335
- end
336
-
337
- test "after recovering a password, should set failed attempts to 0" do
338
- user = create_user
339
- user.update_attribute(:failed_attempts, 10)
340
-
341
- assert_equal 10, user.failed_attempts
342
- request_forgot_password
343
- reset_password
344
-
345
- assert warden.authenticated?(:user)
346
- user.reload
347
- assert_equal 0, user.failed_attempts
348
- end
349
- end