mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:08:05 -05:00
Account for relative_url_root in FailureApp's recall method
Closes #3738
This commit is contained in:
@@ -51,7 +51,18 @@ module Devise
|
||||
end
|
||||
|
||||
def recall
|
||||
env["PATH_INFO"] = attempted_path
|
||||
config = Rails.application.config
|
||||
|
||||
if config.try(:relative_url_root)
|
||||
base_path = Pathname.new(config.relative_url_root)
|
||||
full_path = Pathname.new(attempted_path)
|
||||
|
||||
env["SCRIPT_NAME"] = config.relative_url_root
|
||||
env["PATH_INFO"] = '/' + full_path.relative_path_from(base_path).to_s
|
||||
else
|
||||
env["PATH_INFO"] = attempted_path
|
||||
end
|
||||
|
||||
flash.now[:alert] = i18n_message(:invalid) if is_flashing_format?
|
||||
self.response = recall_app(warden_options[:recall]).call(env)
|
||||
end
|
||||
|
||||
@@ -294,5 +294,22 @@ class FailureTest < ActiveSupport::TestCase
|
||||
assert @response.third.body.include?('<h2>Log in</h2>')
|
||||
assert @response.third.body.include?('Your account is not activated yet.')
|
||||
end
|
||||
|
||||
if Rails.application.config.respond_to?(:relative_url_root)
|
||||
test 'calls the original controller with the proper environment considering the relative url root' do
|
||||
swap Rails.application.config, relative_url_root: "/sample" do
|
||||
env = {
|
||||
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/sample/users/sign_in"},
|
||||
"devise.mapping" => Devise.mappings[:user],
|
||||
"warden" => stub_everything
|
||||
}
|
||||
call_failure(env)
|
||||
assert @response.third.body.include?('<h2>Log in</h2>')
|
||||
assert @response.third.body.include?('Invalid email or password.')
|
||||
assert_equal @request.env["SCRIPT_NAME"], '/sample'
|
||||
assert_equal @request.env["PATH_INFO"], '/users/sign_in'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user