Permalink
Browse files

fixed uri to path_info

  • Loading branch information...
1 parent b7fd99e commit 9dbf915e1846212011e0c283ae8d6834e169b2ce @joshbuddy committed May 18, 2009
Showing with 11 additions and 4 deletions.
  1. +1 −1 lib/rack_rewrite/condition_set.rb
  2. +10 −3 spec/conditions_spec.rb
@@ -13,7 +13,7 @@ def initialize(parent_set, conditions = nil)
def satisfied?(env)
if conditions
- uri_ok = conditions.key?(:uri) ? conditions[:uri] === env['PATH_INFO'] : true
+ uri_ok = conditions.key?(:path_info) ? conditions[:path_info] === env['PATH_INFO'] : true
method_ok = conditions.key?(:method) ? conditions[:method] === env['REQUEST_METHOD'].downcase : true
host_ok = conditions.key?(:host) ? conditions[:host] === env['HTTP_HOST'] : true
port_ok = conditions.key?(:port) ? conditions[:port] === env['SERVER_PORT'].to_i : true
@@ -8,23 +8,30 @@
env = Rack::MockRequest.env_for('/test', :method => method)
app = mock('app')
app.should_receive(:call).with(env).and_return([200, {}, ["body"]])
- Rack::Rewrite.new(app) { on(:method => method) { pass } }.call(env)
+ Rack::Rewrite.new(app) { on(:method => method) { pass }; fail }.call(env)
end
end
it "should detect a simple path_info" do
env = Rack::MockRequest.env_for('/test', :method => 'get')
app = mock('app')
app.should_receive(:call).with(env).and_return([200, {}, ["body"]])
- Rack::Rewrite.new(app) { on(:path_info => '/test') { pass } }.call(env)
+ Rack::Rewrite.new(app) { on(:path_info => '/test') { pass }; fail }.call(env)
+ proc { Rack::Rewrite.new(app) { on(:path_info => %r{^/test}) { pass }; fail }.call(Rack::MockRequest.env_for('/badtest', :method => 'get')) }.should raise_error
+ end
+
+ it "should fail on a simple path_info" do
+ env = Rack::MockRequest.env_for('/test', :method => 'get')
+ app = mock('app')
+ proc { Rack::Rewrite.new(app) { on(:path_info => %r{^/test}) { pass }; fail }.call(Rack::MockRequest.env_for('/badtest', :method => 'get')) }.should raise_error
end
it "should detect a param in the query string" do
env = Rack::MockRequest.env_for('/test?test=helpme', :method => 'get')
app = mock('app')
app.should_receive(:call).with(env).and_return([200, {}, ["body"]])
Rack::Rewrite.new(app) { on(:params => {:test => 'helpme'}) { pass } }.call(env)
- proc { Rack::Rewrite.new(app) { on(:params => {:test => 'helpme2'}) { pass } }.call(env) }.should raise_error
+ proc { Rack::Rewrite.new(app) { on(:params => {:test => 'helpme2'}) { pass }; fail }.call(env) }.should raise_error
end
end

0 comments on commit 9dbf915

Please sign in to comment.