-
-
Notifications
You must be signed in to change notification settings - Fork 111
Description
I'm opening this here but to be honest I'm not sure if the issue is in the Model Fragments RecordData refactor or the Ember Data upgrade (considering we need to upgrade to Ember Data 3.16).
Background
The Factory Guy addon gives you a set of APIs to bootstrap your models in tests. The make helper allows you to push records directly into the store rather than need to use the push, pushPayload or createRecord APIs to bootstrap your models. A common pattern when using make is to compose your test models with other models created using make. For example take the following person Ember Data model which contains a fragment:
// models/user.js
export default class User extends Model {
@fragment('info') info
}
// models/info.js
export default class Info extends Fragment {
@attr name
}This can be created in a test by doing the following (once you've created your factories correctly). Here we create a user model and pass it an info fragment model.
let user = make('user',
info: make('info'),
});The problem
It appears passing a fragment to a model like above causes the properties of info to be undefined rather than the values which were originally on the model.
console.log(info.name); //=> "Jon Snow"
console.log(user.info.name); //=> undefinedStrangely, if you pass a model to another model, or a fragment to another fragment it works correctly. It specifically seems to be the case where you pass a fragment to a model which isn't working. I've pushed a draft PR here which has a failing test (and some passing ones) to illustrate the problem.
Potential bug
The problem seems specifically to be an issue all the way down in EmberObject when we are pushing the _internalModel property on the object to create the model instance. Looking at the screenshot below, the passed in props have the correct value, but once the model is created they are "lost" and come back as undefined.
var instance = this.class.create(props);And just to clarify, the failing test in the PR passes on the commit before the RecordData refactor.
