devise 3.4.1 → 3.5.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.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +26 -16
- data/CHANGELOG.md +131 -104
- data/Gemfile +1 -1
- data/Gemfile.lock +84 -85
- data/MIT-LICENSE +1 -1
- data/README.md +52 -32
- data/Rakefile +2 -1
- data/app/controllers/devise/confirmations_controller.rb +4 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +4 -0
- data/app/controllers/devise/passwords_controller.rb +14 -4
- data/app/controllers/devise/registrations_controller.rb +10 -11
- data/app/controllers/devise/sessions_controller.rb +7 -2
- data/app/controllers/devise/unlocks_controller.rb +3 -0
- data/app/controllers/devise_controller.rb +34 -18
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +3 -0
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/gemfiles/Gemfile.rails-3.2-stable.lock +43 -43
- data/gemfiles/Gemfile.rails-4.0-stable.lock +45 -47
- data/gemfiles/Gemfile.rails-4.1-stable.lock +52 -53
- data/gemfiles/Gemfile.rails-4.2-stable +29 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +191 -0
- data/lib/devise.rb +23 -28
- data/lib/devise/controllers/rememberable.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +1 -1
- data/lib/devise/controllers/store_location.rb +3 -1
- data/lib/devise/controllers/url_helpers.rb +7 -9
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +26 -10
- data/lib/devise/mapping.rb +1 -0
- data/lib/devise/models/authenticatable.rb +20 -26
- data/lib/devise/models/confirmable.rb +29 -7
- data/lib/devise/models/database_authenticatable.rb +6 -9
- data/lib/devise/models/recoverable.rb +22 -10
- data/lib/devise/models/rememberable.rb +16 -3
- data/lib/devise/models/trackable.rb +1 -2
- data/lib/devise/models/validatable.rb +3 -3
- data/lib/devise/rails.rb +1 -1
- data/lib/devise/rails/routes.rb +3 -3
- data/lib/devise/strategies/authenticatable.rb +5 -2
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +10 -0
- data/lib/devise/test_helpers.rb +2 -2
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -1
- data/lib/generators/active_record/templates/migration_existing.rb +1 -1
- data/lib/generators/templates/controllers/README +1 -1
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
- data/lib/generators/templates/controllers/registrations_controller.rb +2 -2
- data/lib/generators/templates/controllers/sessions_controller.rb +1 -1
- data/lib/generators/templates/devise.rb +14 -8
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- data/test/controllers/custom_registrations_controller_test.rb +6 -1
- data/test/controllers/helpers_test.rb +5 -0
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +4 -4
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +1 -1
- data/test/controllers/sessions_controller_test.rb +3 -3
- data/test/devise_test.rb +2 -2
- data/test/failure_app_test.rb +23 -0
- data/test/integration/database_authenticatable_test.rb +11 -0
- data/test/integration/omniauthable_test.rb +1 -1
- data/test/integration/recoverable_test.rb +13 -0
- data/test/integration/rememberable_test.rb +9 -0
- data/test/mapping_test.rb +6 -0
- data/test/models/confirmable_test.rb +47 -34
- data/test/models/lockable_test.rb +6 -6
- data/test/models/recoverable_test.rb +39 -7
- data/test/models/rememberable_test.rb +8 -2
- data/test/models/validatable_test.rb +5 -5
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +10 -0
- data/test/rails_app/config/application.rb +1 -1
- data/test/rails_app/config/environments/production.rb +6 -2
- data/test/rails_app/config/environments/test.rb +7 -2
- data/test/rails_app/config/initializers/devise.rb +12 -15
- data/test/rails_app/lib/shared_user.rb +1 -1
- data/test/rails_test.rb +9 -0
- data/test/support/integration.rb +2 -2
- data/test/test_helpers_test.rb +22 -7
- data/test/test_models.rb +2 -2
- metadata +11 -2
@@ -46,7 +46,7 @@ module Devise
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Generate a new remember token and save the record without validations
|
49
|
-
#
|
49
|
+
# if remember expired (token is no longer valid) or extend_remember_period is true
|
50
50
|
def remember_me!(extend_period=false)
|
51
51
|
self.remember_token = self.class.remember_token if generate_remember_token?
|
52
52
|
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
|
@@ -75,7 +75,7 @@ module Devise
|
|
75
75
|
def rememberable_value
|
76
76
|
if respond_to?(:remember_token)
|
77
77
|
remember_token
|
78
|
-
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt)
|
78
|
+
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt.presence)
|
79
79
|
salt
|
80
80
|
else
|
81
81
|
raise "authenticable_salt returned nil for the #{self.class.name} model. " \
|
@@ -89,6 +89,19 @@ module Devise
|
|
89
89
|
self.class.rememberable_options
|
90
90
|
end
|
91
91
|
|
92
|
+
# A callback initiated after successfully being remembered. This can be
|
93
|
+
# used to insert your own logic that is only run after the user is
|
94
|
+
# remembered.
|
95
|
+
#
|
96
|
+
# Example:
|
97
|
+
#
|
98
|
+
# def after_remembered
|
99
|
+
# self.update_attribute(:invite_code, nil)
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
def after_remembered
|
103
|
+
end
|
104
|
+
|
92
105
|
protected
|
93
106
|
|
94
107
|
def generate_remember_token? #:nodoc:
|
@@ -98,7 +111,7 @@ module Devise
|
|
98
111
|
# Generate a timestamp if extend_remember_period is true, if no remember_token
|
99
112
|
# exists, or if an existing remember token has expired.
|
100
113
|
def generate_remember_timestamp?(extend_period) #:nodoc:
|
101
|
-
extend_period ||
|
114
|
+
extend_period || remember_expired?
|
102
115
|
end
|
103
116
|
|
104
117
|
module ClassMethods
|
@@ -30,8 +30,7 @@ module Devise
|
|
30
30
|
|
31
31
|
def update_tracked_fields!(request)
|
32
32
|
update_tracked_fields(request)
|
33
|
-
save(validate: false)
|
34
|
-
"Please make sure a model using trackable can be saved at sign in."
|
33
|
+
save(validate: false)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -10,12 +10,12 @@ module Devise
|
|
10
10
|
# Validatable adds the following options to devise_for:
|
11
11
|
#
|
12
12
|
# * +email_regexp+: the regular expression used to validate e-mails;
|
13
|
-
# * +password_length+: a range expressing password length. Defaults to 8..
|
13
|
+
# * +password_length+: a range expressing password length. Defaults to 8..72.
|
14
14
|
#
|
15
15
|
module Validatable
|
16
16
|
# All validations used by this module.
|
17
|
-
VALIDATIONS = [
|
18
|
-
|
17
|
+
VALIDATIONS = [:validates_presence_of, :validates_uniqueness_of, :validates_format_of,
|
18
|
+
:validates_confirmation_of, :validates_length_of].freeze
|
19
19
|
|
20
20
|
def self.required_fields(klass)
|
21
21
|
[]
|
data/lib/devise/rails.rb
CHANGED
@@ -17,7 +17,7 @@ module Devise
|
|
17
17
|
Devise.include_helpers(Devise::Controllers)
|
18
18
|
end
|
19
19
|
|
20
|
-
initializer "devise.omniauth" do |app|
|
20
|
+
initializer "devise.omniauth", after: :load_config_initializers, before: :build_middleware_stack do |app|
|
21
21
|
Devise.omniauth_configs.each do |provider, config|
|
22
22
|
app.middleware.use config.strategy_class, *config.args do |strategy|
|
23
23
|
config.strategy = strategy
|
data/lib/devise/rails/routes.rb
CHANGED
@@ -119,7 +119,7 @@ module ActionDispatch::Routing
|
|
119
119
|
# * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :get),
|
120
120
|
# if you wish to restrict this to accept only :post or :delete requests you should do:
|
121
121
|
#
|
122
|
-
# devise_for :users, sign_out_via: [
|
122
|
+
# devise_for :users, sign_out_via: [:post, :delete]
|
123
123
|
#
|
124
124
|
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
125
125
|
#
|
@@ -402,7 +402,7 @@ module ActionDispatch::Routing
|
|
402
402
|
def devise_omniauth_callback(mapping, controllers) #:nodoc:
|
403
403
|
if mapping.fullpath =~ /:[a-zA-Z_]/
|
404
404
|
raise <<-ERROR
|
405
|
-
Devise does not support scoping
|
405
|
+
Devise does not support scoping OmniAuth callbacks under a dynamic segment
|
406
406
|
and you have set #{mapping.fullpath.inspect}. You can work around by passing
|
407
407
|
`skip: :omniauth_callbacks` and manually defining the routes. Here is an example:
|
408
408
|
|
@@ -414,7 +414,7 @@ and you have set #{mapping.fullpath.inspect}. You can work around by passing
|
|
414
414
|
|
415
415
|
match "/users/auth/:action/callback",
|
416
416
|
constraints: { action: /google|facebook/ },
|
417
|
-
to: "devise/omniauth_callbacks",
|
417
|
+
to: "devise/omniauth_callbacks#:action",
|
418
418
|
as: :omniauth_callback,
|
419
419
|
via: [:get, :post]
|
420
420
|
ERROR
|
@@ -57,7 +57,7 @@ module Devise
|
|
57
57
|
|
58
58
|
# Check if this is a valid strategy for http authentication by:
|
59
59
|
#
|
60
|
-
# * Validating if the model allows
|
60
|
+
# * Validating if the model allows http authentication;
|
61
61
|
# * If any of the authorization headers were sent;
|
62
62
|
# * If all authentication keys are present;
|
63
63
|
#
|
@@ -108,7 +108,10 @@ module Devise
|
|
108
108
|
params_auth_hash.is_a?(Hash)
|
109
109
|
end
|
110
110
|
|
111
|
-
#
|
111
|
+
# Note: unlike `Model.valid_password?`, this method does not actually
|
112
|
+
# ensure that the password in the params matches the password stored in
|
113
|
+
# the database. It only checks if the password is *present*. Do not rely
|
114
|
+
# on this method for validating that a given password is correct.
|
112
115
|
def valid_password?
|
113
116
|
password.present?
|
114
117
|
end
|
@@ -5,7 +5,7 @@ module Devise
|
|
5
5
|
# Default strategy for signing in a user, based on their email and password in the database.
|
6
6
|
class DatabaseAuthenticatable < Authenticatable
|
7
7
|
def authenticate!
|
8
|
-
resource =
|
8
|
+
resource = password.present? && mapping.to.find_for_database_authentication(authentication_hash)
|
9
9
|
encrypted = false
|
10
10
|
|
11
11
|
if validate(resource){ encrypted = true; resource.valid_password?(password) }
|
@@ -27,10 +27,20 @@ module Devise
|
|
27
27
|
if validate(resource)
|
28
28
|
remember_me(resource)
|
29
29
|
extend_remember_me_period(resource)
|
30
|
+
resource.after_remembered
|
30
31
|
success!(resource)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
# No need to clean up the CSRF when using rememberable.
|
36
|
+
# In fact, cleaning it up here would be a bug because
|
37
|
+
# rememberable is triggered on GET requests which means
|
38
|
+
# we would render a page on first access with all csrf
|
39
|
+
# tokens expired.
|
40
|
+
def clean_up_csrf?
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
34
44
|
private
|
35
45
|
|
36
46
|
def extend_remember_me_period(resource)
|
data/lib/devise/test_helpers.rb
CHANGED
@@ -26,11 +26,11 @@ module Devise
|
|
26
26
|
|
27
27
|
# Quick access to Warden::Proxy.
|
28
28
|
def warden #:nodoc:
|
29
|
-
@warden ||= begin
|
29
|
+
@request.env['warden'] ||= begin
|
30
30
|
manager = Warden::Manager.new(nil) do |config|
|
31
31
|
config.merge! Devise.warden_config
|
32
32
|
end
|
33
|
-
|
33
|
+
Warden::Proxy.new(@request.env, manager)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/lib/devise/version.rb
CHANGED
@@ -8,7 +8,7 @@ class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
8
8
|
<% end -%>
|
9
9
|
|
10
10
|
# Uncomment below if timestamps were not included in your original model.
|
11
|
-
# t.timestamps
|
11
|
+
# t.timestamps null: false
|
12
12
|
end
|
13
13
|
|
14
14
|
add_index :<%= table_name %>, :email, unique: true
|
@@ -38,12 +38,12 @@ class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsControl
|
|
38
38
|
|
39
39
|
# protected
|
40
40
|
|
41
|
-
#
|
41
|
+
# If you have extra params to permit, append them to the sanitizer.
|
42
42
|
# def configure_sign_up_params
|
43
43
|
# devise_parameter_sanitizer.for(:sign_up) << :attribute
|
44
44
|
# end
|
45
45
|
|
46
|
-
#
|
46
|
+
# If you have extra params to permit, append them to the sanitizer.
|
47
47
|
# def configure_account_update_params
|
48
48
|
# devise_parameter_sanitizer.for(:account_update) << :attribute
|
49
49
|
# end
|
@@ -18,7 +18,7 @@ class <%= @scope_prefix %>SessionsController < Devise::SessionsController
|
|
18
18
|
|
19
19
|
# protected
|
20
20
|
|
21
|
-
#
|
21
|
+
# If you have extra params to permit, append them to the sanitizer.
|
22
22
|
# def configure_sign_in_params
|
23
23
|
# devise_parameter_sanitizer.for(:sign_in) << :attribute
|
24
24
|
# end
|
@@ -4,6 +4,8 @@ Devise.setup do |config|
|
|
4
4
|
# The secret key used by Devise. Devise uses this key to generate
|
5
5
|
# random tokens. Changing this key will render invalid all existing
|
6
6
|
# confirmation, reset password and unlock tokens in the database.
|
7
|
+
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key`
|
8
|
+
# by default. You can change it below and use your own secret key.
|
7
9
|
<% if rails_4? -%>
|
8
10
|
# config.secret_key = '<%= SecureRandom.hex(64) %>'
|
9
11
|
<% else -%>
|
@@ -33,7 +35,7 @@ Devise.setup do |config|
|
|
33
35
|
# session. If you need permissions, you should implement that in a before filter.
|
34
36
|
# You can also supply a hash where the value is a boolean determining whether
|
35
37
|
# or not authentication should be aborted when the value is not present.
|
36
|
-
# config.authentication_keys = [
|
38
|
+
# config.authentication_keys = [:email]
|
37
39
|
|
38
40
|
# Configure parameters from the request object used for authentication. Each entry
|
39
41
|
# given should be a request method and it will automatically be passed to the
|
@@ -45,12 +47,12 @@ Devise.setup do |config|
|
|
45
47
|
# Configure which authentication keys should be case-insensitive.
|
46
48
|
# These keys will be downcased upon creating or modifying a user and when used
|
47
49
|
# to authenticate or find a user. Default is :email.
|
48
|
-
config.case_insensitive_keys = [
|
50
|
+
config.case_insensitive_keys = [:email]
|
49
51
|
|
50
52
|
# Configure which authentication keys should have whitespace stripped.
|
51
53
|
# These keys will have whitespace before and after removed upon creating or
|
52
54
|
# modifying a user and when used to authenticate or find a user. Default is :email.
|
53
|
-
config.strip_whitespace_keys = [
|
55
|
+
config.strip_whitespace_keys = [:email]
|
54
56
|
|
55
57
|
# Tell if authentication through request.params is enabled. True by default.
|
56
58
|
# It can be set to an array that will enable params authentication only for the
|
@@ -126,7 +128,7 @@ Devise.setup do |config|
|
|
126
128
|
config.reconfirmable = true
|
127
129
|
|
128
130
|
# Defines which key will be used when confirming an account
|
129
|
-
# config.confirmation_keys = [
|
131
|
+
# config.confirmation_keys = [:email]
|
130
132
|
|
131
133
|
# ==> Configuration for :rememberable
|
132
134
|
# The time the user will be remembered without asking for credentials again.
|
@@ -144,7 +146,7 @@ Devise.setup do |config|
|
|
144
146
|
|
145
147
|
# ==> Configuration for :validatable
|
146
148
|
# Range for password length.
|
147
|
-
config.password_length = 8..
|
149
|
+
config.password_length = 8..72
|
148
150
|
|
149
151
|
# Email regex used to validate email formats. It simply asserts that
|
150
152
|
# one (and only one) @ exists in the given string. This is mainly
|
@@ -166,7 +168,7 @@ Devise.setup do |config|
|
|
166
168
|
# config.lock_strategy = :failed_attempts
|
167
169
|
|
168
170
|
# Defines which key will be used when locking and unlocking an account
|
169
|
-
# config.unlock_keys = [
|
171
|
+
# config.unlock_keys = [:email]
|
170
172
|
|
171
173
|
# Defines which strategy will be used to unlock an account.
|
172
174
|
# :email = Sends an unlock link to the user email
|
@@ -188,13 +190,17 @@ Devise.setup do |config|
|
|
188
190
|
# ==> Configuration for :recoverable
|
189
191
|
#
|
190
192
|
# Defines which key will be used when recovering the password for an account
|
191
|
-
# config.reset_password_keys = [
|
193
|
+
# config.reset_password_keys = [:email]
|
192
194
|
|
193
195
|
# Time interval you can reset your password with a reset password key.
|
194
196
|
# Don't put a too small interval or your users won't have the time to
|
195
197
|
# change their passwords.
|
196
198
|
config.reset_password_within = 6.hours
|
197
199
|
|
200
|
+
# When set to false, does not sign a user in automatically after their password is
|
201
|
+
# reset. Defaults to true, so a user is signed in automatically after a reset.
|
202
|
+
# config.sign_in_after_reset_password = true
|
203
|
+
|
198
204
|
# ==> Configuration for :encryptable
|
199
205
|
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
200
206
|
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
@@ -257,7 +263,7 @@ Devise.setup do |config|
|
|
257
263
|
# The router that invoked `devise_for`, in the example above, would be:
|
258
264
|
# config.router_name = :my_engine
|
259
265
|
#
|
260
|
-
# When using
|
266
|
+
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
|
261
267
|
# so you need to do it manually. For the users scope, it would be:
|
262
268
|
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
263
269
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%= f.full_error :reset_password_token %>
|
8
8
|
|
9
9
|
<div class="form-inputs">
|
10
|
-
<%= f.input :password, label: "New password", required: true, autofocus: true %>
|
10
|
+
<%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
|
11
11
|
<%= f.input :password_confirmation, label: "Confirm your new password", required: true %>
|
12
12
|
</div>
|
13
13
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
<div class="form-inputs">
|
7
7
|
<%= f.input :email, required: true, autofocus: true %>
|
8
|
-
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @
|
8
|
+
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
|
9
9
|
<%= f.input :password_confirmation, required: true %>
|
10
10
|
</div>
|
11
11
|
|
@@ -8,7 +8,7 @@ class CustomRegistrationsControllerTest < ActionController::TestCase
|
|
8
8
|
setup do
|
9
9
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
10
10
|
@password = 'password'
|
11
|
-
@user = create_user(password: @password, password_confirmation: @password).tap(&:confirm
|
11
|
+
@user = create_user(password: @password, password_confirmation: @password).tap(&:confirm)
|
12
12
|
end
|
13
13
|
|
14
14
|
test "yield resource to block on create success" do
|
@@ -32,4 +32,9 @@ class CustomRegistrationsControllerTest < ActionController::TestCase
|
|
32
32
|
put :update, { user: { } }
|
33
33
|
assert @controller.update_block_called?, "update failed to yield resource to provided block"
|
34
34
|
end
|
35
|
+
|
36
|
+
test "yield resource to block on new" do
|
37
|
+
get :new
|
38
|
+
assert @controller.new_block_called?, "new failed to yield resource to provided block"
|
39
|
+
end
|
35
40
|
end
|
@@ -245,6 +245,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
|
245
245
|
assert_equal "/foo?bar=baz", @controller.stored_location_for(:user)
|
246
246
|
end
|
247
247
|
|
248
|
+
test 'store location for stores fragments' do
|
249
|
+
@controller.store_location_for(:user, "/foo#bar")
|
250
|
+
assert_equal "/foo#bar", @controller.stored_location_for(:user)
|
251
|
+
end
|
252
|
+
|
248
253
|
test 'after sign in path defaults to root path if none by was specified for the given scope' do
|
249
254
|
assert_equal root_path, @controller.after_sign_in_path_for(:user)
|
250
255
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SessionsInheritedController < Devise::SessionsController
|
4
|
+
def test_i18n_scope
|
5
|
+
set_flash_message(:notice, :signed_in)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class AnotherInheritedController < SessionsInheritedController
|
10
|
+
protected
|
11
|
+
|
12
|
+
def translation_scope
|
13
|
+
'another'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class InheritedControllerTest < ActionController::TestCase
|
18
|
+
tests SessionsInheritedController
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@mock_warden = OpenStruct.new
|
22
|
+
@controller.request.env['warden'] = @mock_warden
|
23
|
+
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'I18n scope is inherited from Devise::Sessions' do
|
27
|
+
I18n.expects(:t).with do |message, options|
|
28
|
+
message == 'user.signed_in' &&
|
29
|
+
options[:scope] == 'devise.sessions'
|
30
|
+
end
|
31
|
+
@controller.test_i18n_scope
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class AnotherInheritedControllerTest < ActionController::TestCase
|
36
|
+
tests AnotherInheritedController
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@mock_warden = OpenStruct.new
|
40
|
+
@controller.request.env['warden'] = @mock_warden
|
41
|
+
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'I18n scope is overridden' do
|
45
|
+
I18n.expects(:t).with do |message, options|
|
46
|
+
message == 'user.signed_in' &&
|
47
|
+
options[:scope] == 'another'
|
48
|
+
end
|
49
|
+
@controller.test_i18n_scope
|
50
|
+
end
|
51
|
+
end
|
@@ -13,16 +13,16 @@ class HelpersTest < ActionController::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
test 'get resource name from env' do
|
16
|
-
assert_equal :user, @controller.resource_name
|
16
|
+
assert_equal :user, @controller.send(:resource_name)
|
17
17
|
end
|
18
18
|
|
19
19
|
test 'get resource class from env' do
|
20
|
-
assert_equal User, @controller.resource_class
|
20
|
+
assert_equal User, @controller.send(:resource_class)
|
21
21
|
end
|
22
22
|
|
23
23
|
test 'get resource instance variable from env' do
|
24
24
|
@controller.instance_variable_set(:@user, user = User.new)
|
25
|
-
assert_equal user, @controller.resource
|
25
|
+
assert_equal user, @controller.send(:resource)
|
26
26
|
end
|
27
27
|
|
28
28
|
test 'set resource instance variable from env' do
|
@@ -80,7 +80,7 @@ class HelpersTest < ActionController::TestCase
|
|
80
80
|
|
81
81
|
test 'signed in resource returns signed in resource for current scope' do
|
82
82
|
@mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)
|
83
|
-
assert_kind_of User, @controller.signed_in_resource
|
83
|
+
assert_kind_of User, @controller.send(:signed_in_resource)
|
84
84
|
end
|
85
85
|
|
86
86
|
test 'is a devise controller' do
|