Add missing support of Rails.application.config.action_controller.relative_url_root (#4146)
* Add Devise::FailureApp#{relative_url_root, relative_url_root?} Also support missing action_controller.relative_url_root configuration. * Dry assignment of relative_url_root Also this commit adds support for Rails.application.config.action_controller.relative_url_root
This commit is contained in:
parent
cccc137714
commit
4015488b90
|
@ -50,13 +50,11 @@ module Devise
|
|||
end
|
||||
|
||||
def recall
|
||||
config = Rails.application.config
|
||||
|
||||
header_info = if config.try(:relative_url_root)
|
||||
base_path = Pathname.new(config.relative_url_root)
|
||||
header_info = if relative_url_root?
|
||||
base_path = Pathname.new(relative_url_root)
|
||||
full_path = Pathname.new(attempted_path)
|
||||
|
||||
{ "SCRIPT_NAME" => config.relative_url_root,
|
||||
{ "SCRIPT_NAME" => relative_url_root,
|
||||
"PATH_INFO" => '/' + full_path.relative_path_from(base_path).to_s }
|
||||
else
|
||||
{ "PATH_INFO" => attempted_path }
|
||||
|
@ -144,11 +142,7 @@ module Devise
|
|||
|
||||
opts[:format] = request_format unless skip_format?
|
||||
|
||||
config = Rails.application.config
|
||||
|
||||
if config.respond_to?(:relative_url_root) && config.relative_url_root.present?
|
||||
opts[:script_name] = config.relative_url_root
|
||||
end
|
||||
opts[:script_name] = relative_url_root if relative_url_root?
|
||||
|
||||
router_name = Devise.mappings[scope].router_name || Devise.available_router_name
|
||||
context = send(router_name)
|
||||
|
@ -252,5 +246,17 @@ module Devise
|
|||
def request_format
|
||||
@request_format ||= request.format.try(:ref)
|
||||
end
|
||||
|
||||
def relative_url_root
|
||||
@relative_url_root ||= begin
|
||||
config = Rails.application.config
|
||||
|
||||
config.try(:relative_url_root) || config.action_controller.try(:relative_url_root)
|
||||
end
|
||||
end
|
||||
|
||||
def relative_url_root?
|
||||
relative_url_root.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -131,6 +131,24 @@ class FailureTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
if Rails.application.config.action_controller.respond_to?(:relative_url_root)
|
||||
test "returns to the default redirect location considering action_controller's relative url root" do
|
||||
swap Rails.application.config.action_controller, relative_url_root: "/sample" do
|
||||
call_failure
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
|
||||
end
|
||||
end
|
||||
|
||||
test "returns to the default redirect location considering action_controller's relative url root and subdomain" do
|
||||
swap Rails.application.config.action_controller, relative_url_root: "/sample" do
|
||||
call_failure('warden.options' => { scope: :subdomain_user })
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test 'uses the proxy failure message as symbol' do
|
||||
call_failure('warden' => OpenStruct.new(message: :invalid))
|
||||
assert_equal 'Invalid Email or password.', @request.flash[:alert]
|
||||
|
|
Loading…
Reference in New Issue