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

Fixed type checks for Boolean and Number primitive types in valueToProperty #21

Merged
merged 3 commits into from
Jul 17, 2014
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
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