Skip to content

Commit

Permalink
Allows for yeilding the manager when it is created.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neighman committed Apr 19, 2009
1 parent e80bedd commit 6472253
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/rack-auth/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ class Manager
# :api: public
def initialize(app, config = {})
@app = app
@failure_app = config[:failure_app]
@config = config
end
yield self if block_given?

# should ensure there is a failure application defined.
@failure_app = config[:failure_app] if config[:failure_app]
raise "No Failure App provided" unless @failure_app
self
end

# :api: private
def call(env) # :nodoc:
Expand Down
13 changes: 10 additions & 3 deletions spec/helpers/request_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Rack::Auth::Spec
module Helpers

FAILURE_APP = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }

def env_with_params(path = "/", params = {})
method = params.fetch(:method, "GET")
Rack::MockRequest.env_for(path, :input => Rack::Utils.build_query(params),
Expand All @@ -10,10 +13,14 @@ def env_with_params(path = "/", params = {})
def setup_rack(app = nil, opts = {}, &block)
app ||= block if block_given?
opts[:default] ||= [:password]
opts[:failure_app] ||= failure_app
# opts[:failure_app] ||= failure_app
Rack::Builder.new do
use Rack::Auth::Spec::Helpers::Session
use Rack::Auth::Manager, opts
use Rack::Auth::Manager, opts do |manager|
manager.failure_app = Rack::Auth::Spec::Helpers::FAILURE_APP
puts manager.inspect

end
run app
end
end
Expand All @@ -23,7 +30,7 @@ def valid_response
end

def failure_app
lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }
Rack::Auth::Spec::Helpers::FAILURE_APP
end

def success_app
Expand Down

0 comments on commit 6472253

Please sign in to comment.