From d4f775ca9cbf3b874448d3c15b5a8635f2d7d432 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Wed, 5 Nov 2008 18:06:11 -0500 Subject: [PATCH] Refactoring rails session --- lib/webrat/rails.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/webrat/rails.rb b/lib/webrat/rails.rb index 8fc0bbf..a84d707 100644 --- a/lib/webrat/rails.rb +++ b/lib/webrat/rails.rb @@ -17,23 +17,19 @@ module Webrat end def get(url, data, headers = nil) - update_protocol(url) - @integration_session.get_via_redirect(remove_protocol(url), data, headers) + do_request(:get, url, data, headers) end def post(url, data, headers = nil) - update_protocol(url) - @integration_session.post_via_redirect(remove_protocol(url), data, headers) + do_request(:post, url, data, headers) end def put(url, data, headers = nil) - update_protocol(url) - @integration_session.put_via_redirect(remove_protocol(url), data, headers) + do_request(:delete, url, data, headers) end def delete(url, data, headers = nil) - update_protocol(url) - @integration_session.delete_via_redirect(remove_protocol(url), data, headers) + do_request(:delete, url, data, headers) end def response_body @@ -45,6 +41,11 @@ module Webrat end protected + + def do_request(http_method, url, data, headers) + update_protocol(url) + @integration_session.request_via_redirect(http_method, remove_protocol(url), data, headers) + end def remove_protocol(href) if href =~ %r{^https?://www.example.com(/.*)}