diff --git a/lib/apache/rewrites.rb b/lib/apache/rewrites.rb index d6794c0..f58f1db 100644 --- a/lib/apache/rewrites.rb +++ b/lib/apache/rewrites.rb @@ -283,7 +283,9 @@ module Apache opts[:request_uri] = 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) end diff --git a/lib/apache/version.rb b/lib/apache/version.rb index 316c892..feda9b1 100644 --- a/lib/apache/version.rb +++ b/lib/apache/version.rb @@ -1,3 +1,3 @@ module Apache - VERSION = '0.2.7' + VERSION = '0.2.8' end diff --git a/spec/apache/rewrites_spec.rb b/spec/apache/rewrites_spec.rb index 5662e5c..6ff4dd7 100644 --- a/spec/apache/rewrites_spec.rb +++ b/spec/apache/rewrites_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'apache/config' describe Apache::Config, "rewrites" do let(:apache) { Apache::Config } @@ -71,26 +72,40 @@ describe Apache::MatchableThing, "something that can be matched" do end describe Apache::RewriteRule, "a RewriteRule" do - subject do - rule = Apache::RewriteRule.new - rule.cond('/%{REQUEST_FILENAME}', '^/test$') - rule.rule(%r{^/test$}, '/test2', :last => true, :preserve_query_string => true) - rule + context 'basic' do + subject do + rule = Apache::RewriteRule.new + rule.cond('/%{REQUEST_FILENAME}', '^/test$') + 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 - its(:to_s) { should == 'RewriteRule "^/test$" "/test2" [L,QSA]' } - its(:to_a) { should == [ - '', - 'RewriteCond "/%{REQUEST_FILENAME}" "^/test$"', - 'RewriteRule "^/test$" "/test2" [L,QSA]' - ] } + context 'dash' do + subject { + rule = Apache::RewriteRule.new + rule.rule(%r{^/test$}, '-', :last => true) + rule + } - 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 + it "should succeed and return itself" do + subject.test('/test').should == '/test' + end end end