Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #5316 from Jacobkg/master

Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings
  • Loading branch information...
commit 3da31b948f0e9af07e503d955f27ffd5d91c84cb 2 parents 7638004 + 04aca25
@josevalim josevalim authored
View
2  activerecord/lib/active_record/attribute_methods.rb
@@ -189,7 +189,7 @@ def attribute_for_inspect(attr_name)
# 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.
View
3  activerecord/test/cases/attribute_methods_test.rb
@@ -30,9 +30,12 @@ def test_attribute_present
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
Please sign in to comment.
Something went wrong with that request. Please try again.