Skip to content

Commit

Permalink
Merge pull request #21 from silvolu/master
Browse files Browse the repository at this point in the history
Fixed type checks for Boolean and Number primitive types in valueToProperty
  • Loading branch information
Burcu Dogan committed Jul 17, 2014
2 parents 1ef6202 + 01e782f commit 8614669
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ TODO
Get operations require a valid key to retrieve the key identified entity from Datastore. Skip to the "Querying" section if you'd like to learn more about querying against Datastore.

~~~~ js
ds.get(['Company', 123], function(err, obj) {
ds.get(['Company', 123], function(err, key, obj) {

});
// alternatively, you can retrieve multiple entities at once.
ds.getAll([key1, key2, ...], function(err, objs) {
ds.getAll([key1, key2, ...], function(err, keys, objs) {

});
~~~~
Expand Down
4 changes: 2 additions & 2 deletions lib/datastore/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module.exports.entityFromEntityProto = entityFromEntityProto;
*/
function valueToProperty(v) {
var p = {};
if (v instanceof Boolean) {
if (v instanceof Boolean || typeof v === 'boolean') {
p.booleanValue = v;
return p;
}
Expand All @@ -192,7 +192,7 @@ function valueToProperty(v) {
p.doubleValue = v.get();
return p;
}
if (v instanceof Number) {
if (v instanceof Number || typeof v === 'number') {
if (v % 1 === 0) {
p.integerValue = v;
} else {
Expand Down
4 changes: 4 additions & 0 deletions test/datastore.entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ describe('entityToEntityProto', function() {
name: 'Burcu',
desc: 'Description',
count: new entity.Int(6),
primitiveCount: 6,
legit: true,
date : now,
bytes: new Buffer("Hello"),
list: ['a', new entity.Double(54.7)],
Expand All @@ -193,6 +195,8 @@ describe('entityToEntityProto', function() {
assert.equal(proto.properties.name.stringValue, 'Burcu');
assert.equal(proto.properties.desc.stringValue, 'Description');
assert.equal(proto.properties.count.integerValue, 6);
assert.equal(proto.properties.primitiveCount.integerValue, 6);
assert.equal(proto.properties.legit.booleanValue, true);
assert.equal(proto.properties.date.dateTimeValue, now);
assert.equal(proto.properties.bytes.blobValue, 'SGVsbG8=');
assert.equal(proto.properties.list.listValue[0].stringValue, 'a');
Expand Down

0 comments on commit 8614669

Please sign in to comment.