diff options
author | Jacob Green <jacob@nationbuilder.com> | 2012-03-06 22:32:29 -0800 |
---|---|---|
committer | Jacob Green <jacob@nationbuilder.com> | 2012-03-06 22:32:29 -0800 |
commit | 04aca254cc927663c9f53560bbe0d0b680194c5e (patch) | |
tree | 582f2550abdd63fbdab4b3e5ab4dd5365fbc32fd /activerecord | |
parent | d87ec9d3108afda28a5744d0b7edd328c3c284d1 (diff) | |
download | rails-04aca254cc927663c9f53560bbe0d0b680194c5e.tar.gz rails-04aca254cc927663c9f53560bbe0d0b680194c5e.tar.bz2 rails-04aca254cc927663c9f53560bbe0d0b680194c5e.zip |
attribute_present? should return false for empty strings
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 3e27e85f02..93c243e7b1 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -189,7 +189,7 @@ module ActiveRecord # nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings). def attribute_present?(attribute) value = read_attribute(attribute) - !value.nil? || (value.respond_to?(:empty?) && !value.empty?) + !value.nil? && !(value.respond_to?(:empty?) && value.empty?) end # Returns the column object for the named attribute. diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 23bdb09514..ef01476ae4 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -30,9 +30,12 @@ class AttributeMethodsTest < ActiveRecord::TestCase t = Topic.new t.title = "hello there!" t.written_on = Time.now + t.author_name = "" assert t.attribute_present?("title") assert t.attribute_present?("written_on") assert !t.attribute_present?("content") + assert !t.attribute_present?("author_name") + end def test_attribute_present_with_booleans |