Changes to Rails fixtures do not apply to associations

In Rails 4.2.1, I have a model Book

. I also have a model BookAcl

that belongs_to

is Book

. In my test, I load both through the fixtures defined in tests/fixtures

. In my test, in setup

, I create an instance of both objects based on the instrument data. Up to this point everything is working fine.

In my test I am modifying the BookAcl object and expect these changes to be reflected when accessing the same BookAcl via the Book object. However, this does not happen. In fact, when I look (via Pry) at the BookAcl object, the properties are different from the Book.BookAcl object, although the rest of the object is identical.

What am I doing wrong? How do I make these changes propagate through the object graph?

+3


source to share


1 answer


Call #reload

. There is no Identity Map in the current version of Rails (they figured it caused too many errors), so you have to manually reselect all the objects you want by calling #reload

when the DB record changes.



+2


source







All Articles