[WIP] Ensure correct locale set by controller is used in failure app

This commit is contained in:
Carlos Antonio da Silva 2020-09-29 15:34:33 -03:00
parent c82e4cf47b
commit a2884112c7
4 changed files with 10 additions and 7 deletions

View File

@ -45,7 +45,7 @@ class Devise::SessionsController < DeviseController
end
def auth_options
{ scope: resource_name, recall: "#{controller_path}#new" }
{ scope: resource_name, recall: "#{controller_path}#new", locale: I18n.locale }
end
def translation_scope

View File

@ -46,6 +46,7 @@ module Devise
mappings.unshift mappings.delete(favorite.to_sym) if favorite
mappings.each do |mapping|
opts[:scope] = mapping
opts[:locale] = I18n.locale
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
end
@ -115,6 +116,7 @@ module Devise
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(opts = {})
opts[:scope] = :#{mapping}
opts[:locale] = I18n.locale
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end

View File

@ -101,9 +101,10 @@ module Devise
options[:resource_name] = scope
options[:scope] = "devise.failure"
options[:default] = [message]
options[:locale] = warden_options[:locale]
auth_keys = scope_class.authentication_keys
keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key| scope_class.human_attribute_name(key) }
options[:authentication_keys] = keys.join(I18n.translate(:"support.array.words_connector"))
options[:authentication_keys] = keys.join(I18n.translate(:"support.array.words_connector", locale: warden_options[:locale]))
options = i18n_options(options)
I18n.t(:"#{scope}.#{message}", **options)

View File

@ -64,30 +64,30 @@ class ControllerAuthenticatableTest < Devise::ControllerTestCase
end
test 'proxy authenticate_user! to authenticate with user scope' do
@mock_warden.expects(:authenticate!).with(scope: :user)
@mock_warden.expects(:authenticate!).with(scope: :user, locale: :en)
@controller.authenticate_user!
end
test 'proxy authenticate_user! options to authenticate with user scope' do
@mock_warden.expects(:authenticate!).with(scope: :user, recall: "foo")
@mock_warden.expects(:authenticate!).with(scope: :user, recall: "foo", locale: :en)
@controller.authenticate_user!(recall: "foo")
end
test 'proxy authenticate_admin! to authenticate with admin scope' do
@mock_warden.expects(:authenticate!).with(scope: :admin)
@mock_warden.expects(:authenticate!).with(scope: :admin, locale: :en)
@controller.authenticate_admin!
end
test 'proxy authenticate_[group]! to authenticate!? with each scope' do
[:user, :admin].each do |scope|
@mock_warden.expects(:authenticate!).with(scope: scope)
@mock_warden.expects(:authenticate!).with(scope: scope, locale: :en)
@mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
end
@controller.authenticate_commenter!
end
test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
@mock_warden.expects(:authenticate!).with(scope: :publisher_account)
@mock_warden.expects(:authenticate!).with(scope: :publisher_account, locale: :en)
@controller.authenticate_publisher_account!
end