ActiveRecord.attribute_present? returns false for boolean values that are present but false #1613

Closed
schmickie opened this Issue Jun 9, 2011 · 1 comment

Projects

None yet

3 participants

@schmickie

The ActiveRecord.attribute_present? method reads the attribute then returns value.blank? This is not a correct implementation for boolean values. The blank? method returns true if a boolean value is false. Thus, attribute_present? incorrectly returns false for boolean values that are present but false.

@bcobb

The method's documentation reads:

  # Returns true if the specified +attribute+ has been set by the user or by a database load and is neither
  # nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings).

Note "and is neither nil nor empty?" So: are false values and string values are equally "present?"

@jonleighton jonleighton pushed a commit that closed this issue Nov 6, 2011
@jmazzi jmazzi Update ActiveRecord#attribute_present? to work as documented
"Returns true if the specified attribute has been set by the user or by
a database load and is neither nil nor empty?"

Fixes #1613
c7d2078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment