Rails and Merb integration tests for following redirects

This commit is contained in:
Josh Knowles 2008-12-29 23:14:26 -05:00
parent e77495bc04
commit e19b1cc323
10 changed files with 31 additions and 20 deletions

View File

@ -110,7 +110,7 @@ For example:
@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

View File

@ -42,11 +42,6 @@ module Webrat
: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 @@ module Merb #:nodoc:
@_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

View File

@ -7,4 +7,8 @@ class Testing < Application
def submit_form
end
def redirect_to_root
redirect "/"
end
end

View File

@ -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

View File

@ -14,4 +14,8 @@ describe "Webrat" do
click_button "Test"
end
it "should follow redirects" do
response = visit "/redirect"
response.should contain("Webrat Form")
end
end

View File

@ -7,4 +7,8 @@ class WebratController < ApplicationController
render :text => "OK"
end
def redirect
redirect_to :submit
end
end

View File

@ -1,6 +1,8 @@
ActionController::Routing::Routes.draw do |map|
map.with_options :controller => "webrat" do |webrat|
webrat.submit "/submit", :action => "submit"
webrat.redirect "/redirect", :action => "redirect"
webrat.root :action => "form"
end
end

View File

@ -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

View File

@ -115,7 +115,7 @@ describe Webrat::Session do
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, {})

View File

@ -33,7 +33,7 @@ describe "visit" do
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")