Added support for HTTP_REFERER header, so that redirect_to :back works

This commit is contained in:
Hendrik Volkmer 2008-08-20 10:35:57 +02:00
parent 206e65b92f
commit e193110a91
4 changed files with 30 additions and 11 deletions

View File

@ -54,7 +54,11 @@ module Webrat
def request_page(url, http_method, data) def request_page(url, http_method, data)
debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect}" debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect}"
send "#{http_method}", url, data || {} if @current_url
send "#{http_method}", url, data || {}, {"HTTP_REFERER" => @current_url}
else
send "#{http_method}", url, data || {}
end
save_and_open_page if exception_caught? save_and_open_page if exception_caught?
flunk("Page load was not successful (Code: #{response_code.inspect})") unless success_code? flunk("Page load was not successful (Code: #{response_code.inspect})") unless success_code?

View File

@ -14,24 +14,24 @@ module Webrat
File.expand_path(File.join(RAILS_ROOT, "tmp")) File.expand_path(File.join(RAILS_ROOT, "tmp"))
end end
def get(url, data) def get(url, data, headers = nil)
update_protocol(url) update_protocol(url)
@integration_session.get_via_redirect(url, data) @integration_session.get_via_redirect(url, data, headers)
end end
def post(url, data) def post(url, data, headers = nil)
update_protocol(url) update_protocol(url)
@integration_session.post_via_redirect(url, data) @integration_session.post_via_redirect(url, data, headers)
end end
def put(url, data) def put(url, data, headers = nil)
update_protocol(url) update_protocol(url)
@integration_session.put_via_redirect(url, data) @integration_session.put_via_redirect(url, data, headers)
end end
def delete(url, data) def delete(url, data, headers = nil)
update_protocol(url) update_protocol(url)
@integration_session.delete_via_redirect(url, data) @integration_session.delete_via_redirect(url, data, headers)
end end
def response_body def response_body

View File

@ -6,8 +6,9 @@ describe "reloads" do
@session.response_body = "Hello world" @session.response_body = "Hello world"
end end
it "should reload the page" do it "should reload the page with http referer" do
@session.should_receive(:get).with("/", {}).twice @session.should_receive(:get).with("/", {})
@session.should_receive(:get).with("/", {}, {"HTTP_REFERER"=>"/"})
@session.visits("/") @session.visits("/")
@session.reloads @session.reloads
end end

View File

@ -20,3 +20,17 @@ describe "visits" do
lambda { @session.fills_in "foo", :with => "blah" }.should raise_error lambda { @session.fills_in "foo", :with => "blah" }.should raise_error
end end
end end
describe "visits with referer" do
before do
@session = Webrat::TestSession.new
@session.instance_variable_set(:@current_url, "/old_url")
@session.response_body = "Hello world"
end
it "should use get with referer header" do
@session.should_receive(:get).with("/", {}, {"HTTP_REFERER" => "/old_url"})
@session.visits("/")
end
end