Add authentication_keys.

This commit is contained in:
José Valim
2009-11-15 03:31:13 -02:00
parent dbe0b48bca
commit b70b293690
11 changed files with 76 additions and 35 deletions

View File

@@ -76,6 +76,13 @@ class AuthenticationTest < ActionController::IntegrationTest
assert_contain 'Welcome Admin'
end
test 'sign in as user should not authenticate if not using proper authentication keys' do
swap Devise, :authentication_keys => [:username] do
sign_in_as_user
assert_not warden.authenticated?(:user)
end
end
test 'admin signing in with invalid email should return to sign in form with error message' do
sign_in_as_admin do
fill_in 'email', :with => 'wrongemail@test.com'

View File

@@ -127,4 +127,22 @@ class AuthenticatableTest < ActiveSupport::TestCase
authenticated_user = User.authenticate(:email => user.email, :password => 'another_password')
assert_nil authenticated_user
end
test 'should use authentication keys to retrieve users' do
swap Devise, :authentication_keys => [:username] do
user = create_user(:username => "josevalim")
assert_nil User.authenticate(:email => user.email, :password => user.password)
assert_not_nil User.authenticate(:username => user.username, :password => user.password)
end
end
test 'should serialize user into session' do
user = create_user
assert_equal [User, user.id], User.serialize_into_session(user)
end
test 'should serialize user from session' do
user = create_user
assert_equal user.id, User.serialize_from_session([User, user.id]).id
end
end

View File

@@ -18,6 +18,7 @@ ActiveRecord::Schema.define(:version => 1) do
[:users, :admins].each do |table|
create_table table do |t|
t.authenticatable :null => table == :admins
t.string :username if table == :users
if table == :users
t.confirmable