diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 157ed39..ecf243c 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -54,7 +54,11 @@ module Webrat def request_page(url, http_method, data) 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? flunk("Page load was not successful (Code: #{response_code.inspect})") unless success_code? diff --git a/lib/webrat/rails/rails_session.rb b/lib/webrat/rails/rails_session.rb index 9c2e125..0412888 100644 --- a/lib/webrat/rails/rails_session.rb +++ b/lib/webrat/rails/rails_session.rb @@ -14,24 +14,24 @@ module Webrat File.expand_path(File.join(RAILS_ROOT, "tmp")) end - def get(url, data) + def get(url, data, headers = nil) update_protocol(url) - @integration_session.get_via_redirect(remove_protocol(url), data) + @integration_session.get_via_redirect(remove_protocol(url), data, headers) end - def post(url, data) + def post(url, data, headers = nil) update_protocol(url) - @integration_session.post_via_redirect(remove_protocol(url), data) + @integration_session.post_via_redirect(remove_protocol(url), data, headers) end - def put(url, data) + def put(url, data, headers = nil) update_protocol(url) - @integration_session.put_via_redirect(remove_protocol(url), data) + @integration_session.put_via_redirect(remove_protocol(url), data, headers) end - def delete(url, data) + def delete(url, data, headers = nil) update_protocol(url) - @integration_session.delete_via_redirect(remove_protocol(url), data) + @integration_session.delete_via_redirect(remove_protocol(url), data, headers) end def response_body diff --git a/spec/api/reloads_spec.rb b/spec/api/reloads_spec.rb index 588095d..b0741ca 100644 --- a/spec/api/reloads_spec.rb +++ b/spec/api/reloads_spec.rb @@ -6,8 +6,9 @@ describe "reloads" do @session.response_body = "Hello world" end - it "should reload the page" do - @session.should_receive(:get).with("/", {}).twice + it "should reload the page with http referer" do + @session.should_receive(:get).with("/", {}) + @session.should_receive(:get).with("/", {}, {"HTTP_REFERER"=>"/"}) @session.visits("/") @session.reloads end diff --git a/spec/api/visits_spec.rb b/spec/api/visits_spec.rb index f14c903..df1ccb4 100644 --- a/spec/api/visits_spec.rb +++ b/spec/api/visits_spec.rb @@ -20,3 +20,17 @@ describe "visits" do lambda { @session.fills_in "foo", :with => "blah" }.should raise_error 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 \ No newline at end of file