-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning inherited models of various types #231
Comments
I will put this test to use in finding out what is going on ... on first glance it is probably due to the way polymorphism is handled in factory guy and that I have tested in a relationship setting and not freestyle as this one is ( load some polymorphic models on their own ) |
this issue is now fixed in version 2.7.4 .. thanks for bringing it up |
Thank you very much for fixing it! It will help us a lot. |
Your 100% welcome. I always like that you give me very clear idea of what is going on and write a test I can work with to fix the issue. |
Hello! It seems that this issue strikes again. The polymorphic models are returned just fine when we use test("using returns with model instances for a polymorphic route", function(assert) {
run(() => {
let done = assert.async();
let bigHat = make('big-hat');
console.log(bigHat.constructor.modelName); // "big-hat"
mockQuery('hat', {size: 'all'}).returns({models: [bigHat]});
FactoryGuy.store.query('hat', {size: 'all'}).then(function(hats) {
assert.equal(hats.get('length'), 1);
console.log(hats.get('firstObject').constructor.modelName); // "hat"
assert.equal(hats.get('firstObject').constructor.modelName, bigHat.constructor.modelName) // fails
assert.equal(FactoryGuy.store.peekAll('hat').get('content').length, 0, "does not make another hat"); // fails again
done();
});
});
}); It seems that the previous behaviour was broken by this fix. Our test cases started to work just fine when we returned |
Interesting, I am going to try this out and see if i can figure this out. |
Hello!
I ran into a problem while writing tests for our application. We have a certain backend route that can return various models inherited from a single base model. When I tried to mock it, I found out that the mock replaces the types of the supplied model instances with the type specified as the modelName for the mock, so the data aren't loaded properly.
To illustrate this, I wrote a simple test based on your test setup:
As it turned out, the data type specified in the JSON is
'hat'
in both cases.I would greatly appreciate your suggestions on handling this situation.
The text was updated successfully, but these errors were encountered: