Skip to content
Browse files

fixes #44 Race condition: test_mode! intermittent failures (rails 3.2)

  • Loading branch information...
1 parent e31d0a0 commit e67abc71ddeda3dac861de1c040f3cb67039e212 @sarmiena sarmiena committed Apr 2, 2012
Showing with 73 additions and 4 deletions.
  1. +1 −0 Gemfile
  2. +15 −0 Gemfile.lock
  3. +4 −2 lib/warden.rb
  4. +7 −1 lib/warden/proxy.rb
  5. +14 −0 lib/warden/test/warden_helpers.rb
  6. +27 −1 spec/warden/proxy_spec.rb
  7. +5 −0 spec/warden/test/helpers_spec.rb
View
1 Gemfile
@@ -8,4 +8,5 @@ gem 'rack', '1.3'
group :test do
gem 'rspec', '~>2'
gem 'rack-test'
+ gem 'ruby-debug19'
end
View
15 Gemfile.lock
@@ -7,7 +7,11 @@ PATH
GEM
remote: http://rubygems.org/
specs:
+ archive-tar-minitar (0.5.2)
+ columnize (0.3.6)
diff-lcs (1.1.2)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
rack (1.3.0)
rack-test (0.6.0)
rack (>= 1.0)
@@ -20,6 +24,16 @@ GEM
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
PLATFORMS
ruby
@@ -29,4 +43,5 @@ DEPENDENCIES
rack-test
rake
rspec (~> 2)
+ ruby-debug19
warden!
View
6 lib/warden.rb
@@ -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
8 lib/warden/proxy.rb
@@ -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
View
14 lib/warden/test/warden_helpers.rb
@@ -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
28 spec/warden/proxy_spec.rb
@@ -1,5 +1,6 @@
# encoding: utf-8
require 'spec_helper'
+require 'ruby-debug'
describe Warden::Proxy do
@@ -956,4 +957,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
View
5 spec/warden/test/helpers_spec.rb
@@ -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

0 comments on commit e67abc7

Please sign in to comment.
Something went wrong with that request. Please try again.