paulelliott/fabrication — Issue #80: nil associations evaluate to true
Author: flipsasser
Created: 2012-01-06 21:55:02+00:00
State: open

I have a before_create hook that looks like this:

```ruby
if address && address.new_record?
address.user = self.user
end
```

Unfortunately, the first part, `if address` evaluates as true. If I remove the second part of the statement and do something like:

```ruby
if address
puts "#{address.inspect} - #{address.class.inspect} - #{{address.methods - ActiveRecord::Base).methods.inspect}"
end
```
... I get something along the lines of:

```ruby
"nil - NilClass - [:to_i, :to_f, :to_a, :&, :|, :^, :to_r, :rationalize, :to_c]"
```

Which looks like it really is nil. Except the interpreter never should have gotten to that puts statement if `address` really **was** nil. This is a new bug introduced when I switched from Machinist to Fabrication, so I'm *guessing* it's coming from this library.

I poked around the code, and my best guess is that the redefinition of lazy associations' getter methods somehow evaluate to true while acting as a proxy for a nil value (you'd know better than I would).

Anyway, I thought I'd just let you know - nil is now evaluating to true!