forked from heartcombo/devise
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass back the custom response, if the winning strategy uses the custo…
…m\! method Signed-off-by: José Valim <jose.valim@gmail.com>
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "test/test_helper" | ||
require "rack/test" | ||
|
||
class RackMiddlewareTest < Test::Unit::TestCase | ||
include Rack::Test::Methods | ||
|
||
def app | ||
ActionController::Dispatcher.new | ||
end | ||
|
||
def warden | ||
last_request.env['warden'] | ||
end | ||
|
||
def with_custom_strategy | ||
get '/' | ||
|
||
Warden::Strategies.add(:custom_test) do | ||
def valid? | ||
true | ||
end | ||
|
||
def authenticate! | ||
custom! [599, { | ||
"X-Custom-Response" => "Custom response test", | ||
"Content-type" => "text/plain" | ||
}, "Custom response test"] | ||
end | ||
end | ||
|
||
#ActionController::Dispatcher.middleware.use CustomStrategyInterceptor | ||
default_strategies = warden.manager.config.default_strategies | ||
warden.manager.config.default_strategies :custom_test | ||
yield | ||
warden.manager.config.default_strategies default_strategies | ||
end | ||
|
||
def test_custom_strategy_response | ||
with_custom_strategy do | ||
post('/users/sign_in') | ||
|
||
assert_equal 599, last_response.status | ||
assert_equal "Custom response test", last_response.body | ||
assert_equal "Custom response test", last_response.headers["X-Custom-Response"] | ||
end | ||
end | ||
end |