-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
add ability to make models in the new state #269
Comments
ummmmmmm .. mmmmm .. hmmmm .. interesting. I have not needed this ( does not mean its not a good idea ) .. so I am not sure right now what is best way. you could change this: let adapterAttrs = build('adapter', id: null).get();
let adapter = run(() => FactoryGuy.store.createRecord('adapter', adapterAttrs));
this.set('model', adapter); // did you really mean to do { adapter } ? seems odd I usually do this way because I am usually testing one or two attributes only and I don't mind if the rest are blank. let adapter = run(() => FactoryGuy.store.createRecord('adapter', {name: 'dude'}));
this.set('model', adapter); |
your suggestion is more succinct, thanks. but yes, was wondering if it's possible to do a make to create a model in the 'new' state with less code. we have several components which behave differently for new (creating) and existing (updating) records. as far as syntax - i'm not sure; just getting to know factory-guy. maybe: let adapter = make('adapter', isNew: true); ...since that is the recommended attribute for differentiating in user code, and it's read-only in ember-data. i am totally unfamiliar with the level of difficulty for implementation, however. do you think its possible? |
This ( using make ) would be confusing though because "make" is supposed to make a 'loaded' model. So, maybe there needs to be another name for "make me a new record" like make createNew ? or makeNew ? .. then you could use the same traits and options as you would with make , build. let newCan = makeNew('cat', 'calico', {name: 'Meow'}) |
oh, and this code: let adapterAttrs = build('adapter', id: null).get(); produces hyphenated attributes (using JSONAPIAdapter with defaults) so won't work for handing to |
Howdy partner, this new behaviour is enabled in: |
amazing - thanks! |
@danielspaniel I'm having an issue with makeNew() {
let args = extractArguments.apply(this, arguments);
...
let modelName = lookupModelForFixtureName(args.name);
let fixture = this.buildRaw.apply(this, arguments);
console.log("==> fixture:", fixture);
let data = this.fixtureBuilder(modelName).convertForBuild(modelName, fixture);
data = data.get();
delete data.id;
console.log("==> data:", data);
const model = Ember.run(()=> this.store.createRecord(modelName, data));
console.log("==> model:", model.toJSON());
return model;
} yields: {
id: 1,
name: "Adapter 1",
coverageMergerClassName: "CoverageMergers::Synchronize"
}
{
name: "Adapter 1",
coverage-merger-class-name: "CoverageMergers::Synchronize"
}
{
name: "Adapter 1",
coverageMergerClassName: null,
...
} Is this particular to my ember-data adapter setup or an issue with factory-guy? (sorry for the confusing use of |
per your original comment, the shortest i can write the code using let adapterAttrs = make('adapter').toJSON({ includeId: false });
let adapter = run(() => FactoryGuy.store.createRecord('adapter', adapterAttrs)); |
hmm .. let me write a test for this @jakeonfire .. might be that I have to use let data = this.fixtureBuilder(modelName).convertForMake(modelName, fixture); instead of let data = this.fixtureBuilder(modelName).convertForBuild(modelName, fixture); can you do me favour and swap that out and see what happens? good catch in any case |
@jakeonfire .. this is now fixe on v2.11.4 .. happy testing! |
perfect, thanks! |
factory-guy cannot make models in the new state for use in component integration tests. i had to use the following code to set a model in a component which - when saved - would issue a create (POST) in ember-data:
The text was updated successfully, but these errors were encountered: