diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ccb0882a4..f147a731dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### Unreleased + +* bug fixes + * Set `attempted_path` in `warden.options` before calling failure app in controller test helpers. #5768 + ### 5.0.4 - 2026-05-08 * security fixes diff --git a/lib/devise/test/controller_helpers.rb b/lib/devise/test/controller_helpers.rb index d3522a3466..6a29b5f33f 100644 --- a/lib/devise/test/controller_helpers.rb +++ b/lib/devise/test/controller_helpers.rb @@ -125,6 +125,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) diff --git a/test/test/controller_helpers_test.rb b/test/test/controller_helpers_test.rb index a158e87536..f76c7f81d3 100644 --- a/test/test/controller_helpers_test.rb +++ b/test/test/controller_helpers_test.rb @@ -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