test/rule_test.rb in rack-rewrite-1.3.2 vs test/rule_test.rb in rack-rewrite-1.3.3
- old
+ new
@@ -183,10 +183,20 @@
should 'return the contents of geminstaller.yml in an array for Ruby 1.9.2 compatibility' do
assert_equal [File.read(@file)], @response[2]
end
end
+
+ should 'return proper status for send_file or x_send_file if specified' do
+ [:send_file, :x_send_file].each do |rule_type|
+ file = File.join(TEST_ROOT, 'geminstaller.yml')
+ rule = Rack::Rewrite::Rule.new(rule_type, /.*/, file, :status => 503)
+ env = {'PATH_INFO' => '/abc'}
+ assert_equal 503, rule.apply!(env)[0]
+ end
+ end
+
end
context 'Rule#matches' do
context 'Given rule with :not option which matches "from" string' do
setup do
@@ -252,13 +262,21 @@
should 'not match PATH_INFO of /my_features' do
assert !@rule.matches?(rack_env_for("/my_features"))
end
end
- should 'match with the ^ operator for regexps' do
- rule = Rack::Rewrite::Rule.new(:rewrite, %r{^/jason}, '/steve')
- assert rule.matches?(rack_env_for('/jason'))
+ context 'Given a rule with the ^ operator' do
+ setup do
+ @rule = Rack::Rewrite::Rule.new(:rewrite, %r{^/jason}, '/steve')
+ end
+ should 'match with the ^ operator if match is at the beginning of the path' do
+ assert @rule.matches?(rack_env_for('/jason'))
+ end
+
+ should 'not match with the ^ operator when match is deeply nested' do
+ assert !@rule.matches?(rack_env_for('/foo/bar/jason'))
+ end
end
context 'Given any rule with a "from" regular expression of /features(.*)' do
setup do
@rule = Rack::Rewrite::Rule.new(:rewrite, %r{/features(.*)}, '/facial_features$1')
@@ -392,9 +410,16 @@
end
should 'call to with from match data' do
rule = Rack::Rewrite::Rule.new(:rewrite, %r{/person_(\d+)(.*)}, lambda {|match, env| "people-#{match[1].to_i * 3}#{match[2]}"})
assert_equal 'people-3?show_bio=1', rule.send(:interpret_to, rack_env_for('/person_1?show_bio=1'))
+ end
+ end
+
+ context 'Mongel 1.2.0.pre2 edge case: root url with a query string' do
+ should 'handle a nil PATH_INFO variable without errors' do
+ rule = Rack::Rewrite::Rule.new(:r301, '/a', '/')
+ assert_equal '?exists', rule.send(:build_path_from_env, {'QUERY_STRING' => 'exists'})
end
end
def rack_env_for(url, options = {})
components = url.split('?')