Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chrisarcand opened this issue Aug 24, 2018 · 2 comments
Open

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

chrisarcand opened this issue Aug 24, 2018 · 2 comments
Labels

Comments

@chrisarcand
Copy link
Contributor

chrisarcand commented Aug 24, 2018

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

@romaind
Copy link

romaind commented Aug 27, 2018

@chrisarcand thanks a lot for taking what I mentionned into account.
I'll do some thinking and try to come up with a solution in the upcoming week

@romaind
Copy link

romaind commented Aug 29, 2018

@chrisarcand currently working on that
it seems you've not tested the false.nil? case as replacing nil? with blank? line 167 doesn't break tests
I'll add that.
Or maybe you did, but weird that the tests don't break then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants