From 49fc7bce835046d6ed0e9f2bf1454b84bfc1ebcb Mon Sep 17 00:00:00 2001 From: Derek Wickern Date: Wed, 13 Mar 2024 19:16:35 -0700 Subject: [PATCH] fix passing arbitrary props to fragmentArray.createFragment (#486) --- addon/array/fragment.js | 2 +- tests/unit/fragment_array_property_test.js | 13 +++++++++++++ tests/unit/fragment_property_test.js | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addon/array/fragment.js b/addon/array/fragment.js index 36075f49..ee293ef4 100644 --- a/addon/array/fragment.js +++ b/addon/array/fragment.js @@ -149,7 +149,7 @@ const FragmentArray = StatefulArray.extend({ this.key, props ); - const fragment = recordData._fragmentGetRecord(); + const fragment = recordData._fragmentGetRecord(props); return this.pushObject(fragment); }, }); diff --git a/tests/unit/fragment_array_property_test.js b/tests/unit/fragment_array_property_test.js index 0e1b38d1..0f513f10 100644 --- a/tests/unit/fragment_array_property_test.js +++ b/tests/unit/fragment_array_property_test.js @@ -585,4 +585,17 @@ module('unit - `MF.fragmentArray` property', function (hooks) { ); }); }); + + test('pass arbitrary props to createFragment', async function (assert) { + pushPerson(1); + + const person = await store.findRecord('person', 1); + const address = person.addresses.createFragment({ + street: '1 Dungeon Cell', + extra: 123, + }); + + assert.equal(address.street, '1 Dungeon Cell', 'street is correct'); + assert.equal(address.extra, 123, 'extra property is correct'); + }); }); diff --git a/tests/unit/fragment_property_test.js b/tests/unit/fragment_property_test.js index 7cc094d7..942abf7a 100644 --- a/tests/unit/fragment_property_test.js +++ b/tests/unit/fragment_property_test.js @@ -520,4 +520,14 @@ module('unit - `MF.fragment` property', function (hooks) { assert.ok(newName.isDestroying, 'the new fragment is being destroyed'); }); }); + + test('pass arbitrary props to createFragment', async function (assert) { + const address = store.createFragment('address', { + street: '1 Dungeon Cell', + extra: 123, + }); + + assert.equal(address.street, '1 Dungeon Cell', 'street is correct'); + assert.equal(address.extra, 123, 'extra property is correct'); + }); });