Test oddities

8 views
Skip to first unread message

IAmNan

unread,
Apr 24, 2012, 9:48:26 PM4/24/12
to rubyonra...@googlegroups.com
Can someone explain why a instance variable cannot be changed through an association under rspec/factory_girl? An example is in this gist.

All tests pass except the last. All the steps pass in the console.

Frederick Cheung

unread,
Apr 24, 2012, 10:13:06 PM4/24/12
to Ruby on Rails: Talk


On Apr 24, 8:48 pm, IAmNan <dger...@gmail.com> wrote:
> Can someone explain why a instance variable cannot be changed through an
> association under rspec/factory_girl? An example is in this gist<https://gist.github.com/2484336>
> .
>

When you use .first and if the association is not already loaded then
the object is refetched from the db each time, so the unsaved change
you've made to the object is lost.

Fred

IAmNan

unread,
Apr 24, 2012, 11:27:05 PM4/24/12
to rubyonra...@googlegroups.com
I see. No cache. So it's effectively a no-op. That explains why update_attributes instead of the = operator works as expected.

It seems kind of pointless for a framework to allow such a thing. Boy, I've got a lot of old code to revisit.

Thanks for your feedback, Fred.
Reply all
Reply to author
Forward
0 new messages