railsmonk (owner)

Revisions

gist: 110550 Download_button fork
public
Public Clone URL: git://gist.github.com/110550.git
Embed All Files: show embed
rails_mock_openid_request.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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