Skip to content

Commit

Permalink
datastore: allow storing empty objects (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and callmehiphop committed Jul 27, 2016
1 parent 9cdcef5 commit c741869
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/datastore/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,12 @@ function encodeValue(value) {
return valueProto;
}

if (is.object(value) && !is.empty(value)) {
for (var prop in value) {
if (value.hasOwnProperty(prop)) {
value[prop] = entity.encodeValue(value[prop]);
if (is.object(value)) {
if (!is.empty(value)) {
for (var prop in value) {
if (value.hasOwnProperty(prop)) {
value[prop] = entity.encodeValue(value[prop]);
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion test/datastore/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,21 @@ describe('entity', function() {
assert.deepEqual(entity.encodeValue(value), expectedValueProto);
});

it('should encode an empty object', function() {
var value = {};

var expectedValueProto = {
entityValue: {
properties: {}
}
};

assert.deepEqual(entity.encodeValue(value), expectedValueProto);
});

it('should throw if an invalid value was provided', function() {
assert.throws(function() {
entity.encodeValue({});
entity.encodeValue();
}, /Unsupported field value/);
});
});
Expand Down

0 comments on commit c741869

Please sign in to comment.