Skip to content

Commit

Permalink
Merge pull request #4348 from pangratz/cleanup-ds-finder-include
Browse files Browse the repository at this point in the history
[CLEANUP ds-finder-include]
  • Loading branch information
bmac committed Apr 28, 2016
2 parents f699952 + 3c88c9c commit 6143081
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 69 deletions.
6 changes: 0 additions & 6 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ entry in `config/features.json`.

Note that this feature only works when `ds-transform-pass-options` is enabled too.

- `ds-finder-include`

Allows an `include` query parameter to be specified with using
`store.findRecord()` and `store.findAll()` as described in [RFC
99](https://github.com/emberjs/rfcs/pull/99)

- `ds-improved-ajax`

This feature allows to customize how a request is formed by overwriting
Expand Down
4 changes: 1 addition & 3 deletions addon/-private/system/snapshot-record-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export default function SnapshotRecordArray(recordArray, meta, options = {}) {
*/
this.adapterOptions = options.adapterOptions;

if (isEnabled('ds-finder-include')) {
this.include = options.include;
}
this.include = options.include;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions addon/-private/system/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export default function Snapshot(internalModel, options = {}) {
*/
this.adapterOptions = options.adapterOptions;

if (isEnabled('ds-finder-include')) {
this.include = options.include;
}
this.include = options.include;

this._changedAttributes = record.changedAttributes();
}
Expand Down
10 changes: 4 additions & 6 deletions addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,11 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
buildQuery(snapshot) {
let query = {};

if (isEnabled('ds-finder-include')) {
if (snapshot) {
const { include } = snapshot;
if (snapshot) {
const { include } = snapshot;

if (include) {
query.include = include;
}
if (include) {
query.include = include;
}
}

Expand Down
1 change: 0 additions & 1 deletion config/features.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"ds-boolean-transform-allow-null": null,
"ds-finder-include": true,
"ds-improved-ajax": null,
"ds-transform-pass-options": true,
"ds-pushpayload-return": null,
Expand Down
36 changes: 16 additions & 20 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,15 @@ test("findRecord - payload with a serializer-specified attribute mapping", funct
}));
});

if (isEnabled('ds-finder-include')) {
test("findRecord - passes `include` as a query parameter to ajax", function(assert) {
ajaxResponse({
post: { id: 1, name: 'Rails is very expensive sushi' }
});

run(store, 'findRecord', 'post', 1, { include: 'comments' }).then(assert.wait(function() {
assert.deepEqual(passedHash.data, { include: 'comments' }, '`include` parameter sent to adapter.ajax');
}));
test("findRecord - passes `include` as a query parameter to ajax", function(assert) {
ajaxResponse({
post: { id: 1, name: 'Rails is very expensive sushi' }
});
}

run(store, 'findRecord', 'post', 1, { include: 'comments' }).then(assert.wait(function() {
assert.deepEqual(passedHash.data, { include: 'comments' }, '`include` parameter sent to adapter.ajax');
}));
});

test("createRecord - an empty payload is a basic success if an id was specified", function(assert) {
ajaxResponse();
Expand Down Expand Up @@ -1053,17 +1051,15 @@ test("findAll - passes buildURL the requestType and snapshot", function(assert)
}));
});

if (isEnabled('ds-finder-include')) {
test("findAll - passed `include` as a query parameter to ajax", function(assert) {
ajaxResponse({
posts: [{ id: 1, name: 'Rails is very expensive sushi' }]
});

run(store, 'findAll', 'post', { include: 'comments' }).then(assert.wait(function() {
assert.deepEqual(passedHash.data, { include: 'comments' }, '`include` params sent to adapter.ajax');
}));
test("findAll - passed `include` as a query parameter to ajax", function(assert) {
ajaxResponse({
posts: [{ id: 1, name: 'Rails is very expensive sushi' }]
});
}

run(store, 'findAll', 'post', { include: 'comments' }).then(assert.wait(function() {
assert.deepEqual(passedHash.data, { include: 'comments' }, '`include` params sent to adapter.ajax');
}));
});

test("findAll - returning sideloaded data loads the data", function(assert) {
ajaxResponse({
Expand Down
37 changes: 16 additions & 21 deletions tests/integration/adapter/store-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Ember from 'ember';
import {module, test} from 'qunit';

import DS from 'ember-data';
import isEnabled from 'ember-data/-private/features';

/*
This is an integration test that tests the communication between a store
Expand Down Expand Up @@ -1319,18 +1318,16 @@ test("store.findRecord should pass adapterOptions to adapter.findRecord", functi
});
});

if (isEnabled('ds-finder-include')) {
test("store.findRecord should pass 'include' to adapter.findRecord", function(assert) {
assert.expect(1);

env.adapter.findRecord = assert.wait((store, type, id, snapshot) => {
assert.equal(snapshot.include, 'books', 'include passed to adapter.findRecord');
return Ember.RSVP.resolve({ id: 1 });
});
test("store.findRecord should pass 'include' to adapter.findRecord", function(assert) {
assert.expect(1);

run(() => store.findRecord('person', 1, { include: 'books' }));
env.adapter.findRecord = assert.wait((store, type, id, snapshot) => {
assert.equal(snapshot.include, 'books', 'include passed to adapter.findRecord');
return Ember.RSVP.resolve({ id: 1 });
});
}

run(() => store.findRecord('person', 1, { include: 'books' }));
});

test("store.findAll should pass adapterOptions to the adapter.findAll method", function(assert) {
assert.expect(1);
Expand All @@ -1346,18 +1343,16 @@ test("store.findAll should pass adapterOptions to the adapter.findAll method", f
});
});

if (isEnabled('ds-finder-include')) {
test("store.findAll should pass 'include' to adapter.findAll", function(assert) {
assert.expect(1);

env.adapter.findAll = assert.wait((store, type, sinceToken, arraySnapshot) => {
assert.equal(arraySnapshot.include, 'books', 'include passed to adapter.findAll');
return Ember.RSVP.resolve([{ id: 1 }]);
});
test("store.findAll should pass 'include' to adapter.findAll", function(assert) {
assert.expect(1);

run(() => store.findAll('person', { include: 'books' }));
env.adapter.findAll = assert.wait((store, type, sinceToken, arraySnapshot) => {
assert.equal(arraySnapshot.include, 'books', 'include passed to adapter.findAll');
return Ember.RSVP.resolve([{ id: 1 }]);
});
}

run(() => store.findAll('person', { include: 'books' }));
});

test("An async hasMany relationship with links should not trigger shouldBackgroundReloadRecord", function(assert) {
var Post = DS.Model.extend({
Expand Down
15 changes: 6 additions & 9 deletions tests/unit/adapters/rest-adapter/build-query-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { module, test } from 'qunit';
import DS from 'ember-data';
import isEnabled from 'ember-data/-private/features';

module("unit/adapters/rest-adapter/build-query - building queries");

Expand All @@ -20,13 +19,11 @@ test("buildQuery - doesn't fail without a snapshot", function(assert) {
assert.deepEqual(query, {}, 'returns an empty query');
});

if (isEnabled('ds-finder-include')) {
test("buildQuery() returns query with `include` from snapshot", function(assert) {
const adapter = DS.RESTAdapter.create();
const snapshotStub = { include: 'comments' };
test("buildQuery() returns query with `include` from snapshot", function(assert) {
const adapter = DS.RESTAdapter.create();
const snapshotStub = { include: 'comments' };

const query = adapter.buildQuery(snapshotStub);
const query = adapter.buildQuery(snapshotStub);

assert.deepEqual(query, { include: 'comments' }, 'query includes `include`');
});
}
assert.deepEqual(query, { include: 'comments' }, 'query includes `include`');
});

0 comments on commit 6143081

Please sign in to comment.