devise 3.2.0 → 3.3.0
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.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +18 -3
- data/CHANGELOG.md +82 -9
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +7 -9
- data/Gemfile.lock +102 -96
- data/MIT-LICENSE +1 -1
- data/README.md +94 -42
- data/Rakefile +1 -1
- data/app/controllers/devise/confirmations_controller.rb +5 -3
- data/app/controllers/devise/omniauth_callbacks_controller.rb +2 -2
- data/app/controllers/devise/passwords_controller.rb +5 -3
- data/app/controllers/devise/registrations_controller.rb +26 -10
- data/app/controllers/devise/sessions_controller.rb +39 -14
- data/app/controllers/devise/unlocks_controller.rb +4 -2
- data/app/controllers/devise_controller.rb +6 -6
- data/app/helpers/devise_helper.rb +2 -2
- data/app/views/devise/confirmations/new.html.erb +2 -2
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +3 -3
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/edit.html.erb +6 -6
- data/app/views/devise/registrations/new.html.erb +5 -5
- data/app/views/devise/sessions/new.html.erb +5 -5
- data/app/views/devise/shared/_links.erb +1 -1
- data/app/views/devise/unlocks/new.html.erb +2 -2
- data/config/locales/en.yml +17 -16
- data/devise.gemspec +2 -2
- data/gemfiles/{Gemfile.rails-3.2.x → Gemfile.rails-3.2-stable} +8 -10
- data/gemfiles/Gemfile.rails-3.2-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.0-stable +29 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +162 -0
- data/gemfiles/Gemfile.rails-head +32 -0
- data/gemfiles/Gemfile.rails-head.lock +190 -0
- data/lib/devise/controllers/helpers.rb +84 -29
- data/lib/devise/controllers/rememberable.rb +3 -3
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +9 -10
- data/lib/devise/controllers/store_location.rb +56 -0
- data/lib/devise/controllers/url_helpers.rb +3 -1
- data/lib/devise/failure_app.rb +12 -10
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +3 -1
- data/lib/devise/hooks/lockable.rb +1 -1
- data/lib/devise/hooks/proxy.rb +2 -2
- data/lib/devise/hooks/rememberable.rb +2 -2
- data/lib/devise/hooks/timeoutable.rb +10 -3
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +8 -8
- data/lib/devise/mapping.rb +4 -1
- data/lib/devise/models/authenticatable.rb +5 -5
- data/lib/devise/models/confirmable.rb +14 -14
- data/lib/devise/models/database_authenticatable.rb +18 -5
- data/lib/devise/models/lockable.rb +14 -11
- data/lib/devise/models/omniauthable.rb +1 -1
- data/lib/devise/models/recoverable.rb +23 -7
- data/lib/devise/models/rememberable.rb +6 -6
- data/lib/devise/models/timeoutable.rb +2 -2
- data/lib/devise/models/trackable.rb +5 -2
- data/lib/devise/models/validatable.rb +6 -6
- data/lib/devise/modules.rb +10 -10
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/rails/routes.rb +107 -78
- data/lib/devise/rails.rb +7 -1
- data/lib/devise/strategies/authenticatable.rb +11 -4
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +7 -4
- data/lib/devise/test_helpers.rb +2 -2
- data/lib/devise/time_inflector.rb +2 -2
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +15 -10
- data/lib/generators/active_record/devise_generator.rb +27 -10
- data/lib/generators/active_record/templates/migration.rb +4 -4
- data/lib/generators/active_record/templates/migration_existing.rb +4 -4
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/views_generator.rb +31 -18
- data/lib/generators/mongoid/devise_generator.rb +20 -19
- data/lib/generators/templates/README +4 -4
- data/lib/generators/templates/devise.rb +20 -11
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +2 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +35 -0
- data/test/controllers/helpers_test.rb +89 -31
- data/test/controllers/internal_helpers_test.rb +11 -8
- data/test/controllers/passwords_controller_test.rb +1 -1
- data/test/controllers/sessions_controller_test.rb +29 -25
- data/test/controllers/url_helpers_test.rb +4 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +21 -8
- data/test/failure_app_test.rb +61 -25
- data/test/generators/active_record_generator_test.rb +10 -4
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +30 -1
- data/test/helpers/devise_helper_test.rb +14 -13
- data/test/integration/authenticatable_test.rb +61 -45
- data/test/integration/confirmable_test.rb +95 -55
- data/test/integration/database_authenticatable_test.rb +16 -16
- data/test/integration/http_authenticatable_test.rb +12 -12
- data/test/integration/lockable_test.rb +43 -43
- data/test/integration/omniauthable_test.rb +3 -3
- data/test/integration/recoverable_test.rb +53 -53
- data/test/integration/registerable_test.rb +90 -80
- data/test/integration/rememberable_test.rb +15 -15
- data/test/integration/timeoutable_test.rb +27 -16
- data/test/integration/trackable_test.rb +4 -4
- data/test/mailers/confirmation_instructions_test.rb +7 -7
- data/test/mailers/reset_password_instructions_test.rb +6 -6
- data/test/mailers/unlock_instructions_test.rb +5 -5
- data/test/mapping_test.rb +3 -3
- data/test/models/authenticatable_test.rb +3 -3
- data/test/models/confirmable_test.rb +32 -32
- data/test/models/database_authenticatable_test.rb +32 -27
- data/test/models/lockable_test.rb +57 -33
- data/test/models/recoverable_test.rb +34 -22
- data/test/models/rememberable_test.rb +29 -14
- data/test/models/serializable_test.rb +8 -8
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +13 -13
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +3 -3
- data/test/orm/mongoid.rb +1 -1
- data/test/parameter_sanitizer_test.rb +1 -1
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +1 -1
- data/test/rails_app/app/controllers/application_controller.rb +5 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +6 -6
- data/test/rails_app/app/mailers/users/mailer.rb +4 -4
- data/test/rails_app/app/mongoid/admin.rb +11 -11
- data/test/rails_app/app/mongoid/shim.rb +2 -2
- data/test/rails_app/app/mongoid/user.rb +19 -19
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/config/application.rb +2 -2
- data/test/rails_app/config/boot.rb +7 -1
- data/test/rails_app/config/environments/development.rb +0 -4
- data/test/rails_app/config/environments/production.rb +0 -4
- data/test/rails_app/config/initializers/devise.rb +7 -5
- data/test/rails_app/config/initializers/secret_token.rb +1 -1
- data/test/rails_app/config/routes.rb +60 -42
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +7 -7
- data/test/rails_app/db/schema.rb +21 -17
- data/test/rails_app/lib/shared_admin.rb +4 -4
- data/test/rails_app/lib/shared_user.rb +1 -1
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/routes_test.rb +72 -58
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +4 -4
- data/test/support/integration.rb +14 -14
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +2 -7
- data/test/test_helpers_test.rb +25 -35
- data/test/test_models.rb +12 -5
- metadata +53 -38
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
data/test/failure_app_test.rb
CHANGED
@@ -8,9 +8,21 @@ class FailureTest < ActiveSupport::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
class FailureWithSubdomain < RootFailureApp
|
12
|
+
routes = ActionDispatch::Routing::RouteSet.new
|
13
|
+
|
14
|
+
routes.draw do
|
15
|
+
scope subdomain: 'sub' do
|
16
|
+
root to: 'foo#bar'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
include routes.url_helpers
|
21
|
+
end
|
22
|
+
|
11
23
|
class FailureWithI18nOptions < Devise::FailureApp
|
12
24
|
def i18n_options(options)
|
13
|
-
options.merge(:
|
25
|
+
options.merge(name: 'Steve')
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
@@ -23,11 +35,11 @@ class FailureTest < ActiveSupport::TestCase
|
|
23
35
|
'REQUEST_URI' => 'http://test.host/',
|
24
36
|
'HTTP_HOST' => 'test.host',
|
25
37
|
'REQUEST_METHOD' => 'GET',
|
26
|
-
'warden.options' => { :
|
38
|
+
'warden.options' => { scope: :user },
|
27
39
|
'rack.session' => {},
|
28
40
|
'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML),
|
29
41
|
'rack.input' => "",
|
30
|
-
'warden' => OpenStruct.new(:
|
42
|
+
'warden' => OpenStruct.new(message: nil)
|
31
43
|
}.merge!(env_params)
|
32
44
|
|
33
45
|
@response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
|
@@ -42,6 +54,13 @@ class FailureTest < ActiveSupport::TestCase
|
|
42
54
|
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
|
43
55
|
end
|
44
56
|
|
57
|
+
test 'returns to the default redirect location considering subdomain' do
|
58
|
+
call_failure('warden.options' => { scope: :subdomain_user })
|
59
|
+
assert_equal 302, @response.first
|
60
|
+
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
61
|
+
assert_equal 'http://sub.test.host/subdomain_users/sign_in', @response.second['Location']
|
62
|
+
end
|
63
|
+
|
45
64
|
test 'returns to the default redirect location for wildcard requests' do
|
46
65
|
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
|
47
66
|
assert_equal 302, @response.first
|
@@ -49,37 +68,54 @@ class FailureTest < ActiveSupport::TestCase
|
|
49
68
|
end
|
50
69
|
|
51
70
|
test 'returns to the root path if no session path is available' do
|
52
|
-
swap Devise, :
|
53
|
-
call_failure :
|
71
|
+
swap Devise, router_name: :fake_app do
|
72
|
+
call_failure app: RootFailureApp
|
54
73
|
assert_equal 302, @response.first
|
55
74
|
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
56
75
|
assert_equal 'http://test.host/', @response.second['Location']
|
57
76
|
end
|
58
77
|
end
|
59
78
|
|
79
|
+
test 'returns to the root path considering subdomain if no session path is available' do
|
80
|
+
swap Devise, router_name: :fake_app do
|
81
|
+
call_failure app: FailureWithSubdomain
|
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/', @response.second['Location']
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
60
88
|
if Rails.application.config.respond_to?(:relative_url_root)
|
61
89
|
test 'returns to the default redirect location considering the relative url root' do
|
62
|
-
swap Rails.application.config, :
|
90
|
+
swap Rails.application.config, relative_url_root: "/sample" do
|
63
91
|
call_failure
|
64
92
|
assert_equal 302, @response.first
|
65
93
|
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
|
66
94
|
end
|
67
95
|
end
|
96
|
+
|
97
|
+
test 'returns to the default redirect location considering the relative url root and subdomain' do
|
98
|
+
swap Rails.application.config, relative_url_root: "/sample" do
|
99
|
+
call_failure('warden.options' => { scope: :subdomain_user })
|
100
|
+
assert_equal 302, @response.first
|
101
|
+
assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
|
102
|
+
end
|
103
|
+
end
|
68
104
|
end
|
69
105
|
|
70
106
|
test 'uses the proxy failure message as symbol' do
|
71
|
-
call_failure('warden' => OpenStruct.new(:
|
107
|
+
call_failure('warden' => OpenStruct.new(message: :invalid))
|
72
108
|
assert_equal 'Invalid email or password.', @request.flash[:alert]
|
73
109
|
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
74
110
|
end
|
75
111
|
|
76
112
|
test 'uses custom i18n options' do
|
77
|
-
call_failure('warden' => OpenStruct.new(:
|
113
|
+
call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions)
|
78
114
|
assert_equal 'User Steve does not exist', @request.flash[:alert]
|
79
115
|
end
|
80
116
|
|
81
117
|
test 'uses the proxy failure message as string' do
|
82
|
-
call_failure('warden' => OpenStruct.new(:
|
118
|
+
call_failure('warden' => OpenStruct.new(message: 'Hello world'))
|
83
119
|
assert_equal 'Hello world', @request.flash[:alert]
|
84
120
|
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
85
121
|
end
|
@@ -97,14 +133,14 @@ class FailureTest < ActiveSupport::TestCase
|
|
97
133
|
end
|
98
134
|
|
99
135
|
test 'works for any navigational format' do
|
100
|
-
swap Devise, :
|
136
|
+
swap Devise, navigational_formats: [:xml] do
|
101
137
|
call_failure('formats' => Mime::XML)
|
102
138
|
assert_equal 302, @response.first
|
103
139
|
end
|
104
140
|
end
|
105
141
|
|
106
142
|
test 'redirects the correct format if it is a non-html format request' do
|
107
|
-
swap Devise, :
|
143
|
+
swap Devise, navigational_formats: [:js] do
|
108
144
|
call_failure('formats' => Mime::JS)
|
109
145
|
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
|
110
146
|
end
|
@@ -140,28 +176,28 @@ class FailureTest < ActiveSupport::TestCase
|
|
140
176
|
end
|
141
177
|
|
142
178
|
test 'does not return WWW-authenticate headers if model does not allow' do
|
143
|
-
swap Devise, :
|
179
|
+
swap Devise, http_authenticatable: false do
|
144
180
|
call_failure('formats' => Mime::XML)
|
145
181
|
assert_nil @response.second["WWW-Authenticate"]
|
146
182
|
end
|
147
183
|
end
|
148
184
|
|
149
185
|
test 'works for any non navigational format' do
|
150
|
-
swap Devise, :
|
186
|
+
swap Devise, navigational_formats: [] do
|
151
187
|
call_failure('formats' => Mime::HTML)
|
152
188
|
assert_equal 401, @response.first
|
153
189
|
end
|
154
190
|
end
|
155
191
|
|
156
192
|
test 'uses the failure message as response body' do
|
157
|
-
call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(:
|
193
|
+
call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(message: :invalid))
|
158
194
|
assert_match '<error>Invalid email or password.</error>', @response.third.body
|
159
195
|
end
|
160
196
|
|
161
197
|
context 'on ajax call' do
|
162
198
|
context 'when http_authenticatable_on_xhr is false' do
|
163
199
|
test 'dont return 401 with navigational formats' do
|
164
|
-
swap Devise, :
|
200
|
+
swap Devise, http_authenticatable_on_xhr: false do
|
165
201
|
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
166
202
|
assert_equal 302, @response.first
|
167
203
|
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
@@ -169,7 +205,7 @@ class FailureTest < ActiveSupport::TestCase
|
|
169
205
|
end
|
170
206
|
|
171
207
|
test 'dont return 401 with non navigational formats' do
|
172
|
-
swap Devise, :
|
208
|
+
swap Devise, http_authenticatable_on_xhr: false do
|
173
209
|
call_failure('formats' => Mime::JSON, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
174
210
|
assert_equal 302, @response.first
|
175
211
|
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
|
@@ -179,14 +215,14 @@ class FailureTest < ActiveSupport::TestCase
|
|
179
215
|
|
180
216
|
context 'when http_authenticatable_on_xhr is true' do
|
181
217
|
test 'return 401' do
|
182
|
-
swap Devise, :
|
218
|
+
swap Devise, http_authenticatable_on_xhr: true do
|
183
219
|
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
184
220
|
assert_equal 401, @response.first
|
185
221
|
end
|
186
222
|
end
|
187
223
|
|
188
224
|
test 'skip WWW-Authenticate header' do
|
189
|
-
swap Devise, :
|
225
|
+
swap Devise, http_authenticatable_on_xhr: true do
|
190
226
|
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
191
227
|
assert_nil @response.second['WWW-Authenticate']
|
192
228
|
end
|
@@ -198,34 +234,34 @@ class FailureTest < ActiveSupport::TestCase
|
|
198
234
|
context 'With recall' do
|
199
235
|
test 'calls the original controller if invalid email or password' do
|
200
236
|
env = {
|
201
|
-
"warden.options" => { :
|
237
|
+
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" },
|
202
238
|
"devise.mapping" => Devise.mappings[:user],
|
203
239
|
"warden" => stub_everything
|
204
240
|
}
|
205
241
|
call_failure(env)
|
206
|
-
assert @response.third.body.include?('<h2>
|
242
|
+
assert @response.third.body.include?('<h2>Log in</h2>')
|
207
243
|
assert @response.third.body.include?('Invalid email or password.')
|
208
244
|
end
|
209
245
|
|
210
246
|
test 'calls the original controller if not confirmed email' do
|
211
247
|
env = {
|
212
|
-
"warden.options" => { :
|
248
|
+
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :unconfirmed },
|
213
249
|
"devise.mapping" => Devise.mappings[:user],
|
214
250
|
"warden" => stub_everything
|
215
251
|
}
|
216
252
|
call_failure(env)
|
217
|
-
assert @response.third.body.include?('<h2>
|
218
|
-
assert @response.third.body.include?('You have to confirm your
|
253
|
+
assert @response.third.body.include?('<h2>Log in</h2>')
|
254
|
+
assert @response.third.body.include?('You have to confirm your email address before continuing.')
|
219
255
|
end
|
220
256
|
|
221
257
|
test 'calls the original controller if inactive account' do
|
222
258
|
env = {
|
223
|
-
"warden.options" => { :
|
259
|
+
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :inactive },
|
224
260
|
"devise.mapping" => Devise.mappings[:user],
|
225
261
|
"warden" => stub_everything
|
226
262
|
}
|
227
263
|
call_failure(env)
|
228
|
-
assert @response.third.body.include?('<h2>
|
264
|
+
assert @response.third.body.include?('<h2>Log in</h2>')
|
229
265
|
assert @response.third.body.include?('Your account is not activated yet.')
|
230
266
|
end
|
231
267
|
end
|
@@ -30,13 +30,19 @@ if DEVISE_ORM == :active_record
|
|
30
30
|
run_generator %w(monster)
|
31
31
|
assert_migration "db/migrate/devise_create_monsters.rb"
|
32
32
|
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
33
|
-
run_generator %w(monster), :
|
33
|
+
run_generator %w(monster), behavior: :revoke
|
34
34
|
assert_no_migration "db/migrate/add_devise_to_monsters.rb"
|
35
35
|
assert_migration "db/migrate/devise_create_monsters.rb"
|
36
|
-
run_generator %w(monster), :
|
36
|
+
run_generator %w(monster), behavior: :revoke
|
37
37
|
assert_no_file "app/models/monster.rb"
|
38
38
|
assert_no_migration "db/migrate/devise_create_monsters.rb"
|
39
39
|
end
|
40
|
+
|
41
|
+
test "use string column type for ip addresses" do
|
42
|
+
run_generator %w(monster)
|
43
|
+
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :current_sign_in_ip/
|
44
|
+
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :last_sign_in_ip/
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
module RailsEngine
|
@@ -47,11 +53,11 @@ if DEVISE_ORM == :active_record
|
|
47
53
|
|
48
54
|
def simulate_inside_engine(engine, namespace)
|
49
55
|
if Rails::Generators.respond_to?(:namespace=)
|
50
|
-
swap Rails::Generators, :
|
56
|
+
swap Rails::Generators, namespace: namespace do
|
51
57
|
yield
|
52
58
|
end
|
53
59
|
else
|
54
|
-
swap Rails, :
|
60
|
+
swap Rails, application: engine.instance do
|
55
61
|
yield
|
56
62
|
end
|
57
63
|
end
|
@@ -18,13 +18,13 @@ class DeviseGeneratorTest < Rails::Generators::TestCase
|
|
18
18
|
|
19
19
|
test "route generation for namespaced model names" do
|
20
20
|
run_generator %w(monster/goblin name:string)
|
21
|
-
match = /devise_for :goblins, :
|
21
|
+
match = /devise_for :goblins, class_name: "Monster::Goblin"/
|
22
22
|
assert_file "config/routes.rb", match
|
23
23
|
end
|
24
24
|
|
25
25
|
test "route generation with skip routes" do
|
26
26
|
run_generator %w(monster name:string --skip-routes)
|
27
|
-
match = /devise_for :monsters, :
|
27
|
+
match = /devise_for :monsters, skip: :all/
|
28
28
|
assert_file "config/routes.rb", match
|
29
29
|
end
|
30
30
|
|
@@ -7,15 +7,15 @@ if DEVISE_ORM == :mongoid
|
|
7
7
|
tests Mongoid::Generators::DeviseGenerator
|
8
8
|
destination File.expand_path("../../tmp", __FILE__)
|
9
9
|
setup :prepare_destination
|
10
|
-
|
10
|
+
|
11
11
|
test "all files are properly created" do
|
12
12
|
run_generator %w(monster)
|
13
13
|
assert_file "app/models/monster.rb", /devise/
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
test "all files are properly deleted" do
|
17
17
|
run_generator %w(monster)
|
18
|
-
run_generator %w(monster), :
|
18
|
+
run_generator %w(monster), behavior: :revoke
|
19
19
|
assert_no_file "app/models/monster.rb"
|
20
20
|
end
|
21
21
|
end
|
@@ -33,7 +33,36 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
|
|
33
33
|
|
34
34
|
test "Assert views with markerb" do
|
35
35
|
run_generator %w(--markerb)
|
36
|
-
assert_files nil, :
|
36
|
+
assert_files nil, mail_template_engine: "markerb"
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
test "Assert only views within specified directories" do
|
41
|
+
run_generator %w(-v sessions registrations)
|
42
|
+
assert_file "app/views/devise/sessions/new.html.erb"
|
43
|
+
assert_file "app/views/devise/registrations/new.html.erb"
|
44
|
+
assert_file "app/views/devise/registrations/edit.html.erb"
|
45
|
+
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
46
|
+
assert_no_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
47
|
+
end
|
48
|
+
|
49
|
+
test "Assert specified directories with scope" do
|
50
|
+
run_generator %w(users -v sessions)
|
51
|
+
assert_file "app/views/users/sessions/new.html.erb"
|
52
|
+
assert_no_file "app/views/users/confirmations/new.html.erb"
|
53
|
+
end
|
54
|
+
|
55
|
+
test "Assert specified directories with simple form" do
|
56
|
+
run_generator %w(-v registrations -b simple_form_for)
|
57
|
+
assert_file "app/views/devise/registrations/new.html.erb", /simple_form_for/
|
58
|
+
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
59
|
+
end
|
60
|
+
|
61
|
+
test "Assert specified directories with markerb" do
|
62
|
+
run_generator %w(--markerb -v passwords mailer)
|
63
|
+
assert_file "app/views/devise/passwords/new.html.erb"
|
64
|
+
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
65
|
+
assert_file "app/views/devise/mailer/reset_password_instructions.markerb"
|
37
66
|
end
|
38
67
|
|
39
68
|
def assert_files(scope = nil, options={})
|
@@ -2,16 +2,18 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class DeviseHelperTest < ActionDispatch::IntegrationTest
|
4
4
|
setup do
|
5
|
-
model_labels = { :
|
6
|
-
|
5
|
+
model_labels = { models: { user: "utilisateur" } }
|
6
|
+
# TODO: Remove this hack that fixes the I18n performance safeguards that
|
7
|
+
# breaks the custom locale.
|
8
|
+
I18n.available_locales += [:fr]
|
7
9
|
I18n.backend.store_translations :fr,
|
8
10
|
{
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
11
|
+
errors: { messages: { not_saved: {
|
12
|
+
one: "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
|
13
|
+
other: "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
|
12
14
|
} } },
|
13
|
-
:
|
14
|
-
:
|
15
|
+
activerecord: model_labels,
|
16
|
+
mongoid: model_labels
|
15
17
|
}
|
16
18
|
|
17
19
|
I18n.locale = 'fr'
|
@@ -24,8 +26,8 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest
|
|
24
26
|
test 'test errors.messages.not_saved with single error from i18n' do
|
25
27
|
get new_user_registration_path
|
26
28
|
|
27
|
-
fill_in 'password', :
|
28
|
-
fill_in 'password confirmation', :
|
29
|
+
fill_in 'password', with: 'new_user123'
|
30
|
+
fill_in 'password confirmation', with: 'new_user123'
|
29
31
|
click_button 'Sign up'
|
30
32
|
|
31
33
|
assert_have_selector '#error_explanation'
|
@@ -39,13 +41,12 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest
|
|
39
41
|
|
40
42
|
get new_user_registration_path
|
41
43
|
|
42
|
-
fill_in 'email', :
|
43
|
-
fill_in 'password', :
|
44
|
-
fill_in 'password confirmation', :
|
44
|
+
fill_in 'email', with: 'invalid_email'
|
45
|
+
fill_in 'password', with: 'new_user123'
|
46
|
+
fill_in 'password confirmation', with: 'new_user321'
|
45
47
|
click_button 'Sign up'
|
46
48
|
|
47
49
|
assert_have_selector '#error_explanation'
|
48
50
|
assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 2 erreurs"
|
49
51
|
end
|
50
52
|
end
|
51
|
-
|