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,346 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'ostruct'
5
-
6
- class FailureTest < ActiveSupport::TestCase
7
- class RootFailureApp < Devise::FailureApp
8
- def fake_app
9
- Object.new
10
- end
11
- end
12
-
13
- class FailureWithSubdomain < RootFailureApp
14
- routes = ActionDispatch::Routing::RouteSet.new
15
-
16
- routes.draw do
17
- scope subdomain: 'sub' do
18
- root to: 'foo#bar'
19
- end
20
- end
21
-
22
- include routes.url_helpers
23
- end
24
-
25
- class FailureWithI18nOptions < Devise::FailureApp
26
- def i18n_options(options)
27
- options.merge(name: 'Steve')
28
- end
29
- end
30
-
31
- class FakeEngineApp < Devise::FailureApp
32
- class FakeEngine
33
- def new_user_on_engine_session_url _
34
- '/user_on_engines/sign_in'
35
- end
36
- end
37
-
38
- def main_app
39
- raise 'main_app router called instead of fake_engine'
40
- end
41
-
42
- def fake_engine
43
- @fake_engine ||= FakeEngine.new
44
- end
45
- end
46
-
47
- def self.context(name, &block)
48
- instance_eval(&block)
49
- end
50
-
51
- def call_failure(env_params={})
52
- env = {
53
- 'REQUEST_URI' => 'http://test.host/',
54
- 'HTTP_HOST' => 'test.host',
55
- 'REQUEST_METHOD' => 'GET',
56
- 'warden.options' => { scope: :user },
57
- 'rack.session' => {},
58
- 'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime[:html]),
59
- 'rack.input' => "",
60
- 'warden' => OpenStruct.new(message: nil)
61
- }.merge!(env_params)
62
-
63
- # Passing nil for action_dispatch.request.formats prevents the default from being used in Rails 5, need to remove it
64
- if env.has_key?('action_dispatch.request.formats') && env['action_dispatch.request.formats'].nil?
65
- env.delete 'action_dispatch.request.formats' unless env['action_dispatch.request.formats']
66
- end
67
-
68
- @response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
69
- @request = ActionDispatch::Request.new(env)
70
- end
71
-
72
- context 'When redirecting' do
73
- test 'returns to the default redirect location' do
74
- call_failure
75
- assert_equal 302, @response.first
76
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
77
- assert_equal 'http://test.host/users/sign_in', @response.second['Location']
78
- end
79
-
80
- test 'returns to the default redirect location considering subdomain' do
81
- call_failure('warden.options' => { scope: :subdomain_user })
82
- assert_equal 302, @response.first
83
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
84
- assert_equal 'http://sub.test.host/subdomain_users/sign_in', @response.second['Location']
85
- end
86
-
87
- test 'returns to the default redirect location for wildcard requests' do
88
- call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
89
- assert_equal 302, @response.first
90
- assert_equal 'http://test.host/users/sign_in', @response.second['Location']
91
- end
92
-
93
- test 'returns to the root path if no session path is available' do
94
- swap Devise, router_name: :fake_app do
95
- call_failure app: RootFailureApp
96
- assert_equal 302, @response.first
97
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
98
- assert_equal 'http://test.host/', @response.second['Location']
99
- end
100
- end
101
-
102
- test 'returns to the root path considering subdomain if no session path is available' do
103
- swap Devise, router_name: :fake_app do
104
- call_failure app: FailureWithSubdomain
105
- assert_equal 302, @response.first
106
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
107
- assert_equal 'http://sub.test.host/', @response.second['Location']
108
- end
109
- end
110
-
111
- test 'returns to the default redirect location considering the router for supplied scope' do
112
- call_failure app: FakeEngineApp, 'warden.options' => { scope: :user_on_engine }
113
- assert_equal 302, @response.first
114
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
115
- assert_equal 'http://test.host/user_on_engines/sign_in', @response.second['Location']
116
- end
117
-
118
- if Rails.application.config.respond_to?(:relative_url_root)
119
- test 'returns to the default redirect location considering the relative url root' do
120
- swap Rails.application.config, relative_url_root: "/sample" do
121
- call_failure
122
- assert_equal 302, @response.first
123
- assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
124
- end
125
- end
126
-
127
- test 'returns to the default redirect location considering the relative url root and subdomain' do
128
- swap Rails.application.config, relative_url_root: "/sample" do
129
- call_failure('warden.options' => { scope: :subdomain_user })
130
- assert_equal 302, @response.first
131
- assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
132
- end
133
- end
134
- end
135
-
136
- if Rails.application.config.action_controller.respond_to?(:relative_url_root)
137
- test "returns to the default redirect location considering action_controller's relative url root" do
138
- swap Rails.application.config.action_controller, relative_url_root: "/sample" do
139
- call_failure
140
- assert_equal 302, @response.first
141
- assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
142
- end
143
- end
144
-
145
- test "returns to the default redirect location considering action_controller's relative url root and subdomain" do
146
- swap Rails.application.config.action_controller, relative_url_root: "/sample" do
147
- call_failure('warden.options' => { scope: :subdomain_user })
148
- assert_equal 302, @response.first
149
- assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
150
- end
151
- end
152
- end
153
-
154
- test 'uses the proxy failure message as symbol' do
155
- call_failure('warden' => OpenStruct.new(message: :invalid))
156
- assert_equal 'Invalid Email or password.', @request.flash[:alert]
157
- assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
158
- end
159
-
160
- test 'supports authentication_keys as a Hash for the flash message' do
161
- swap Devise, authentication_keys: { email: true, login: true } do
162
- call_failure('warden' => OpenStruct.new(message: :invalid))
163
- assert_equal 'Invalid Email, Login or password.', @request.flash[:alert]
164
- end
165
- end
166
-
167
- test 'uses custom i18n options' do
168
- call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions)
169
- assert_equal 'User Steve does not exist', @request.flash[:alert]
170
- end
171
-
172
- test 'uses the proxy failure message as string' do
173
- call_failure('warden' => OpenStruct.new(message: 'Hello world'))
174
- assert_equal 'Hello world', @request.flash[:alert]
175
- assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
176
- end
177
-
178
- test 'set content type to default text/html' do
179
- call_failure
180
- assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
181
- end
182
-
183
- test 'set up a default message' do
184
- call_failure
185
- assert_match(/You are being/, @response.last.body)
186
- assert_match(/redirected/, @response.last.body)
187
- assert_match(/users\/sign_in/, @response.last.body)
188
- end
189
-
190
- test 'works for any navigational format' do
191
- swap Devise, navigational_formats: [:xml] do
192
- call_failure('formats' => Mime[:xml])
193
- assert_equal 302, @response.first
194
- end
195
- end
196
-
197
- test 'redirects the correct format if it is a non-html format request' do
198
- swap Devise, navigational_formats: [:js] do
199
- call_failure('formats' => Mime[:js])
200
- assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
201
- end
202
- end
203
- end
204
-
205
- context 'For HTTP request' do
206
- test 'return 401 status' do
207
- call_failure('formats' => Mime[:xml])
208
- assert_equal 401, @response.first
209
- end
210
-
211
- test 'return appropriate body for xml' do
212
- call_failure('formats' => Mime[:xml])
213
- result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
214
- assert_equal result, @response.last.body
215
- end
216
-
217
- test 'return appropriate body for json' do
218
- call_failure('formats' => Mime[:json])
219
- result = %({"error":"You need to sign in or sign up before continuing."})
220
- assert_equal result, @response.last.body
221
- end
222
-
223
- test 'return 401 status for unknown formats' do
224
- call_failure 'formats' => []
225
- assert_equal 401, @response.first
226
- end
227
-
228
- test 'return WWW-authenticate headers if model allows' do
229
- call_failure('formats' => Mime[:xml])
230
- assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
231
- end
232
-
233
- test 'does not return WWW-authenticate headers if model does not allow' do
234
- swap Devise, http_authenticatable: false do
235
- call_failure('formats' => Mime[:xml])
236
- assert_nil @response.second["WWW-Authenticate"]
237
- end
238
- end
239
-
240
- test 'works for any non navigational format' do
241
- swap Devise, navigational_formats: [] do
242
- call_failure('formats' => Mime[:html])
243
- assert_equal 401, @response.first
244
- end
245
- end
246
-
247
- test 'uses the failure message as response body' do
248
- call_failure('formats' => Mime[:xml], 'warden' => OpenStruct.new(message: :invalid))
249
- assert_match '<error>Invalid Email or password.</error>', @response.third.body
250
- end
251
-
252
- context 'on ajax call' do
253
- context 'when http_authenticatable_on_xhr is false' do
254
- test 'dont return 401 with navigational formats' do
255
- swap Devise, http_authenticatable_on_xhr: false do
256
- call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
257
- assert_equal 302, @response.first
258
- assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
259
- end
260
- end
261
-
262
- test 'dont return 401 with non navigational formats' do
263
- swap Devise, http_authenticatable_on_xhr: false do
264
- call_failure('formats' => Mime[:json], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
265
- assert_equal 302, @response.first
266
- assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
267
- end
268
- end
269
- end
270
-
271
- context 'when http_authenticatable_on_xhr is true' do
272
- test 'return 401' do
273
- swap Devise, http_authenticatable_on_xhr: true do
274
- call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
275
- assert_equal 401, @response.first
276
- end
277
- end
278
-
279
- test 'skip WWW-Authenticate header' do
280
- swap Devise, http_authenticatable_on_xhr: true do
281
- call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
282
- assert_nil @response.second['WWW-Authenticate']
283
- end
284
- end
285
- end
286
- end
287
- end
288
-
289
- context 'With recall' do
290
- test 'calls the original controller if invalid email or password' do
291
- env = {
292
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" },
293
- "devise.mapping" => Devise.mappings[:user],
294
- "warden" => stub_everything
295
- }
296
- call_failure(env)
297
- assert @response.third.body.include?('<h2>Log in</h2>')
298
- assert @response.third.body.include?('Invalid Email or password.')
299
- end
300
-
301
- test 'calls the original controller if not confirmed email' do
302
- env = {
303
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :unconfirmed },
304
- "devise.mapping" => Devise.mappings[:user],
305
- "warden" => stub_everything
306
- }
307
- call_failure(env)
308
- assert @response.third.body.include?('<h2>Log in</h2>')
309
- assert @response.third.body.include?('You have to confirm your email address before continuing.')
310
- end
311
-
312
- test 'calls the original controller if inactive account' do
313
- env = {
314
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :inactive },
315
- "devise.mapping" => Devise.mappings[:user],
316
- "warden" => stub_everything
317
- }
318
- call_failure(env)
319
- assert @response.third.body.include?('<h2>Log in</h2>')
320
- assert @response.third.body.include?('Your account is not activated yet.')
321
- end
322
-
323
- if Rails.application.config.respond_to?(:relative_url_root)
324
- test 'calls the original controller with the proper environment considering the relative url root' do
325
- swap Rails.application.config, relative_url_root: "/sample" do
326
- env = {
327
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/sample/users/sign_in"},
328
- "devise.mapping" => Devise.mappings[:user],
329
- "warden" => stub_everything
330
- }
331
- call_failure(env)
332
- assert @response.third.body.include?('<h2>Log in</h2>')
333
- assert @response.third.body.include?('Invalid Email or password.')
334
- assert_equal @request.env["SCRIPT_NAME"], '/sample'
335
- assert_equal @request.env["PATH_INFO"], '/users/sign_in'
336
- end
337
- end
338
- end
339
- end
340
-
341
- context "Lazy loading" do
342
- test "loads" do
343
- assert_equal Devise::FailureApp.new.lazy_loading_works?, "yes it does"
344
- end
345
- end
346
- end
@@ -1,130 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- if DEVISE_ORM == :active_record
6
- require "generators/active_record/devise_generator"
7
-
8
- class ActiveRecordGeneratorTest < Rails::Generators::TestCase
9
- tests ActiveRecord::Generators::DeviseGenerator
10
- destination File.expand_path("../../tmp", __FILE__)
11
- setup :prepare_destination
12
-
13
- test "all files are properly created with rails31 migration syntax" do
14
- run_generator %w(monster)
15
- assert_migration "db/migrate/devise_create_monsters.rb", /def change/
16
- end
17
-
18
- test "all files are properly created with changed db/migrate path in application configuration" do
19
- old_paths = Rails.application.config.paths["db/migrate"]
20
- Rails.application.config.paths.add "db/migrate", with: "db2/migrate"
21
-
22
- run_generator %w(monster)
23
- if Rails.version >= '5.0.3'
24
- assert_migration "db2/migrate/devise_create_monsters.rb", /def change/
25
- else
26
- assert_migration "db/migrate/devise_create_monsters.rb", /def change/
27
- end
28
-
29
- Rails.application.config.paths["db/migrate"] = old_paths
30
- end
31
-
32
- test "all files for namespaced model are properly created" do
33
- run_generator %w(admin/monster)
34
- assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/
35
- end
36
-
37
- test "update model migration when model exists" do
38
- run_generator %w(monster)
39
- assert_file "app/models/monster.rb"
40
- run_generator %w(monster)
41
- assert_migration "db/migrate/add_devise_to_monsters.rb"
42
- end
43
-
44
- test "update model migration when model exists with changed db/migrate path in application configuration" do
45
- old_paths = Rails.application.config.paths["db/migrate"]
46
- Rails.application.config.paths.add "db/migrate", with: "db2/migrate"
47
-
48
- run_generator %w(monster)
49
- assert_file "app/models/monster.rb"
50
- run_generator %w(monster)
51
-
52
- if Rails.version >= '5.0.3'
53
- assert_migration "db2/migrate/add_devise_to_monsters.rb"
54
- else
55
- assert_migration "db/migrate/add_devise_to_monsters.rb"
56
- end
57
-
58
- Rails.application.config.paths["db/migrate"] = old_paths
59
- end
60
-
61
- test "all files are properly deleted" do
62
- run_generator %w(monster)
63
- run_generator %w(monster)
64
- assert_migration "db/migrate/devise_create_monsters.rb"
65
- assert_migration "db/migrate/add_devise_to_monsters.rb"
66
- run_generator %w(monster), behavior: :revoke
67
- assert_no_migration "db/migrate/add_devise_to_monsters.rb"
68
- assert_migration "db/migrate/devise_create_monsters.rb"
69
- run_generator %w(monster), behavior: :revoke
70
- assert_no_file "app/models/monster.rb"
71
- assert_no_migration "db/migrate/devise_create_monsters.rb"
72
- end
73
-
74
- test "use string column type for ip addresses" do
75
- run_generator %w(monster)
76
- assert_migration "db/migrate/devise_create_monsters.rb", /t.string :current_sign_in_ip/
77
- assert_migration "db/migrate/devise_create_monsters.rb", /t.string :last_sign_in_ip/
78
- end
79
-
80
- test "do NOT add primary key type when NOT specified in rails generator" do
81
- run_generator %w(monster)
82
- assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters do/
83
- end
84
-
85
- test "add primary key type with rails 5 when specified in rails generator" do
86
- run_generator ["monster", "--primary_key_type=uuid"]
87
- if Rails.version.start_with? '5'
88
- assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters, id: :uuid do/
89
- else
90
- assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters do/
91
- end
92
- end
93
- end
94
-
95
- module RailsEngine
96
- class Engine < Rails::Engine
97
- isolate_namespace RailsEngine
98
- end
99
- end
100
-
101
- def simulate_inside_engine(engine, namespace)
102
- if Rails::Generators.respond_to?(:namespace=)
103
- swap Rails::Generators, namespace: namespace do
104
- yield
105
- end
106
- else
107
- swap Rails, application: engine.instance do
108
- yield
109
- end
110
- end
111
- end
112
-
113
- class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase
114
- tests ActiveRecord::Generators::DeviseGenerator
115
- destination File.expand_path("../../tmp", __FILE__)
116
- setup :prepare_destination
117
-
118
- test "all files are properly created in rails 4.0" do
119
- simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
120
- run_generator ["monster"]
121
-
122
- assert_file "app/models/rails_engine/monster.rb", /devise/
123
- assert_file "app/models/rails_engine/monster.rb" do |content|
124
- assert_no_match %r{attr_accessible :email}, content
125
- end
126
- end
127
- end
128
-
129
- end
130
- end