From 9f325922ddc98076b6e2420aa8004ebea21e6a47 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Mon, 17 May 2021 06:44:22 -0500 Subject: [PATCH] [Bug]: setDeep does not respect re-setting top level Change object (#593) * [Bug]: setDeep does not respect re-setting top level Change object * add tests from issue --- package.json | 2 +- tests/unit/changeset-test.js | 56 ++++++++++++++++++++++++++++++++++++ yarn.lock | 8 +++--- 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1e2e6069..466b9866 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@glimmer/tracking": "^1.0.1", "ember-auto-import": "^1.5.2", "ember-cli-babel": "^7.19.0", - "validated-changeset": "~0.14.4" + "validated-changeset": "~0.14.5" }, "devDependencies": { "@ember/optional-features": "^1.0.0", diff --git a/tests/unit/changeset-test.js b/tests/unit/changeset-test.js index cc95d7c8..f3cfa7c4 100644 --- a/tests/unit/changeset-test.js +++ b/tests/unit/changeset-test.js @@ -870,6 +870,62 @@ module('Unit | Utility | changeset', function (hooks) { assert.deepEqual(dummyChangeset.options, expectedChanges[0].value, 'should have new values'); }); + test('#set Ember.set with Object actually does work TWICE for nested', async function (assert) { + set(dummyModel, 'name', {}); + let title1 = { id: 'Mr', description: 'Mister' }; + let title2 = { id: 'Mrs', description: 'Missus' }; + let dummyChangeset = Changeset(dummyModel); + set(dummyChangeset, 'name.title', title1); + + assert.equal(get(dummyModel, 'name.title.id'), undefined, 'should not have new change'); + assert.equal(dummyChangeset.name.title.id, 'Mr', 'should have new change'); + assert.equal(dummyChangeset.get('name.title.id'), 'Mr', 'should have new change using get'); + + let changes = get(dummyChangeset, 'changes'); + assert.deepEqual(changes, [{ key: 'name.title', value: title1 }], 'changes with nested key Ember.set'); + + set(dummyChangeset, 'name.title', title2); + + assert.equal(get(dummyModel, 'name.title.id'), undefined, 'should not have new change'); + assert.equal(dummyChangeset.name.title.id, 'Mrs', 'should have new change'); + assert.equal(dummyChangeset.get('name.title.id'), 'Mrs', 'should have new change using get'); + + changes = get(dummyChangeset, 'changes'); + assert.deepEqual(changes, [{ key: 'name.title', value: title2 }], 'changes with nested key Ember.set'); + + dummyChangeset.execute(); + + assert.equal(dummyModel.name.title.id, 'Mrs', 'has new property'); + }); + + test('#set with Object should work TWICE for nested', async function (assert) { + set(dummyModel, 'name', {}); + let title1 = { id: 'Mr', description: 'Mister' }; + let title2 = { id: 'Mrs', description: 'Missus' }; + let dummyChangeset = Changeset(dummyModel); + dummyChangeset.set('name.title', title1); + + assert.equal(get(dummyModel, 'name.title.id'), undefined, 'should not have new change'); + assert.equal(dummyChangeset.name.title.id, 'Mr', 'should have new change'); + assert.equal(dummyChangeset.get('name.title.id'), 'Mr', 'should have new change using get'); + + let changes = get(dummyChangeset, 'changes'); + assert.deepEqual(changes, [{ key: 'name.title', value: title1 }], 'changes with nested key Ember.set'); + + dummyChangeset.set('name.title', title2); + + assert.equal(get(dummyModel, 'name.title.id'), undefined, 'should not have new change'); + assert.equal(dummyChangeset.name.title.id, 'Mrs', 'should have new change'); + assert.equal(dummyChangeset.get('name.title.id'), 'Mrs', 'should have new change using get'); + + changes = get(dummyChangeset, 'changes'); + assert.deepEqual(changes, [{ key: 'name.title', value: title2 }], 'changes with nested key Ember.set'); + + dummyChangeset.execute(); + + assert.equal(dummyModel.name.title.id, 'Mrs', 'has new property'); + }); + test('it works with setProperties', async function (assert) { let dummyChangeset = Changeset(dummyModel); let expectedResult = [ diff --git a/yarn.lock b/yarn.lock index f2b9c391..3eaf663a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13517,10 +13517,10 @@ validate-npm-package-name@~2.2.2: dependencies: builtins "0.0.7" -validated-changeset@~0.14.4: - version "0.14.4" - resolved "https://registry.yarnpkg.com/validated-changeset/-/validated-changeset-0.14.4.tgz#b8314a1fed15230901e12dec6ffb0eeea6edefbd" - integrity sha512-g0DFT5gbQcvz7r7QMCxbugAQU9kvjSgNlA9JtBM+RZzFE6B1RtW7EXOF7BA/PvAycqmONaqalFbCwA7Ih3l8UQ== +validated-changeset@~0.14.5: + version "0.14.5" + resolved "https://registry.yarnpkg.com/validated-changeset/-/validated-changeset-0.14.5.tgz#377feade30993b9eb7d0a87986483c36c8c71ad6" + integrity sha512-QKox80QIjm6I0jO13iVGb9KYpE2XmysaI+zv0wlBJvupUdKnzbtuDQIYm1W893ubl05oKi7TZLB2TNzvBXd1Jg== vary@~1.1.2: version "1.1.2"