Joe Van Dyk
2008-Apr-16 01:09 UTC
[rspec-users] Writing a story for logging in with OpenID
So I added OpenID to my application (via the openid plugin). But I''m having troubles writing the story for it -- specifically, how to mock the openid calls. Anyone got any quick pointers?
This is a rather open ended question, Joe. You might want to get a little more detailed. Would you happen to have any code to paste or a specific problem? I think you might have a tough time finding someone who has written specific mocks around the openid calls. On Apr 15, 2008, at 8:09 PM, Joe Van Dyk wrote:> So I added OpenID to my application (via the openid plugin). But I''m > having troubles writing the story for it -- specifically, how to mock > the openid calls. > > Anyone got any quick pointers? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Joe Van Dyk
2008-Apr-17 18:13 UTC
[rspec-users] Writing a story for logging in with OpenID
I found this on the internet somewhere, forgot where:
odule OpenIdAuthentication
EXTENSION_FIELDS = {''email'' => ''user at
somedomain.com'',
''nickname'' => ''cool_user'',
''country'' => ''US'',
''postcode'' => ''12345'',
''fullname'' => ''Cool User'',
''dob'' => ''1970-04-01'',
''language'' => ''en'',
''timezone'' => ''America/New_York''}
protected
def authenticate_with_open_id(identity_url = params[:openid_url],
fields = {}) #:doc:
identity_url = normalize_url(identity_url)
if User.find_by_identity_url(identity_url) ||
identity_url.include?(''good'')
# Don''t process registration fields unless it is requested.
unless identity_url.include?(''blank'') ||
(fields[:required].nil?
&& fields[:optional].nil?)
extension_response_fields = {}
# fields[:required].each do |field|
# extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
# end
fields[:optional].each do |field|
extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
end
end
yield Result[:successful], identity_url , extension_response_fields
else
logger.info "OpenID authentication failed: #{identity_url}"
yield Result[:failed], identity_url, nil
end
end
private
def add_simple_registration_fields(open_id_response, fields)
open_id_response.add_extension_arg(''sreg'',
''required'', [
fields[:required] ].flatten * '','') if fields[:required]
open_id_response.add_extension_arg(''sreg'',
''optional'', [
fields[:optional] ].flatten * '','') if fields[:optional]
end
end
Seemed to do the trick.
On Tue, Apr 15, 2008 at 9:50 PM, Bryan Ray <bryansray at gmail.com>
wrote:> This is a rather open ended question, Joe. You might want to get a
> little more detailed.
>
> Would you happen to have any code to paste or a specific problem? I
> think you might have a tough time finding someone who has written
> specific mocks around the openid calls.
>
>
>
> On Apr 15, 2008, at 8:09 PM, Joe Van Dyk wrote:
>
> > So I added OpenID to my application (via the openid plugin). But
I''m
> > having troubles writing the story for it -- specifically, how to mock
> > the openid calls.
> >
> > Anyone got any quick pointers?
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>