Skip to content

Bug in blank attribute detection w/o column backing #77

Open
@chrisarcand

Description

@chrisarcand

attribute_blank = if attributes.has_key?(attribute)
column = self.class.columns_hash[attribute]
if column && column.type == :boolean
attributes[attribute].nil?
else
attributes[attribute].blank?
end
elsif respond_to?(attribute)
send(attribute).nil?
else
instance_variable_get("@#{attribute}").nil?
end

The above code has a few more edge cases that are missed, specifically with the second two cases in the outer conditional where the attribute is not backed by a database column. The next two cases must account for the same issue (attribute can either be a boolean where false is not 'blank', it's a set value, but false.nil? == true, or a collection that is empty via blank?).

This whole thing should be cleaned up, with perhaps a few comments explaining each case.

See d155ba7#commitcomment-30274475

cc/ @romaind

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions