diff --git a/lib/devise/authenticable.rb b/lib/devise/authenticable.rb index c6e6cf06..db48726d 100644 --- a/lib/devise/authenticable.rb +++ b/lib/devise/authenticable.rb @@ -74,8 +74,8 @@ module Devise # authenticated user if it's valid or nil # def authenticate(email, password) - user = self.find_by_email(email) - user if user.valid_password?(password) unless user.nil? + authenticable = self.find_by_email(email) + authenticable if authenticable.valid_password?(password) unless authenticable.nil? end end end diff --git a/lib/devise/confirmable.rb b/lib/devise/confirmable.rb index 5b1e730a..96a83db7 100644 --- a/lib/devise/confirmable.rb +++ b/lib/devise/confirmable.rb @@ -41,13 +41,13 @@ module Devise # If no user is found, returns a new user # If the user is already confirmed, create an error for the user def find_and_confirm(confirmation_token) - user = find_or_initialize_by_confirmation_token(confirmation_token) - unless user.new_record? - user.confirm! + confirmable = find_or_initialize_by_confirmation_token(confirmation_token) + unless confirmable.new_record? + confirmable.confirm! else - user.errors.add(:confirmation_token, :invalid, :default => "invalid confirmation") + confirmable.errors.add(:confirmation_token, :invalid, :default => "invalid confirmation") end - user + confirmable end end end diff --git a/test/authenticable_test.rb b/test/authenticable_test.rb index 364b5e48..cb7af84e 100644 --- a/test/authenticable_test.rb +++ b/test/authenticable_test.rb @@ -91,7 +91,7 @@ class AuthenticableTest < ActiveSupport::TestCase end test 'should encrypt password using a sha1 hash' do - digest_key = Devise::Authenticable::SECURE_AUTH_SITE_KEY = 'digest_key' + digest_key = Devise::Authenticable::SECURE_AUTH_SITE_KEY user = create_user expected_password = ::Digest::SHA1.hexdigest("--#{user.password_salt}--#{digest_key}--#{12345}--") assert_equal expected_password, user.encrypted_password @@ -103,7 +103,7 @@ class AuthenticableTest < ActiveSupport::TestCase assert_not user.valid_password?('54321') end - test 'should authenticate a valid user and return it' do + test 'should authenticate a valid user with email and password and return it' do user = create_user authenticated_user = User.authenticate('test@email.com', '12345') assert_equal authenticated_user, user diff --git a/test/test_helper.rb b/test/test_helper.rb index 56a59930..492cdfd5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -14,7 +14,7 @@ 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 + t.string :confirmation_token, :null => false t.datetime :confirmed_at end end