diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 3cff73c5..d5f83f19 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -110,7 +110,7 @@ def request_page(url, http_method, data) #:nodoc: @http_method = http_method @data = data - request_page(response.location, :get, data) if redirect? + request_page(response.headers["Location"], :get, data) if redirect? return response end diff --git a/lib/webrat/merb.rb b/lib/webrat/merb.rb index 5ace8b5e..6fa3e46c 100644 --- a/lib/webrat/merb.rb +++ b/lib/webrat/merb.rb @@ -42,11 +42,6 @@ def do_request(url, data, headers, method) :params => (data && data.any?) ? data : nil, :headers => headers, :method => method) - follow_redirect - end - - def follow_redirect - self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302 end end @@ -59,10 +54,6 @@ def request(uri, env = {}) @_webrat_session ||= Webrat::MerbSession.new @_webrat_session.response = @_webrat_session.request(uri, env) end - - def follow_redirect - @_webrat_session.follow_redirect - end end end end diff --git a/spec/integration/merb/app/controllers/testing.rb b/spec/integration/merb/app/controllers/testing.rb index 40a56dad..937500a8 100644 --- a/spec/integration/merb/app/controllers/testing.rb +++ b/spec/integration/merb/app/controllers/testing.rb @@ -7,4 +7,8 @@ def show_form def submit_form end + def redirect_to_root + redirect "/" + end + end \ No newline at end of file diff --git a/spec/integration/merb/config/router.rb b/spec/integration/merb/config/router.rb index 6df8fb28..3b06c55c 100644 --- a/spec/integration/merb/config/router.rb +++ b/spec/integration/merb/config/router.rb @@ -28,4 +28,5 @@ Merb.logger.info("Compiling routes...") Merb::Router.prepare do match("/").to(:controller => "testing", :action => "show_form") + match("/redirect").to(:controller => "testing", :action => "redirect_to_root") end \ No newline at end of file diff --git a/spec/integration/merb/spec/webrat_spec.rb b/spec/integration/merb/spec/webrat_spec.rb index cc9fc1b9..1675a2c6 100644 --- a/spec/integration/merb/spec/webrat_spec.rb +++ b/spec/integration/merb/spec/webrat_spec.rb @@ -5,7 +5,7 @@ response = visit "/" response.should contain("Webrat Form") end - + it "should submit forms" do visit "/" fill_in "Text field", :with => "Hello" @@ -13,5 +13,9 @@ select "January" click_button "Test" end - + + it "should follow redirects" do + response = visit "/redirect" + response.should contain("Webrat Form") + end end \ No newline at end of file diff --git a/spec/integration/rails/app/controllers/webrat_controller.rb b/spec/integration/rails/app/controllers/webrat_controller.rb index 5a2db67a..23f0e821 100644 --- a/spec/integration/rails/app/controllers/webrat_controller.rb +++ b/spec/integration/rails/app/controllers/webrat_controller.rb @@ -1,10 +1,14 @@ class WebratController < ApplicationController - + def form end - + def submit render :text => "OK" end - + + def redirect + redirect_to :submit + end + end \ No newline at end of file diff --git a/spec/integration/rails/config/routes.rb b/spec/integration/rails/config/routes.rb index 7b63461b..41d6ff5b 100644 --- a/spec/integration/rails/config/routes.rb +++ b/spec/integration/rails/config/routes.rb @@ -1,6 +1,8 @@ ActionController::Routing::Routes.draw do |map| map.with_options :controller => "webrat" do |webrat| - webrat.submit "/submit", :action => "submit" - webrat.root :action => "form" + webrat.submit "/submit", :action => "submit" + webrat.redirect "/redirect", :action => "redirect" + + webrat.root :action => "form" end end diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb index 4ecbe273..ec83c1c9 100644 --- a/spec/integration/rails/test/integration/webrat_test.rb +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -6,7 +6,7 @@ class WebratTest < ActionController::IntegrationTest assert_tag "Webrat Form" assert response.body.include?("Webrat Form") end - + test "should submit forms" do visit root_path fill_in "Text field", :with => "Hello" @@ -14,4 +14,9 @@ class WebratTest < ActionController::IntegrationTest select "January" click_button "Test" end + + test "should follow redirects" do + visit redirect_path + assert response.body.include?("OK") + end end diff --git a/spec/private/core/session_spec.rb b/spec/private/core/session_spec.rb index 96cf2815..d4f9b2ad 100644 --- a/spec/private/core/session_spec.rb +++ b/spec/private/core/session_spec.rb @@ -115,7 +115,7 @@ def session.response_body it "should follow redirects" do webrat_session.should_receive(:redirect?).twice.and_return(true, false) - webrat_session.response.should_receive(:location).once.and_return("/newurl") + webrat_session.response.should_receive(:headers).once.and_return({ "Location" => "/newurl" }) webrat_session.request_page("/oldurl", :get, {}) diff --git a/spec/public/visit_spec.rb b/spec/public/visit_spec.rb index cecd4602..28aa2ba7 100644 --- a/spec/public/visit_spec.rb +++ b/spec/public/visit_spec.rb @@ -33,7 +33,7 @@ it "should follow redirects" do webrat_session.should_receive(:redirect?).twice.and_return(true, false) - webrat_session.response.should_receive(:location).once.and_return("/newurl") + webrat_session.response.should_receive(:headers).once.and_return({ "Location" => "/newurl" }) visit("/oldurl")