Refactoring rails session

This commit is contained in:
Bryan Helmkamp 2008-11-05 18:06:11 -05:00
parent ce9235f0fa
commit d4f775ca9c

View File

@ -17,23 +17,19 @@ module Webrat
end end
def get(url, data, headers = nil) def get(url, data, headers = nil)
update_protocol(url) do_request(:get, url, data, headers)
@integration_session.get_via_redirect(remove_protocol(url), data, headers)
end end
def post(url, data, headers = nil) def post(url, data, headers = nil)
update_protocol(url) do_request(:post, url, data, headers)
@integration_session.post_via_redirect(remove_protocol(url), data, headers)
end end
def put(url, data, headers = nil) def put(url, data, headers = nil)
update_protocol(url) do_request(:delete, url, data, headers)
@integration_session.put_via_redirect(remove_protocol(url), data, headers)
end end
def delete(url, data, headers = nil) def delete(url, data, headers = nil)
update_protocol(url) do_request(:delete, url, data, headers)
@integration_session.delete_via_redirect(remove_protocol(url), data, headers)
end end
def response_body def response_body
@ -46,6 +42,11 @@ module Webrat
protected 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) def remove_protocol(href)
if href =~ %r{^https?://www.example.com(/.*)} if href =~ %r{^https?://www.example.com(/.*)}
$LAST_MATCH_INFO.captures.first $LAST_MATCH_INFO.captures.first