Skip to content

Instantly share code, notes, and snippets.

@dsabanin
Created May 12, 2009 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsabanin/110550 to your computer and use it in GitHub Desktop.
Save dsabanin/110550 to your computer and use it in GitHub Desktop.
# Mocks a request to OpenID server with given response status.
# If you give it a hash of args as a third argument, it will act
# like information about user transmitted from OpenID server.
class ActiveSupport::TestCase
# Example:
# mock_openid_response("http://identity.url", OpenID::Consumer::SUCCESS,
# 'fullname' => 'Joe Black',
# 'email' => 'joe.black@gmail.com',
# 'nickname' => 'joeeeey')
# # naming of the params is important - we're emulating request made by OpenID server
# post :create, :openid_identifier => "http://identity.url",
# :open_id_complete => true
def mock_openid_response(identity_url, status, user_data={})
response = stub(:status => status, :display_identifier => identity_url)
@controller.stubs(:timeout_protection_from_identity_server).returns(response)
# Mock data response from openid server with login info
[ OpenID::SReg::Response, OpenID::AX::FetchResponse ].each do |data_response|
resp = stub(:data => user_data)
data_response.stubs(:from_success_response).returns(resp)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment