-
-
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
HandleUpdate builds the wrong url #29
Comments
Are you sure handleUpdate is not using PUT ? handleUpdate: function (type, id, status) {
this.stubEndpointForHttpRequest(
this.buildURL(type, id),
{},
{type: 'PUT', status: (status || 200)}
)
}, And .. hmm .. that sure is a puzzler .. that the url is wrong .. since the buildURL method is a proxy to ember-data's buildUrl method ( which should create the correct url from the namespace which is set in the adapter .. you noticed this too ) buildURL: function (type, id) {
return this.getStore().adapterFor('application').buildURL(type, id);
}, So I am a bit puzzled there .. but will try and run a few tests to see if I can reproduce what you are saying about the url being off. If the handleFind makes the correct url ( uses the same buildUrl method, not sure why handleUpdate would not? ) .. anyway .. for the sake of being super clear .. what ember-data-factory-guy version are you using, and it is the ruby gem or the bower version? |
Sorry @danielspaniel you are correct, it uses For this example I'm using embercli with Ember: 1.7.0, Ember Data : 1.0.0-beta.11 and ember-data-factory-guy "~0.7.3", with bower obviously. The weird thing is that I see it building the correct url when it does a Seems that ember-data-factory-guy uses this code to generate the url I naively modified the ember-data-factory-guy call to pass through the same args but that didn't work. |
@tmcgilchrist .. let me know if the new version 0.7.7 ( which has the new buildUrl method ) fixes this issue for you .. not 100% sure it will .. but it is an improvement form the old buildUrl method |
I'll give it a go this week and report back @danielspaniel |
I figured out why this problem is happening. When you're using a real backend, the response JSON includes an When you use // make the record and load it in the store
var model = store.makeFixture.apply(store,args);
// respond with the record plus an ID higher than existing records
var nextId = Math.max.apply(this, store.all('collection').mapBy('id'))
responseJson[modelName]=model.toJSON();
responseJson[modelName]['id'] = nextId; |
annnd I just noticed that this is fixed in master, with a much less hacky solution. :) responseJson[modelName] = $.extend(options,{id: definition.nextId()}); |
yes, that handleCreate took me forever to get right. I think I finally got it. |
@indirect .. in fixing up handleCreate to allow exact match and returns parameters (version 0.8.3) , I had to take out the part where I set the id for the simplest cases like handleCreate('project') , since if I return and value in the json ( even just the id ) .. all attributes you set in the store.createRecord('project', {attr1: 1, attr2: 2}) will be set to null ( since they are overwritten by returning json with nothing but an id ). |
How
handleUpdate
builds the url for mocking doesn't seem to take into account the namespace preference supplied on an adapter.If try mocking out an update from ember-data like this
testHelper.handleUpdate('album', 1, {type: 'PUT'})
it builds a url for the model/albums/1' when it should really be
/api/albums/1. I'm not really sure if this is an ember-data-factory-guy bug or something wrong with ember since it seems to be using the per adapter
buildUrl()` function which should work.Also it seems that the default type for
handleUpdate
should be PUT since that's what ember-data uses by default when you do a save() on en existing model.The text was updated successfully, but these errors were encountered: