Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from grebaldi/release/1.2.1
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
grebaldi authored Oct 7, 2016
2 parents 7b3ab70 + b3561f2 commit f832976
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ cache:
notifications:
email: false
node_js:
- '4'
before_install:
- npm i -g npm@^2.0.0
- '6'
before_script:
- npm prune
after_success:
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/molecules/merge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const merge = (path, value, subject) => Object.keys(value).reduce(
return merge([...path, key], value[key], subject);
}

return $set([...resolveObjectPath(path), ...key], value[key], subject);
return $set([...resolveObjectPath(path), key], value[key], subject);
},
subject
);
Expand Down
30 changes: 30 additions & 0 deletions src/migrations/molecules/merge/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ describe('Migrations > Atoms > $merge', () => {
const subject = undefined;
expect($merge('some.path', {some: 'value'}, subject)).to.be.an('undefined');
});

it('should not split up keys in deep object structures (bugfix #12)', () => {
const subject = {
test: {
a: {
b: {
cdef: 'c'
}
}
}
};
const result = $merge('test', {
a: {
b: {
cdef: 'foo'
}
}
}, subject);

expect(result.test.a.b.c).to.be.an('undefined');
expect(result).to.deep.equal({
test: {
a: {
b: {
cdef: 'foo'
}
}
}
});
});
});

describe('Immutable', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/resolveObjectPath/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default path => {
return path.split('.').map(part => {
const partAsInteger = parseInt(part);

if (!isNaN(partAsInteger)) {
if (!isNaN(partAsInteger) && String(partAsInteger) === part) {
return partAsInteger;
}

Expand Down
2 changes: 2 additions & 0 deletions src/util/resolveObjectPath/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ describe('Internals: resolveObjectPath', () => {
expect(resolveObjectPath('a.b.c')).to.deep.equal(['a', 'b', 'c']);
expect(resolveObjectPath('a.b.c.1')).to.deep.equal(['a', 'b', 'c', 1]);
expect(resolveObjectPath('a.b.c.1.d.0')).to.deep.equal(['a', 'b', 'c', 1, 'd', 0]);
expect(resolveObjectPath('a.1.c1.2d.d.0')).to.deep.equal(['a', 1, 'c1', '2d', 'd', 0]);
});

it('should leave arrays untouched', () => {
expect(resolveObjectPath(['a'])).to.deep.equal(['a']);
expect(resolveObjectPath(['a', 1, 'b'])).to.deep.equal(['a', 1, 'b']);
expect(resolveObjectPath(['a', '2', 'c'])).to.deep.equal(['a', '2', 'c']);
expect(resolveObjectPath(['a', '2', 'c', '3d'])).to.deep.equal(['a', '2', 'c', '3d']);
});
});

0 comments on commit f832976

Please sign in to comment.