Skip to content
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

[CLEANUP ds-finder-include] #4348

Merged
merged 1 commit into from
Apr 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-references": true,
"ds-transform-pass-options": true,
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`');
});