Adding hook to authenticate method for testing if a user is already confirmed.
This commit is contained in:
parent
3e6d1ffe43
commit
673fe04eca
|
@ -46,10 +46,10 @@ module Devise
|
|||
# Hook default authenticate to provide test whether the account is confirmed
|
||||
# Returns the authenticated_user if it's confirmed, otherwise returns nil
|
||||
# TODO
|
||||
#def authenticate(email, password)
|
||||
# confirmable = super
|
||||
# confirmable if confirmable.confirmed? unless confirmable.nil?
|
||||
#end
|
||||
def authenticate(email, password)
|
||||
confirmable = super
|
||||
confirmable if confirmable.confirmed? unless confirmable.nil?
|
||||
end
|
||||
|
||||
# Find a user by it's confirmation token and try to confirm it.
|
||||
# If no user is found, returns a new user
|
||||
|
|
|
@ -2,6 +2,10 @@ require 'test_helper'
|
|||
|
||||
class ConfirmableTest < ActiveSupport::TestCase
|
||||
|
||||
def setup
|
||||
User.send :include, ::Devise::Confirmable
|
||||
end
|
||||
|
||||
test 'should not have confirmation code accessible' do
|
||||
assert_not field_accessible?(:confirmation_token)
|
||||
end
|
||||
|
@ -88,24 +92,24 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
assert confirmed_user.errors[:email]
|
||||
end
|
||||
|
||||
# test 'should not authenticate a user not confirmed' do
|
||||
# user = create_user
|
||||
# authenticated_user = User.authenticate(user.email, user.password)
|
||||
# assert_nil authenticated_user
|
||||
# end
|
||||
|
||||
# test 'should authenticate a confirmed user' do
|
||||
# user = create_user
|
||||
# user.confirm!
|
||||
# authenticated_user = User.authenticate(user.email, user.password)
|
||||
# assert_not_nil authenticated_user
|
||||
# assert_equal authenticated_user, user
|
||||
# end
|
||||
|
||||
test 'should send confirmation instructions by email' do
|
||||
assert_difference 'ActionMailer::Base.deliveries.size' do
|
||||
create_user
|
||||
end
|
||||
test 'should not authenticate a user not confirmed' do
|
||||
user = create_user
|
||||
authenticated_user = User.authenticate(user.email, user.password)
|
||||
assert_nil authenticated_user
|
||||
end
|
||||
|
||||
test 'should authenticate a confirmed user' do
|
||||
user = create_user
|
||||
user.confirm!
|
||||
authenticated_user = User.authenticate(user.email, user.password)
|
||||
assert_not_nil authenticated_user
|
||||
assert_equal authenticated_user, user
|
||||
end
|
||||
|
||||
# test 'should send confirmation instructions by email' do
|
||||
# assert_difference 'ActionMailer::Base.deliveries.size' do
|
||||
# create_user
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,14 +16,13 @@ ActiveRecord::Schema.define(:version => 1) do
|
|||
t.string :email, :null => false
|
||||
t.string :encrypted_password, :null => false
|
||||
t.string :password_salt, :null => false
|
||||
t.string :confirmation_token, :null => false
|
||||
t.string :confirmation_token
|
||||
t.datetime :confirmed_at
|
||||
end
|
||||
end
|
||||
|
||||
class User < ::ActiveRecord::Base
|
||||
include ::Devise::Authenticable
|
||||
include ::Devise::Confirmable
|
||||
end
|
||||
|
||||
ActionMailer::Base.delivery_method = :test
|
||||
|
|
Loading…
Reference in New Issue