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

add support for ember-data-model-fragments #28

Merged
merged 3 commits into from
Apr 24, 2019
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: 3 additions & 3 deletions addon/mixins/copyable.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default Mixin.create({
copies[guid] = model;

// Copy all the attributes
this.eachAttribute((name, { type, options: attributeOptions }) => {
this.eachAttribute((name, { type, isFragment, options: attributeOptions }) => {
if (ignoreAttributes.includes(name)) {
return;
} else if (!isUndefined(overwrite[name])) {
Expand All @@ -154,14 +154,14 @@ export default Mixin.create({
) {
let value = this.get(name);

if (Copyable && Copyable.detect(value)) {
if ((Copyable && Copyable.detect(value)) || (value && isFragment)) {
// "value" is an Ember.Object using the ember-copy addon
// (ie. old deprecated Ember.Copyable API - if you use
// the "Ember Data Model Fragments" addon and "value" is a fragment or
// if use your own serializer where you deserialize a value to an
// Ember.Object using this Ember.Copyable API)
value = value.copy(deep);
} else {
} else if (!isFragment) {
const transform = getTransform(this, type, _meta);

// Run the transform on the value. This should guarantee that we get
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"ember-cli-template-lint": "^1.0.0-beta.1",
"ember-cli-uglify": "^2.1.0",
"ember-data": "~3.8.0",
"ember-data-model-fragments": "^4.0.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.1.0",
Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ export function testConfig() {

this.get('/foo-transforms');
this.get('/foo-transforms/:id');

this.get('/foo-fragment-holders');
this.get('/foo-fragment-holders/:id');
}
9 changes: 9 additions & 0 deletions tests/dummy/mirage/fixtures/foo-fragment-holders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
{
id: 1,
foos: [
{ name: 'array fragment' }
],
bar: { name: 'single fragment' }
}
];
13 changes: 12 additions & 1 deletion tests/helpers/define-models.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Copyable from 'ember-data-copyable';
import DS from 'ember-data';
import config from '../../config/environment';
import { assign } from '@ember/polyfills';
import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
import Fragment from 'ember-data-model-fragments/fragment';

const { attr, Model, belongsTo, hasMany } = DS;

Expand Down Expand Up @@ -53,7 +55,16 @@ export default function registerModels(application, options) {
'foo-transform': CopyableModel.extend({
property: attr('string'),
object: attr('object')
})
}),

'foo-fragment': Fragment.extend({
name: attr('string')
}),

'foo-fragment-holder': CopyableModel.extend({
foos: fragmentArray('fooFragment'),
bar: fragment('fooFragment')
}),
};

Object.keys(Models).forEach(name => {
Expand Down
4 changes: 3 additions & 1 deletion tests/helpers/setup-mirage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default function setupMirage(application, options) {
if (!options.async) {
// Pre-fetch all models and add them to the store if its not async
return RSVP.all(
Object.keys(Models).map(name => application.store.findAll(name))
Object.keys(Models)
.filter(name => name !== 'foo-fragment')
.map(name => application.store.findAll(name))
);
}
}
60 changes: 60 additions & 0 deletions tests/integration/copyable-fragments-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import setupMirage from '../helpers/setup-mirage';
import { moduleFor, test } from 'ember-qunit';
import { run } from '@ember/runloop'

moduleFor('copyable', 'Integration | Copyable | fragments', {
integration: true,

beforeEach() {
return setupMirage(this, { async: true });
},

afterEach() {
this.server.shutdown();
}
});

test('it copies with null fragments', async function(assert) {
assert.expect(1);

let model = this.store.createRecord('foo-fragment-holder');
let copied;

await run(async () => {
copied = await model.copy(true);
});

assert.ok(copied);
});

test('it copies single framents', async function(assert) {
assert.expect(1);

let model = this.store.createRecord('foo-fragment-holder', {
bar: { name: 'foo' }
});

let copied;

await run(async () => {
copied = await model.copy(true);
});

assert.equal(copied.get('bar.name'), 'foo')
});

test('it copies fragment arrays', async function(assert) {
assert.expect(1);

let model = this.store.createRecord('foo-fragment-holder', {
foos: [{ name: 'foo' }]
});

let copied;

await run(async () => {
copied = await model.copy(true);
});

assert.equal(copied.get('foos.firstObject.name'), 'foo')
});
91 changes: 38 additions & 53 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1089,11 +1089,6 @@ ansi-escapes@^3.2.0:
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b"
integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==

ansi-regex@*, ansi-regex@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.0.0.tgz#70de791edf021404c3fd615aa89118ae0432e5a9"
integrity sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==

ansi-regex@^0.2.0, ansi-regex@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-0.2.1.tgz#0d8e946967a3d8143f93e24e298525fc1b2235f9"
Expand All @@ -1106,6 +1101,11 @@ ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"

ansi-regex@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.0.0.tgz#70de791edf021404c3fd615aa89118ae0432e5a9"
integrity sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==

ansi-styles@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.1.0.tgz#eaecbf66cd706882760b2f4691582b8f55d7a7de"
Expand Down Expand Up @@ -3817,7 +3817,7 @@ debug@^4.0.0, debug@^4.1.0:
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -4107,7 +4107,7 @@ ember-cli-babel@^6.0.0-beta.4, ember-cli-babel@^6.0.0-beta.7, ember-cli-babel@^6
ember-cli-version-checker "^2.1.0"
semver "^5.4.1"

ember-cli-babel@^6.16.0, ember-cli-babel@^6.3.0:
ember-cli-babel@^6.16.0, ember-cli-babel@^6.3.0, ember-cli-babel@^6.8.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.18.0.tgz#3f6435fd275172edeff2b634ee7b29ce74318957"
integrity sha512-7ceC8joNYxY2wES16iIBlbPSxwKDBhYwC8drU3ZEvuPDMwVv1KzxCNu1fvxyFEBWhwaRNTUxSCsEVoTd9nosGA==
Expand Down Expand Up @@ -4529,12 +4529,25 @@ ember-concurrency@^0.8.27:
ember-cli-babel "^6.8.2"
ember-maybe-import-regenerator "^0.1.5"

ember-copy@^1.0.0:
ember-copy@1.0.0, ember-copy@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ember-copy/-/ember-copy-1.0.0.tgz#426554ba6cf65920f31d24d0a3ca2cb1be16e4aa"
dependencies:
ember-cli-babel "^6.6.0"

ember-data-model-fragments@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ember-data-model-fragments/-/ember-data-model-fragments-4.0.0.tgz#8570d8b6bef12e8a3518279af01478ef8818a44f"
integrity sha512-DcRRQAWrrfRQBW8+v6takQdS2hNJ9rKWU/uHjnPY6+Vg/y6TxyPU8mo0PF2z0DYAeXwoIQ05iYTJT0sqFPEo+w==
dependencies:
broccoli-file-creator "^2.1.1"
broccoli-merge-trees "^3.0.0"
calculate-cache-key-for-tree "^1.1.0"
ember-cli-babel "^6.8.0"
ember-copy "1.0.0"
git-repo-info "^2.0.0"
npm-git-info "^1.0.3"

ember-data@~3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-3.8.0.tgz#05b4d48ab3d612824862b037c4159ce2578fd688"
Expand Down Expand Up @@ -6449,7 +6462,7 @@ ignore@^4.0.2, ignore@^4.0.3:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"

Expand Down Expand Up @@ -7255,7 +7268,7 @@ lodash._basefor@^3.0.0:
resolved "https://registry.yarnpkg.com/lodash._basefor/-/lodash._basefor-3.0.3.tgz#7550b4e9218ef09fad24343b612021c79b4c20c2"
integrity sha1-dVC06SGO8J+tJDQ7YSAhx5tMIMI=

lodash._baseindexof@*, lodash._baseindexof@^3.0.0:
lodash._baseindexof@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
Expand All @@ -7269,14 +7282,6 @@ lodash._baseisequal@^3.0.0:
lodash.istypedarray "^3.0.0"
lodash.keys "^3.0.0"

lodash._baseuniq@*:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
integrity sha1-DrtE5FaBSveQXGIS+iybLVG4Qeg=
dependencies:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._baseuniq@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-3.0.3.tgz#2123fa0db2d69c28d5beb1c1f36d61522a740234"
Expand All @@ -7286,11 +7291,11 @@ lodash._baseuniq@^3.0.0:
lodash._cacheindexof "^3.0.0"
lodash._createcache "^3.0.0"

lodash._bindcallback@*, lodash._bindcallback@^3.0.0:
lodash._bindcallback@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"

lodash._cacheindexof@*, lodash._cacheindexof@^3.0.0:
lodash._cacheindexof@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
Expand All @@ -7303,18 +7308,13 @@ lodash._createassigner@^3.0.0:
lodash._isiterateecall "^3.0.0"
lodash.restparam "^3.0.0"

lodash._createcache@*, lodash._createcache@^3.0.0:
lodash._createcache@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._createwrapper@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash._createwrapper/-/lodash._createwrapper-2.3.0.tgz#d1aae1102dadf440e8e06fc133a6edd7fe146075"
Expand All @@ -7336,7 +7336,7 @@ lodash._escapestringchar@~2.3.0:
resolved "https://registry.yarnpkg.com/lodash._escapestringchar/-/lodash._escapestringchar-2.3.0.tgz#cce73ae60fc6da55d2bf8a0679c23ca2bab149fc"
integrity sha1-zOc65g/G2lXSv4oGecI8orqxSfw=

lodash._getnative@*, lodash._getnative@^3.0.0:
lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"

Expand Down Expand Up @@ -7376,11 +7376,6 @@ lodash._reunescapedhtml@~2.3.0:
lodash._htmlescapes "~2.3.0"
lodash.keys "~2.3.0"

lodash._root@~3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"
integrity sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=

lodash._setbinddata@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash._setbinddata/-/lodash._setbinddata-2.3.0.tgz#e5610490acd13277d59858d95b5f2727f1508f04"
Expand Down Expand Up @@ -7498,15 +7493,10 @@ lodash.identity@~2.3.0:
resolved "https://registry.yarnpkg.com/lodash.identity/-/lodash.identity-2.3.0.tgz#6b01a210c9485355c2a913b48b6711219a173ded"
integrity sha1-awGiEMlIU1XCqRO0i2cRIZoXPe0=

lodash.isarguments@*, lodash.isarguments@^3.0.0:
lodash.isarguments@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"

lodash.isarray@*:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-4.0.0.tgz#2aca496b28c4ca6d726715313590c02e6ea34403"
integrity sha1-KspJayjEym1yZxUxNZDALm6jRAM=

lodash.isarray@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"
Expand All @@ -7528,11 +7518,6 @@ lodash.istypedarray@^3.0.0:
resolved "https://registry.yarnpkg.com/lodash.istypedarray/-/lodash.istypedarray-3.0.6.tgz#c9a477498607501d8e8494d283b87c39281cef62"
integrity sha1-yaR3SYYHUB2OhJTSg7h8OSgc72I=

lodash.keys@*:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-4.2.0.tgz#a08602ac12e4fb83f91fc1fb7a360a4d9ba35205"
integrity sha1-oIYCrBLk+4P5H8H7ejYKTZujUgU=

lodash.keys@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a"
Expand Down Expand Up @@ -7589,7 +7574,7 @@ lodash.pairs@^3.0.0:
dependencies:
lodash.keys "^3.0.0"

lodash.restparam@*, lodash.restparam@^3.0.0:
lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"

Expand Down Expand Up @@ -9359,7 +9344,7 @@ readable-stream@~1.0.2:
isarray "0.0.1"
string_decoder "~0.10.x"

readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
integrity sha1-n6+jfShr5dksuuve4DDcm19AZ0c=
Expand Down Expand Up @@ -10493,13 +10478,6 @@ stringstream@~0.0.4:
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72"
integrity sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA==

strip-ansi@*, strip-ansi@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.0.0.tgz#f78f68b5d0866c20b2c9b8c61b5298508dc8756f"
integrity sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow==
dependencies:
ansi-regex "^4.0.0"

strip-ansi@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.3.0.tgz#25f48ea22ca79187f3174a4db8759347bb126220"
Expand All @@ -10518,6 +10496,13 @@ strip-ansi@^4.0.0:
dependencies:
ansi-regex "^3.0.0"

strip-ansi@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.0.0.tgz#f78f68b5d0866c20b2c9b8c61b5298508dc8756f"
integrity sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow==
dependencies:
ansi-regex "^4.0.0"

strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
Expand Down Expand Up @@ -11134,7 +11119,7 @@ valid-url@^1.0.9:
resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"
integrity sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA=

validate-npm-package-license@*, validate-npm-package-license@^3.0.1:
validate-npm-package-license@^3.0.1:
version "3.0.4"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"
integrity sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==
Expand Down