Skip to content

Association has a truthy value when it is nil  #315

@vbalazs

Description

@vbalazs

When I have an association and I return with nil in my API then the Her association will has a truthy value but it's clearly nil. This caused problems when I tried to use this in a condition.

I created a failing spec, you can find it here as a patch (you get the idea):
https://gist.github.com/vbalazs/87e6991347baff4d8907

so using an association in a condition gives a surprising result:

if subject
  fail # shouldn't reach this
else
  pass
end

As well as

subject
=> nil
subject.class
=> NilClass
subject ? 1 : 0
=> 1 # wut? :)

As a workaround, I called .nil? on it and use that way but I think it would be worth fixing it. I tried to look into it but I lost myself around the proxy objects 😕

Tested against v0.7.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions