Refactor redirect handling as Merb response doesn't support the redirect? method. All integration specs now passing again.
This commit is contained in:
parent
b222d3fde3
commit
e77495bc04
@ -110,7 +110,7 @@ For example:
|
||||
@http_method = http_method
|
||||
@data = data
|
||||
|
||||
request_page(response.location, :get, data) if response.redirect?
|
||||
request_page(response.location, :get, data) if redirect?
|
||||
|
||||
return response
|
||||
end
|
||||
@ -119,6 +119,10 @@ For example:
|
||||
(200..499).include?(response_code)
|
||||
end
|
||||
|
||||
def redirect? #:nodoc:
|
||||
response_code / 100 == 3
|
||||
end
|
||||
|
||||
def exception_caught? #:nodoc:
|
||||
response_body =~ /Exception caught/
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ module Webrat #:nodoc:
|
||||
end
|
||||
|
||||
def response
|
||||
@response ||= TestResponse.new
|
||||
@response ||= Object.new
|
||||
end
|
||||
|
||||
def response_code
|
||||
@ -31,10 +31,4 @@ module Webrat #:nodoc:
|
||||
def delete(url, data, headers = nil)
|
||||
end
|
||||
end
|
||||
|
||||
class TestResponse #:nodoc:
|
||||
def redirect?
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
@ -114,7 +114,7 @@ describe Webrat::Session do
|
||||
end
|
||||
|
||||
it "should follow redirects" do
|
||||
webrat_session.response.should_receive(:redirect?).twice.and_return(true, false)
|
||||
webrat_session.should_receive(:redirect?).twice.and_return(true, false)
|
||||
webrat_session.response.should_receive(:location).once.and_return("/newurl")
|
||||
|
||||
webrat_session.request_page("/oldurl", :get, {})
|
||||
@ -122,4 +122,20 @@ describe Webrat::Session do
|
||||
webrat_session.current_url.should == "/newurl"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#redirect?" do
|
||||
before(:each) do
|
||||
webrat_session = Webrat::Session.new
|
||||
end
|
||||
|
||||
it "should return true if the last response was a redirect" do
|
||||
webrat_session.stub!(:response_code => 301)
|
||||
webrat_session.redirect?.should be_true
|
||||
end
|
||||
|
||||
it "should return false if the last response wasn't a redirect" do
|
||||
webrat_session.stub!(:response_code => 200)
|
||||
webrat_session.redirect?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
@ -34,6 +34,7 @@ describe "click_area" do
|
||||
</map>
|
||||
</html>
|
||||
HTML
|
||||
webrat_session.stub!(:redirect? => false)
|
||||
webrat_session.response_code = status
|
||||
lambda { click_area "Berlin" }.should_not raise_error
|
||||
end
|
||||
|
@ -69,6 +69,7 @@ describe "click_button" do
|
||||
</form>
|
||||
</html>
|
||||
HTML
|
||||
webrat_session.stub!(:redirect? => false)
|
||||
webrat_session.response_code = status
|
||||
lambda { click_button }.should_not raise_error
|
||||
end
|
||||
|
@ -236,6 +236,7 @@ describe "click_link" do
|
||||
<a href="/page">Link text</a>
|
||||
</html>
|
||||
HTML
|
||||
webrat_session.stub!(:redirect? => false)
|
||||
webrat_session.response_code = status
|
||||
lambda { click_link "Link text" }.should_not raise_error
|
||||
end
|
||||
|
@ -21,6 +21,7 @@ describe "visit" do
|
||||
|
||||
[200, 300, 400, 499].each do |status|
|
||||
it "should consider the #{status} status code as success" do
|
||||
webrat_session.stub!(:redirect? => false)
|
||||
webrat_session.response_code = status
|
||||
lambda { visit("/") }.should_not raise_error
|
||||
end
|
||||
@ -31,7 +32,7 @@ describe "visit" do
|
||||
end
|
||||
|
||||
it "should follow redirects" do
|
||||
webrat_session.response.should_receive(:redirect?).twice.and_return(true, false)
|
||||
webrat_session.should_receive(:redirect?).twice.and_return(true, false)
|
||||
webrat_session.response.should_receive(:location).once.and_return("/newurl")
|
||||
|
||||
visit("/oldurl")
|
||||
|
Loading…
Reference in New Issue
Block a user