Refactor a bit to avoid two model attributes lookup

Tidy up tests a bit.
This commit is contained in:
Carlos Antonio da Silva 2012-12-04 17:37:12 -02:00
parent e80e0c9a89
commit 2261005ed5
4 changed files with 10 additions and 19 deletions

View File

@ -172,11 +172,7 @@ module Devise
end
def apply_to_attribute_or_variable(attr, method)
if self[attr]
self[attr].try(method)
else
send(attr).try(method)
end
(self[attr] || send(attr)).try(method)
end
module ClassMethods
@ -207,7 +203,7 @@ module Devise
# it may be wrapped as well. For instance, database authenticatable
# provides a `find_for_database_authentication` that wraps a call to
# this method. This allows you to customize both database authenticatable
# or the whole authenticate stack by customize `find_for_authentication.`
# or the whole authenticate stack by customize `find_for_authentication.`
#
# Overwrite to add customized conditions, create a join, or maybe use a
# namedscope to filter records while authenticating.

View File

@ -14,18 +14,18 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
end
test 'should downcase case insensitive keys that refer to virtual attributes when saving' do
email = 'Foo@Bar1.com'
email = 'Foo@Bar1.com'
confirmation = 'Foo@Bar1.com'
pw = '12345678'
user = UserWithVirtualAttributes.new(
:email => email,
:email_confirmation => confirmation,
:password => pw,
:password_confirmation => pw)
attributes = valid_attributes(:email => email, :email_confirmation => confirmation)
assert_nothing_raised "ActiveRecord::RecordInvalid" do
user = UserWithVirtualAttributes.new(attributes)
assert_equal confirmation, user.email_confirmation
assert_nothing_raised ActiveRecord::RecordInvalid do
user.save!
end
assert_equal confirmation.downcase, user.email_confirmation
end
test 'should remove whitespace from strip whitespace keys when saving' do

View File

@ -29,10 +29,6 @@ class ActiveSupport::TestCase
:password_confirmation => '12345678' }.update(attributes)
end
def new_user_with_class(klass=User, attributes={})
klass.new(valid_attributes(attributes))
end
def new_user(attributes={})
User.new(valid_attributes(attributes))
end

View File

@ -25,4 +25,3 @@ end
class Inheritable < Admin
end