Rails and Merb integration tests for following redirects
This commit is contained in:
parent
e77495bc04
commit
e19b1cc323
@ -110,7 +110,7 @@ For example:
|
|||||||
@http_method = http_method
|
@http_method = http_method
|
||||||
@data = data
|
@data = data
|
||||||
|
|
||||||
request_page(response.location, :get, data) if redirect?
|
request_page(response.headers["Location"], :get, data) if redirect?
|
||||||
|
|
||||||
return response
|
return response
|
||||||
end
|
end
|
||||||
|
@ -42,11 +42,6 @@ module Webrat
|
|||||||
:params => (data && data.any?) ? data : nil,
|
:params => (data && data.any?) ? data : nil,
|
||||||
:headers => headers,
|
:headers => headers,
|
||||||
:method => method)
|
:method => method)
|
||||||
follow_redirect
|
|
||||||
end
|
|
||||||
|
|
||||||
def follow_redirect
|
|
||||||
self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -59,10 +54,6 @@ module Merb #:nodoc:
|
|||||||
@_webrat_session ||= Webrat::MerbSession.new
|
@_webrat_session ||= Webrat::MerbSession.new
|
||||||
@_webrat_session.response = @_webrat_session.request(uri, env)
|
@_webrat_session.response = @_webrat_session.request(uri, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow_redirect
|
|
||||||
@_webrat_session.follow_redirect
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,4 +7,8 @@ class Testing < Application
|
|||||||
def submit_form
|
def submit_form
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect_to_root
|
||||||
|
redirect "/"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -28,4 +28,5 @@
|
|||||||
Merb.logger.info("Compiling routes...")
|
Merb.logger.info("Compiling routes...")
|
||||||
Merb::Router.prepare do
|
Merb::Router.prepare do
|
||||||
match("/").to(:controller => "testing", :action => "show_form")
|
match("/").to(:controller => "testing", :action => "show_form")
|
||||||
|
match("/redirect").to(:controller => "testing", :action => "redirect_to_root")
|
||||||
end
|
end
|
@ -14,4 +14,8 @@ describe "Webrat" do
|
|||||||
click_button "Test"
|
click_button "Test"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should follow redirects" do
|
||||||
|
response = visit "/redirect"
|
||||||
|
response.should contain("Webrat Form")
|
||||||
|
end
|
||||||
end
|
end
|
@ -7,4 +7,8 @@ class WebratController < ApplicationController
|
|||||||
render :text => "OK"
|
render :text => "OK"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect
|
||||||
|
redirect_to :submit
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -1,6 +1,8 @@
|
|||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
map.with_options :controller => "webrat" do |webrat|
|
map.with_options :controller => "webrat" do |webrat|
|
||||||
webrat.submit "/submit", :action => "submit"
|
webrat.submit "/submit", :action => "submit"
|
||||||
|
webrat.redirect "/redirect", :action => "redirect"
|
||||||
|
|
||||||
webrat.root :action => "form"
|
webrat.root :action => "form"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,4 +14,9 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
select "January"
|
select "January"
|
||||||
click_button "Test"
|
click_button "Test"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should follow redirects" do
|
||||||
|
visit redirect_path
|
||||||
|
assert response.body.include?("OK")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -115,7 +115,7 @@ describe Webrat::Session do
|
|||||||
|
|
||||||
it "should follow redirects" do
|
it "should follow redirects" do
|
||||||
webrat_session.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.response.should_receive(:headers).once.and_return({ "Location" => "/newurl" })
|
||||||
|
|
||||||
webrat_session.request_page("/oldurl", :get, {})
|
webrat_session.request_page("/oldurl", :get, {})
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ describe "visit" do
|
|||||||
|
|
||||||
it "should follow redirects" do
|
it "should follow redirects" do
|
||||||
webrat_session.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.response.should_receive(:headers).once.and_return({ "Location" => "/newurl" })
|
||||||
|
|
||||||
visit("/oldurl")
|
visit("/oldurl")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user