Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set attempted_path in warden.options before calling failure app in controller test helpers #5768

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
so it's possible to override `password_length` at runtime. (@manojmj92)
* bug fixes
* Make `Devise` work without `ActionMailer` when `Zeitwerk` autoloader is used.
* Set `attempted_path` in `warden.options` before calling failure app in controller test helpers.

Please check [4-stable](https://github.com/heartcombo/devise/blob/4-stable/CHANGELOG.md)
for previous changes.
1 change: 1 addition & 0 deletions lib/devise/test/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def _process_unauthenticated(env, options = {})
when :custom
proxy.custom_response
else
options.merge!(:attempted_path => ::Rack::Request.new(env).fullpath)
request.env["PATH_INFO"] = "/#{options[:action]}"
request.env["warden.options"] = options
Warden::Manager._run_callbacks(:before_failure, env, options)
Expand Down
13 changes: 13 additions & 0 deletions test/test/controller_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ def respond
end
end

test "sets attempted_path in warden.options" do
custom_failure_app = Class.new(Devise::FailureApp) do
def redirect_url
attempted_path
end
end

swap Devise.warden_config, failure_app: custom_failure_app do
get :index
assert_redirected_to "/users"
end
end

test "returns the body of a failure app" do
get :index

Expand Down