Skip to content

Commit

Permalink
Adding a test to ensure that point properties are pulled from the dat…
Browse files Browse the repository at this point in the history
…abase correctly
  • Loading branch information
Brian Romanko committed Jul 6, 2013
1 parent e8342bd commit c26b0ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Drivers/DML/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Driver.prototype.propertyToValue = function (value, property) {
case "object":
return JSON.stringify(value);
case "point":
return function() { return 'POINT(' + value[0] + ', ' + value[1] + ')'; };
return function() { return 'POINT(' + value.x + ', ' + value.y + ')'; };
default:
return value;
}
Expand Down
29 changes: 29 additions & 0 deletions test/integration2/model-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,33 @@ describe("Model.get()", function() {
});
});
});

describe("with a point property type", function() {
before(function (done) {
Person = db.define("person", {
name : String,
location: {type: 'point'}
});

ORM.singleton.clear();

return helper.dropSync(Person, function () {
Person.create([{
name : "John Doe",
location: {x: 51.5177, y: -0.0968}
}], done);
});
});

it("should deserialize the point to an array", function (done) {
Person.get("John Doe", function(err, person) {
should.equal(err, null);

person.location.should.be.an.instanceOf(Object);
person.location.should.have.property('x', 51.5177);
person.location.should.have.property('y', -0.0968);
return done();
});
});
});
});
9 changes: 4 additions & 5 deletions test/integration2/model-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@ describe("Model.save()", function() {

it("should save the instance as a geospatial point", function (done) {
var John = new Person({
name: [51.5177, -0.0968]
name: {x: 51.5177, y: -0.0968}
});
John.save(function (err) {
should.equal(err, null);

John.name.should.be.an.instanceOf(Array);
John.name.should.have.length(2);
John.name[0].should.equal(51.5177);
John.name[1].should.equal(-0.0968);
John.name.should.be.an.instanceOf(Object);
John.name.should.have.property('x', 51.5177);
John.name.should.have.property('y', -0.0968);
return done();
});
});
Expand Down

0 comments on commit c26b0ff

Please sign in to comment.