You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like we had a bug in "Fake#is_a?" which caused the association type mismatch.
However, even if it is possible to pass fakes to AR associations, I would advise against that, because it violates the "don't mock what you don't own" principle.
In order to pass a fake to an AR association, you have to know what AR does with it under the hood, which is (in pseudocode):
However, when you update your project to use a newer version of AR, this code might change, and all of your tests that depend on that behavior would break.
The way I deal with AR classes in my projects is that I treat them mostly as value types (rule of thumb: no conditionals in AR models). Since value types don't contain any logic, you are free to use them in your isolated tests. Destroy All Software has a lot more on this topic if you are interested.
I have the following test:
As I am testing comment I don't want it to be a fake, but user I would like to be a fake.
Rspec fails with:
Not sure if this should work or I should try to do things differently. Thanks.
The text was updated successfully, but these errors were encountered: