Permalink
Browse files

Merge pull request #45 from sarmiena/b44_asset_race_condition

fixes #44 test_mode! race condition
  • Loading branch information...
2 parents f3961cd + 4c6141a commit 54e83f4be55ab26333c990ae6bf43f9715e7bc98 @hassox committed Apr 11, 2012
View
@@ -33,8 +33,10 @@ def self.test_mode!
unless Warden::Test::WardenHelpers === Warden
Warden.extend Warden::Test::WardenHelpers
Warden::Manager.on_request do |proxy|
- while blk = Warden._on_next_request.shift
- blk.call(proxy)
+ unless proxy.asset_request?
+ while blk = Warden._on_next_request.shift
+ blk.call(proxy)
+ end
end
end
end
View
@@ -268,12 +268,18 @@ def custom_failure!
@custom_failure = true
end
- # Check to see if the custom failur flag has been set
+ # Check to see if the custom failure flag has been set
# :api: public
def custom_failure?
!!@custom_failure
end
+ # Check to see if this is an asset request
+ # :api: public
+ def asset_request?
+ ::Warden::asset_paths.any? { |r| env['PATH_INFO'].to_s.match(r) }
+ end
+
def inspect(*args)
"Warden::Proxy:#{object_id} @config=#{@config.inspect}"
end
@@ -4,6 +4,20 @@ module Warden
module Test
module WardenHelpers
+ # Returns list of regex objects that match paths expected to be an asset
+ # @see Warden::Proxy#asset_request?
+ # @api public
+ def asset_paths
+ @asset_paths ||= [/^\/assets\//]
+ end
+
+ # Sets list of regex objects that match paths expected to be an asset
+ # @see Warden::Proxy#asset_request?
+ # @api public
+ def asset_paths=(*vals)
+ @asset_paths = vals
+ end
+
# Adds a block to be executed on the next request when the stack reaches warden.
# The warden proxy is yielded to the block
# @api public
View
@@ -956,4 +956,29 @@ def wrap_app(app, &blk)
session['warden.user.baz.key'].should == "User"
end
end
-end
+
+ describe "#asset_request?" do
+ before(:each) do
+ @asset_regex = /^\/assets\//
+ ::Warden.asset_paths = @asset_regex
+ end
+
+ it "should return true if PATH_INFO is in asset list" do
+ env = env_with_params('/assets/fun.gif')
+ setup_rack(success_app).call(env)
+ proxy = env["warden"]
+
+ proxy.env['PATH_INFO'].should match(@asset_regex)
+ proxy.should be_asset_request
+ end
+
+ it "should return false if PATH_INFO is not in asset list" do
+ env = env_with_params('/home')
+ setup_rack(success_app).call(env)
+ proxy = env["warden"]
+
+ proxy.env['PATH_INFO'].should_not match(@asset_regex)
+ proxy.should_not be_asset_request
+ end
+ end
+end
@@ -87,4 +87,9 @@
$captures.should == [:run]
end
+ describe "#asset_paths" do
+ it "should default asset_paths to anything asset path regex" do
+ Warden.asset_paths.should == [/^\/assets\//]
+ end
+ end
end
@@ -64,4 +64,13 @@
app.call(env_with_params)
$captures.should == []
end
+
+ context "asset requests" do
+ it "should not execute on_next_request blocks if this is an asset request" do
+ app = setup_rack(@app)
+ Warden.on_next_request{|w| $captures << :first }
+ app.call(env_with_params("/assets/fun.gif"))
+ $captures.should == []
+ end
+ end
end

0 comments on commit 54e83f4

Please sign in to comment.