Skip to content

Commit

Permalink
fix(serializer): fixes decoder being called on mapped properties even if
Browse files Browse the repository at this point in the history
the parent object was null.

Relates to #59
  • Loading branch information
iobaixas committed Oct 24, 2015
1 parent 05ab547 commit e8041b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/module/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
RMModule.factory('RMSerializer', ['$injector', 'inflector', '$filter', 'RMUtils', function($injector, inflector, $filter, Utils) {

function extract(_from, _path) {
if(_from === null && _path.length > 1) return undefined;

var node;
for(var i = 0; _from && (node = _path[i]); i++) {
_from = _from[node];
Expand Down
10 changes: 10 additions & 0 deletions test/serializer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ describe('Restmod serializer', function() {
expect(result.brand.full_name).toEqual('Giant');
});

it('should properly handle null parent when processing nested properties', function() {
var spy = jasmine.createSpy();

serializer.dsl().attrMap('brand', 'brand.full_name');
serializer.dsl().attrDecoder('brand', spy);

serializer.decode({}, null, '');
expect(spy).not.toHaveBeenCalled();
});

it('should allow mapping to a server property inside an ignored property', function() {
serializer.dsl().attrMap('brandName', 'brand.full_name');
serializer.dsl().attrMask('brand', true);
Expand Down

0 comments on commit e8041b8

Please sign in to comment.