Skip to content

Commit

Permalink
[BUGFIX beta] pass DS.SnapshotRecordArray to urlForFindAll
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrjohn committed Apr 6, 2016
1 parent 8959c4e commit 88dd4e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions addon/-private/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default Ember.Mixin.create({
case 'findRecord':
return this.urlForFindRecord(id, modelName, snapshot);
case 'findAll':
return this.urlForFindAll(modelName);
return this.urlForFindAll(modelName, snapshot);
case 'query':
return this.urlForQuery(query, modelName);
case 'queryRecord':
Expand Down Expand Up @@ -121,9 +121,10 @@ export default Ember.Mixin.create({
/**
* @method urlForFindAll
* @param {String} modelName
* @param {DS.SnapshotRecordArray} snapshot
* @return {String} url
*/
urlForFindAll(modelName) {
urlForFindAll(modelName, snapshot) {
return this._buildURL(modelName);
},

Expand Down
2 changes: 1 addition & 1 deletion addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {

return this._makeRequest(request);
} else {
const url = this.buildURL(type.modelName, null, null, 'findAll');
const url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll');

if (sinceToken) {
query.since = sinceToken;
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,11 @@ test("findAll - returning an array populates the array", function(assert) {
});


test("findAll - passes buildURL the requestType", function(assert) {
test("findAll - passes buildURL the requestType and snapshot", function(assert) {
assert.expect(2);
let adapterOptionsStub = { stub: true };
adapter.buildURL = function(type, id, snapshot, requestType) {
assert.equal(snapshot.adapterOptions, adapterOptionsStub);
return "/" + requestType + "/posts";
};

Expand All @@ -1045,7 +1048,7 @@ test("findAll - passes buildURL the requestType", function(assert) {
]
});

store.findAll('post').then(assert.wait(function(posts) {
store.findAll('post', { adapterOptions: adapterOptionsStub }).then(assert.wait(function(posts) {
assert.equal(passedUrl, "/findAll/posts");
}));
});
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/adapters/build-url-mixin/build-url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ test('buildURL - find requestType delegates to urlForFindRecord', function(asser
});

test('buildURL - findAll requestType delegates to urlForFindAll', function(assert) {
assert.expect(2);
assert.expect(3);
let originalMethod = adapter.urlForFindAll;
adapter.urlForFindAll = function(type) {
let snapshotStub = { snapshot: true };
adapter.urlForFindAll = function(type, snapshot) {
assert.equal(type, 'super-user');
assert.equal(snapshot, snapshotStub);
return originalMethod.apply(this, arguments);
};
assert.equal(adapter.buildURL('super-user', null, null, 'findAll'), '/superUsers');
assert.equal(adapter.buildURL('super-user', null, snapshotStub, 'findAll'), '/superUsers');
});

test('buildURL - query requestType delegates to urlForQuery', function(assert) {
Expand Down

0 comments on commit 88dd4e8

Please sign in to comment.