Skip to content

Commit

Permalink
Account for relative_url_root in FailureApp's recall method
Browse files Browse the repository at this point in the history
  • Loading branch information
stanhu committed Sep 6, 2015
1 parent 40258bf commit 7025f96
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/devise/failure_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ def http_auth
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
Expand Down
17 changes: 17 additions & 0 deletions test/failure_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,22 @@ def call_failure(env_params={})
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

0 comments on commit 7025f96

Please sign in to comment.