Skip to content

Commit 52f17f1

Browse files
trevorrjohnbmac
authored andcommitted
[BUGFIX beta] pass snapshot into urlForFindHasMany/BelongsTo
(cherry picked from commit 85a1220)
1 parent 8d7e55f commit 52f17f1

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

addon/-private/adapters/build-url-mixin.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export default Ember.Mixin.create({
6464
case 'findMany':
6565
return this.urlForFindMany(id, modelName, snapshot);
6666
case 'findHasMany':
67-
return this.urlForFindHasMany(id, modelName);
67+
return this.urlForFindHasMany(id, modelName, snapshot);
6868
case 'findBelongsTo':
69-
return this.urlForFindBelongsTo(id, modelName);
69+
return this.urlForFindBelongsTo(id, modelName, snapshot);
7070
case 'createRecord':
7171
return this.urlForCreateRecord(modelName, snapshot);
7272
case 'updateRecord':
@@ -163,19 +163,21 @@ export default Ember.Mixin.create({
163163
* @method urlForFindHasMany
164164
* @param {String} id
165165
* @param {String} modelName
166+
* @param {DS.Snapshot} snapshot
166167
* @return {String} url
167168
*/
168-
urlForFindHasMany(id, modelName) {
169+
urlForFindHasMany(id, modelName, snapshot) {
169170
return this._buildURL(modelName, id);
170171
},
171172

172173
/**
173174
* @method urlForFindBelongTo
174175
* @param {String} id
175176
* @param {String} modelName
177+
* @param {DS.Snapshot} snapshot
176178
* @return {String} url
177179
*/
178-
urlForFindBelongsTo(id, modelName) {
180+
urlForFindBelongsTo(id, modelName, snapshot) {
179181
return this._buildURL(modelName, id);
180182
},
181183

addon/adapters/rest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ export default Adapter.extend(BuildURLMixin, {
569569
var id = snapshot.id;
570570
var type = snapshot.modelName;
571571

572-
url = this.urlPrefix(url, this.buildURL(type, id, null, 'findHasMany'));
572+
url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findHasMany'));
573573

574574
return this.ajax(url, 'GET');
575575
},
@@ -613,7 +613,7 @@ export default Adapter.extend(BuildURLMixin, {
613613
var id = snapshot.id;
614614
var type = snapshot.modelName;
615615

616-
url = this.urlPrefix(url, this.buildURL(type, id, null, 'findBelongsTo'));
616+
url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findBelongsTo'));
617617
return this.ajax(url, 'GET');
618618
},
619619

tests/integration/adapter/rest-adapter-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,8 +1687,10 @@ test("findHasMany - returning an array populates the array", function(assert) {
16871687
});
16881688

16891689
test("findHasMany - passes buildURL the requestType", function(assert) {
1690+
assert.expect(2);
16901691
adapter.shouldBackgroundReloadRecord = () => false;
16911692
adapter.buildURL = function(type, id, snapshot, requestType) {
1693+
assert.ok(snapshot instanceof DS.Snapshot);
16921694
assert.equal(requestType, 'findHasMany');
16931695
};
16941696

@@ -1833,8 +1835,10 @@ test("findMany - a custom serializer is used if present", function(assert) {
18331835
});
18341836

18351837
test('findBelongsTo - passes buildURL the requestType', function(assert) {
1838+
assert.expect(2);
18361839
adapter.shouldBackgroundReloadRecord = () => false;
18371840
adapter.buildURL = function(type, id, snapshot, requestType) {
1841+
assert.ok(snapshot instanceof DS.Snapshot);
18381842
assert.equal(requestType, 'findBelongsTo');
18391843
};
18401844

tests/unit/adapters/build-url-mixin/build-url-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,29 @@ test('buildURL - findMany requestType delegates to urlForFindMany', function(ass
9090
});
9191

9292
test('buildURL - findHasMany requestType delegates to urlForFindHasMany', function(assert) {
93-
assert.expect(3);
93+
assert.expect(4);
9494
let originalMethod = adapter.urlForFindHasMany;
95-
adapter.urlForFindHasMany = function(id, type) {
95+
let snapshotStub = { snapshot: true };
96+
adapter.urlForFindHasMany = function(id, type, snapshot) {
9697
assert.equal(id, 1);
9798
assert.equal(type, 'super-user');
99+
assert.equal(snapshot, snapshotStub);
98100
return originalMethod.apply(this, arguments);
99101
};
100-
assert.equal(adapter.buildURL('super-user', 1, null, 'findHasMany'), '/superUsers/1');
102+
assert.equal(adapter.buildURL('super-user', 1, snapshotStub, 'findHasMany'), '/superUsers/1');
101103
});
102104

103105
test('buildURL - findBelongsTo requestType delegates to urlForFindBelongsTo', function(assert) {
104-
assert.expect(3);
106+
assert.expect(4);
105107
let originalMethod = adapter.urlForFindBelongsTo;
106-
adapter.urlForFindBelongsTo = function(id, type) {
108+
let snapshotStub = { snapshot: true };
109+
adapter.urlForFindBelongsTo = function(id, type, snapshot) {
107110
assert.equal(id, 1);
108111
assert.equal(type, 'super-user');
112+
assert.equal(snapshot, snapshotStub);
109113
return originalMethod.apply(this, arguments);
110114
};
111-
assert.equal(adapter.buildURL('super-user', 1, null, 'findBelongsTo'), '/superUsers/1');
115+
assert.equal(adapter.buildURL('super-user', 1, snapshotStub, 'findBelongsTo'), '/superUsers/1');
112116
});
113117

114118
test('buildURL - createRecord requestType delegates to urlForCreateRecord', function(assert) {

0 commit comments

Comments
 (0)