Skip to content

Commit

Permalink
[Bug]: setDeep does not respect re-setting top level Change object (#593
Browse files Browse the repository at this point in the history
)

* [Bug]: setDeep does not respect re-setting top level Change object

* add tests from issue
  • Loading branch information
snewcomer authored May 17, 2021
1 parent d5ca770 commit 9f32592
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/changeset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9f32592

Please sign in to comment.