Skip to content

Commit

Permalink
Pass back the custom response, if the winning strategy uses the custo…
Browse files Browse the repository at this point in the history
…m\! method

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
nbudin authored and josevalim committed Apr 2, 2010
1 parent b425c70 commit 0bc1528
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/sessions_controller.rb
Expand Up @@ -20,6 +20,7 @@ def create
set_flash_message :notice, :signed_in
sign_in_and_redirect(resource_name, resource, true)
else
throw :warden if warden.result == :custom
set_now_flash_message :alert, (warden.message || :invalid)
clean_up_passwords(build_resource)
render_with_scope :new
Expand Down
47 changes: 47 additions & 0 deletions test/integration/rack_middleware_test.rb
@@ -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

0 comments on commit 0bc1528

Please sign in to comment.