mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Add authentication_keys.
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user