Created
December 19, 2008 20:01
-
-
Save Peeja/38097 to your computer and use it in GitHub Desktop.
stub_request: Catch requests to other domains in an integration test. Could use some features, but it's good enough for me right now.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActionController::Integration::Session | |
# Intercepts a request to a foreign domain. Use this to stub | |
# a service which the user is bounced through, such as an | |
# OpenID provider. The block should return a new URL to | |
# request. This is the URL which the foreign service would | |
# redirect the browser to if we were really using it. | |
# | |
# Currently, the return URL can only be requested with a GET. | |
# | |
# stub_request 'foreign.host.com' do |path| | |
# return_from_bounce_url | |
# end | |
def stub_request(host, &block) | |
@request_stubs ||= {} | |
@request_stubs[host] = block | |
end | |
def process_with_stubs(method, path, parameters = nil, headers = nil) | |
@request_stubs ||= {} | |
if @request_stubs.key? self.host | |
url = @request_stubs[host].call(path) | |
process_without_stubs(method, url, parameters, headers) | |
else | |
process_without_stubs(method, path, parameters, headers) | |
end | |
end | |
alias_method_chain :process, :stubs | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment