diff options
author | José Valim <jose.valim@gmail.com> | 2012-03-07 07:03:59 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-03-07 07:03:59 -0800 |
commit | 3da31b948f0e9af07e503d955f27ffd5d91c84cb (patch) | |
tree | 9dbefd78321e47286a16b5fb8037a722d8d392da /activerecord | |
parent | 7638004d7d23df668ec33a3c570b7865e0d06a06 (diff) | |
parent | 04aca254cc927663c9f53560bbe0d0b680194c5e (diff) | |
download | rails-3da31b948f0e9af07e503d955f27ffd5d91c84cb.tar.gz rails-3da31b948f0e9af07e503d955f27ffd5d91c84cb.tar.bz2 rails-3da31b948f0e9af07e503d955f27ffd5d91c84cb.zip |
Merge pull request #5316 from Jacobkg/master
Update ActiveRecord::AttributeMethods#attribute_present? to 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 |