From 8fc54bd07c39cc6d72b3b04870f15e14efebcd5b Mon Sep 17 00:00:00 2001 From: Dan McClain Date: Thu, 24 Mar 2016 08:55:55 -0400 Subject: [PATCH] [FEATURE ds-links-in-record-array] Add links to RecordArray when present on payload --- .../adapter-populated-record-array.js | 20 +++++++--- config/features.json | 3 +- .../adapter-populated-record-array-test.js | 40 +++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/addon/-private/system/record-arrays/adapter-populated-record-array.js b/addon/-private/system/record-arrays/adapter-populated-record-array.js index 24f09dc8804..a1997699a8b 100644 --- a/addon/-private/system/record-arrays/adapter-populated-record-array.js +++ b/addon/-private/system/record-arrays/adapter-populated-record-array.js @@ -1,6 +1,7 @@ import Ember from 'ember'; import RecordArray from "ember-data/-private/system/record-arrays/record-array"; import cloneNull from "ember-data/-private/system/clone-null"; +import isEnabled from 'ember-data/-private/features'; /** @module ember-data @@ -35,11 +36,20 @@ export default RecordArray.extend({ loadRecords(records, payload) { //TODO Optimize var internalModels = Ember.A(records).mapBy('_internalModel'); - this.setProperties({ - content: Ember.A(internalModels), - isLoaded: true, - meta: cloneNull(payload.meta) - }); + if (isEnabled('ds-links-in-record-array')) { + this.setProperties({ + content: Ember.A(internalModels), + isLoaded: true, + meta: cloneNull(payload.meta), + links: cloneNull(payload.links) + }); + } else { + this.setProperties({ + content: Ember.A(internalModels), + isLoaded: true, + meta: cloneNull(payload.meta) + }); + } internalModels.forEach((record) => { this.manager.recordArraysForRecord(record).add(this); diff --git a/config/features.json b/config/features.json index 9b315a88126..e42f1bb4a7f 100644 --- a/config/features.json +++ b/config/features.json @@ -6,5 +6,6 @@ "ds-transform-pass-options": null, "ds-pushpayload-return": null, "ds-serialize-ids-and-types": null, - "ds-extended-errors": null + "ds-extended-errors": null, + "ds-links-in-record-array": null } diff --git a/tests/unit/adapter-populated-record-array-test.js b/tests/unit/adapter-populated-record-array-test.js index 15c6ef56408..ca185142a1e 100644 --- a/tests/unit/adapter-populated-record-array-test.js +++ b/tests/unit/adapter-populated-record-array-test.js @@ -5,6 +5,8 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; +import isEnabled from 'ember-data/-private/features'; + var Person, store; var run = Ember.run; @@ -102,6 +104,44 @@ test("stores the metadata off the payload", function(assert) { assert.equal(recordArray.get('meta.foo'), 'bar', 'expected meta.foo to be bar from payload'); }); +if (isEnabled('ds-links-in-record-array')) { + test('stores the links off the payload', function(assert) { + var recordArray = store.recordArrayManager + .createAdapterPopulatedRecordArray(store.modelFor('person'), null); + var payload = { + data: [{ + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale' + } + }, { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz' + } + }, { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn' + } + }], + links: { + first: '/foo?page=1' + } + }; + + run(function() { + var records = store.push(payload); + recordArray.loadRecords(records, payload); + }); + + assert.equal(recordArray.get('links.first'), '/foo?page=1', 'expected links.first to be "/foo?page=1" from payload'); + }); +} + test('recordArray.replace() throws error', function(assert) { var recordArray = store.recordArrayManager .createAdapterPopulatedRecordArray(Person, null);