My understanding was always that if a record is found, no changes are
made, otherwise we create one with the prams passed in and set it up
with the block too.
i.e.
User.find_or_create_by_name(name){|new_user| new_user.password =
'1234' }
should be equivalent to:
User.find_by_name(name) || User.create!{ |new_user| new_user.password
= '1234' }
Perhaps a documentation patch would be more appropriate?
We found this behavior in 2.1.0, so it would be great to have it
backported to 2.1.x, but I haven't tried the patch against the that
line. Looks like it might work.
Sorry, I left that bit of context out of my original message. In
*both* of my examples, the record does NOT exist. That is, the first
time the method is called, if the record exists, there's no bug -- the
block isn't called and shouldn't be. But if, on that first call, the
record doesn't exist, the block is still not called, which is a bug.
This is related to the way AR auto-defines these methods the first
time they're invoked.