-
-
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
Can the handler functions deal with non-rest adapters? #121
Comments
Yes @jonocodes, you could do this: // file -> tests/helpers/custom-test-helper.js
import FactoryGuyTestHelper from 'ember-data-factory-guy/factory-guy-test-helper';
var CustomTestHelper = FactoryGuyTestHelper.reopen({
buildURL: function (modelName, id) {
if ( modelName === 'whatever') {
// do your own thing
} else {
// do what factory guy usually does
this._super(modelName, id);
}
}
});
export default CustomTestHelper; |
Thanks for the tip. I ended up doing the following: import FactoryGuyTestHelper from 'ember-data-factory-guy/factory-guy-test-helper';
import MockUpdateRequest from 'ember-data-factory-guy/mock-update-request';
export default FactoryGuyTestHelper.reopen({
// customize the helper to follow our custom adapter for PUT
handleUpdate: function() {
var args = Array.prototype.slice.call(arguments);
Ember.assert("To handleUpdate pass in a model instance or a type and an id", args.length>0);
var options = {};
if (args.length > 1 && typeof args[args.length - 1] === 'object') {
options = args.pop();
}
var model, type, id;
var store = this.getStore();
if (args[0] instanceof DS.Model) {
model = args[0];
id = model.id;
type = model.constructor.typeKey;
} else if (typeof args[0] === "string" && typeof parseInt(args[1]) === "number") {
type = args[0];
id = args[1];
model = store.getById(type, id);
}
Ember.assert("To handleUpdate pass in a model instance or a type and an id",type && id);
if ( type === 'person') {
var url = this.buildURL(type);
return new MockUpdateRequest(url, model, this.mapFind, options);
}
return this._super(type, id);
}
});
|
got it @jonocodes, if you come up with a better way to handle this and want to submit a pull request .. feel free. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a custom adapter which uses a different path for a PUT:
However it seams this wont work with handleUpdate because it has a hardcoded buildUrl that looks like it follows the RestAdapter only:
https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/factory-guy-test-helper.js#L348
Is there a good way to override this in Factory Guy?
The text was updated successfully, but these errors were encountered: