Skip to content

Instantly share code, notes, and snippets.

@emk
Created December 28, 2008 05:14
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 emk/40381 to your computer and use it in GitHub Desktop.
Save emk/40381 to your computer and use it in GitHub Desktop.
class User
class << self
def authenticate_for_with_ldap(site, login, password)
user = authenticate_for_without_ldap(site, login, password)
if user.nil?
# Look in LDAP for login, create a local user, and return it.
end
user
end
alias_method_chain :authenticate_for, :ldap
end
end
class UserLdapTest << ActiveSupport::TestCase
test "should use LDAP data to create missing local users" do
assert_nil User.find_by_login('sam')
# Mock LDAP interface to return user 'sam' with password 'foo'.
assert_difference 'User.count', 1 do
User.authenticate_for sites(:first), 'sam', 'foo'
end
@sam = User.find_by_login('sam')
# Make sure sam has the expected properties.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment