add support for dash 'to' in rewriterule tests

This commit is contained in:
John Bintz 2011-01-11 10:39:52 -05:00
parent e0706fdded
commit 70edad9be0
3 changed files with 36 additions and 19 deletions

View File

@ -283,7 +283,9 @@ module Apache
opts[:request_uri] = from opts[:request_uri] = from
result = from result = from
result = super(from, opts) if match?(from, opts) if match?(from, opts)
result = super(from, opts) if !(@to == '-')
end
result.replace_placeholderize(opts) result.replace_placeholderize(opts)
end end

View File

@ -1,3 +1,3 @@
module Apache module Apache
VERSION = '0.2.7' VERSION = '0.2.8'
end end

View File

@ -1,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require 'apache/config'
describe Apache::Config, "rewrites" do describe Apache::Config, "rewrites" do
let(:apache) { Apache::Config } let(:apache) { Apache::Config }
@ -71,26 +72,40 @@ describe Apache::MatchableThing, "something that can be matched" do
end end
describe Apache::RewriteRule, "a RewriteRule" do describe Apache::RewriteRule, "a RewriteRule" do
subject do context 'basic' do
rule = Apache::RewriteRule.new subject do
rule.cond('/%{REQUEST_FILENAME}', '^/test$') rule = Apache::RewriteRule.new
rule.rule(%r{^/test$}, '/test2', :last => true, :preserve_query_string => true) rule.cond('/%{REQUEST_FILENAME}', '^/test$')
rule rule.rule(%r{^/test$}, '/test2', :last => true, :preserve_query_string => true)
rule
end
its(:to_s) { should == 'RewriteRule "^/test$" "/test2" [L,QSA]' }
its(:to_a) { should == [
'',
'RewriteCond "/%{REQUEST_FILENAME}" "^/test$"',
'RewriteRule "^/test$" "/test2" [L,QSA]'
] }
it "should not the test" do
subject.test('/test', :request_filename => 'test').should == '/test2'
end
it "should fail if opts is not provided" do
lambda { subject.match?('test', nil) }.should raise_error
end
end end
its(:to_s) { should == 'RewriteRule "^/test$" "/test2" [L,QSA]' } context 'dash' do
its(:to_a) { should == [ subject {
'', rule = Apache::RewriteRule.new
'RewriteCond "/%{REQUEST_FILENAME}" "^/test$"', rule.rule(%r{^/test$}, '-', :last => true)
'RewriteRule "^/test$" "/test2" [L,QSA]' rule
] } }
it "should not the test" do it "should succeed and return itself" do
subject.test('/test', :request_filename => 'test').should == '/test2' subject.test('/test').should == '/test'
end end
it "should fail if opts is not provided" do
lambda { subject.match?('test', nil) }.should raise_error
end end
end end