test/rack-rewrite_test.rb in rack-rewrite-0.2.0 vs test/rack-rewrite_test.rb in rack-rewrite-0.2.1
- old
+ new
@@ -1,13 +1,17 @@
require 'test_helper'
class RackRewriteTest < Test::Unit::TestCase
def call_args(overrides={})
- {'REQUEST_URI' => '/wiki/Yair_Flicker', 'PATH_INFO' => '/wiki/Yair_Flicker', 'QUERYSTRING' => ''}.merge(overrides)
+ {'REQUEST_URI' => '/wiki/Yair_Flicker', 'PATH_INFO' => '/wiki/Yair_Flicker', 'QUERY_STRING' => ''}.merge(overrides)
end
+ def call_args_no_req(overrides={})
+ {'PATH_INFO' => '/wiki/Yair_Flicker', 'QUERY_STRING' => ''}.merge(overrides)
+ end
+
def self.should_not_halt
should "not halt the rack chain" do
@app.expects(:call).once
@rack.call(call_args)
end
@@ -88,13 +92,39 @@
should "set PATH_INFO to '/john'" do
assert_equal '/john', @initial_args['PATH_INFO']
end
should "set REQUEST_URI to '/john'" do
- assert_equal '/john', @initial_args['REQUEST_URI']
+ assert_equal '/john', @initial_args['REQUEST_URI']
end
- should "set QUERYSTRING to ''" do
- assert_equal '', @initial_args['QUERYSTRING']
+ should "set QUERY_STRING to ''" do
+ assert_equal '', @initial_args['QUERY_STRING']
+ end
+ end
+ end
+
+ context 'when a rewrite rule matches but there is no REQUEST_URI set' do
+ setup {
+ @rack = Rack::Rewrite.new(@app) do
+ rewrite '/wiki/Yair_Flicker', '/john'
+ end
+ }
+ should_not_halt
+
+ context 'the env' do
+ setup do
+ @initial_args = call_args_no_req.dup
+ @rack.call(@initial_args)
+ end
+
+ should "set PATH_INFO to '/john'" do
+ assert_equal '/john', @initial_args['PATH_INFO']
+ end
+ should "set REQUEST_URI to '/john'" do
+ assert_equal '/john', @initial_args['REQUEST_URI']
+ end
+ should "set QUERY_STRING to ''" do
+ assert_equal '', @initial_args['QUERY_STRING']
end
end
end
end