Refactor a bit to avoid two model attributes lookup
Tidy up tests a bit.
This commit is contained in:
parent
e80e0c9a89
commit
2261005ed5
|
@ -172,11 +172,7 @@ module Devise
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_to_attribute_or_variable(attr, method)
|
def apply_to_attribute_or_variable(attr, method)
|
||||||
if self[attr]
|
(self[attr] || send(attr)).try(method)
|
||||||
self[attr].try(method)
|
|
||||||
else
|
|
||||||
send(attr).try(method)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
@ -207,7 +203,7 @@ module Devise
|
||||||
# it may be wrapped as well. For instance, database authenticatable
|
# it may be wrapped as well. For instance, database authenticatable
|
||||||
# provides a `find_for_database_authentication` that wraps a call to
|
# provides a `find_for_database_authentication` that wraps a call to
|
||||||
# this method. This allows you to customize both database authenticatable
|
# 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
|
# Overwrite to add customized conditions, create a join, or maybe use a
|
||||||
# namedscope to filter records while authenticating.
|
# namedscope to filter records while authenticating.
|
||||||
|
|
|
@ -14,18 +14,18 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'should downcase case insensitive keys that refer to virtual attributes when saving' do
|
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'
|
confirmation = 'Foo@Bar1.com'
|
||||||
pw = '12345678'
|
attributes = valid_attributes(:email => email, :email_confirmation => confirmation)
|
||||||
user = UserWithVirtualAttributes.new(
|
|
||||||
:email => email,
|
|
||||||
:email_confirmation => confirmation,
|
|
||||||
:password => pw,
|
|
||||||
:password_confirmation => pw)
|
|
||||||
|
|
||||||
assert_nothing_raised "ActiveRecord::RecordInvalid" do
|
user = UserWithVirtualAttributes.new(attributes)
|
||||||
|
assert_equal confirmation, user.email_confirmation
|
||||||
|
|
||||||
|
assert_nothing_raised ActiveRecord::RecordInvalid do
|
||||||
user.save!
|
user.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_equal confirmation.downcase, user.email_confirmation
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'should remove whitespace from strip whitespace keys when saving' do
|
test 'should remove whitespace from strip whitespace keys when saving' do
|
||||||
|
|
|
@ -29,10 +29,6 @@ class ActiveSupport::TestCase
|
||||||
:password_confirmation => '12345678' }.update(attributes)
|
:password_confirmation => '12345678' }.update(attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_user_with_class(klass=User, attributes={})
|
|
||||||
klass.new(valid_attributes(attributes))
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_user(attributes={})
|
def new_user(attributes={})
|
||||||
User.new(valid_attributes(attributes))
|
User.new(valid_attributes(attributes))
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,4 +25,3 @@ end
|
||||||
|
|
||||||
class Inheritable < Admin
|
class Inheritable < Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue