Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor a bit to avoid two model attributes lookup

Tidy up tests a bit.
  • Loading branch information...
commit 2261005ed506df251073a6b1e4eee7f29cdfe6f0 1 parent e80e0c9
@carlosantoniodasilva carlosantoniodasilva authored
View
8 lib/devise/models/authenticatable.rb
@@ -172,11 +172,7 @@ def strip_whitespace
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 @@ def http_authenticatable?(strategy)
# 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
18 test/models/database_authenticatable_test.rb
@@ -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)
-
- assert_nothing_raised "ActiveRecord::RecordInvalid" do
+ attributes = valid_attributes(:email => email, :email_confirmation => confirmation)
+
+ 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
4 test/support/helpers.rb
@@ -29,10 +29,6 @@ def valid_attributes(attributes={})
: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
1  test/test_models.rb
@@ -25,4 +25,3 @@ class Several < Admin
class Inheritable < Admin
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.