Skip to content

Instantly share code, notes, and snippets.

@boblin
Created March 27, 2009 10:16
Show Gist options
  • Save boblin/86629 to your computer and use it in GitHub Desktop.
Save boblin/86629 to your computer and use it in GitHub Desktop.
shoulda + webrat + authlogic (+ OpenID)
# originaly from: http://209.85.129.132/search?q=cache:xI4xvFsZlWgJ:www.northpub.com/articles/2007/04/02/testing-openid-support+rails+mocks&cd=3
module OpenIdAuthentication
protected
def authenticate_with_open_id(identity_url = params[:openid_url], fields = {}) #:doc:
# identity_url = normalize_url(identity_url)
if User.find_by_openid_identifier(identity_url)
yield Result[:successful], identity_url
else
logger.info "OpenID authentication failed: #{identity_url}"
yield Result[:failed], identity_url, nil
end
end
end
require File.dirname(__FILE__) + '/../test_helper'
class SignupTest < ActionController::IntegrationTest
context 'User' do
setup do
@user = Factory(:user)
end
should 'be able to login with a valid OpenID' do
visit '/'
assert_equal '/user_session/new', path
fill_in 'OpenID', :with => @user.openid_identifier
click_button 'Login'
assert_equal '/', path
assert_equal 'Wellcome!', flash[:notice]
end
should 'be denied access with an invalid OpenID' do
visit '/'
assert_equal '/user_session/new', path
fill_in 'OpenID', :with => "https://bad_openid_identifier.com"
click_button 'Login'
assert_equal '/user_session', path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment