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

Follow up: Check array type as well #413

Merged
merged 3 commits into from
Jan 18, 2020
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
2 changes: 1 addition & 1 deletion addon/-private/validated-changeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ export class BufferedChangeset implements IChangeset {
// requested key is the top most nested property and we have changes in of the properties, we need to
// merge the original model data with the changes to have the complete object.
// eg. model = { user: { name: 'not changed', email: '[email protected]'} }
if (isObject(content[baseKey]) && !isEmberDataObject(content[baseKey])) {
if (!Array.isArray(result) && isObject(content[baseKey]) && !isEmberDataObject(content[baseKey])) {
let data: Record<string, any> = {}
Object.keys(content[baseKey]).forEach(k => {
data[k] = this.getDeep(content, `${baseKey}.${k}`)
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/components/changeset-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Changeset from 'ember-changeset'
export default class ChangesetForm extends Component {
model = {
user: {
aliases: ['someone'],
name: 'someone',
email: 'something'
},
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/changeset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ module('Unit | Utility | changeset', function(hooks) {
assert.equal(result, undefined, 'should proxy to change');
});

test('#get returns change that is has undefined as value', async function(assert) {
set(dummyModel, 'name', 'Bob');
set(dummyModel, 'creds', ['burgers']);
let dummyChangeset = new Changeset(dummyModel);
set(dummyChangeset, 'name', 'Burdger');

assert.equal(get(dummyChangeset, 'name'), 'Burdger', 'should proxy name to change');
assert.deepEqual(get(dummyChangeset, 'creds'), ['burgers'], 'should proxy creds to change');

set(dummyChangeset, 'creds', ['fries']);
assert.equal(get(dummyChangeset, 'name'), 'Burdger', 'should proxy name to change');
assert.deepEqual(get(dummyChangeset, 'creds'), ['fries'], 'should proxy creds to change after change');
});

test('nested objects will return correct values', async function(assert) {
set(dummyModel, 'org', {
asia: { sg: '_initial' }, // for the sake of disambiguating nulls
Expand Down