Skip to content

Commit c26b0ff

Browse files
author
Brian Romanko
committed
Adding a test to ensure that point properties are pulled from the database correctly
1 parent e8342bd commit c26b0ff

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lib/Drivers/DML/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Driver.prototype.propertyToValue = function (value, property) {
247247
case "object":
248248
return JSON.stringify(value);
249249
case "point":
250-
return function() { return 'POINT(' + value[0] + ', ' + value[1] + ')'; };
250+
return function() { return 'POINT(' + value.x + ', ' + value.y + ')'; };
251251
default:
252252
return value;
253253
}

test/integration2/model-get.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,33 @@ describe("Model.get()", function() {
276276
});
277277
});
278278
});
279+
280+
describe("with a point property type", function() {
281+
before(function (done) {
282+
Person = db.define("person", {
283+
name : String,
284+
location: {type: 'point'}
285+
});
286+
287+
ORM.singleton.clear();
288+
289+
return helper.dropSync(Person, function () {
290+
Person.create([{
291+
name : "John Doe",
292+
location: {x: 51.5177, y: -0.0968}
293+
}], done);
294+
});
295+
});
296+
297+
it("should deserialize the point to an array", function (done) {
298+
Person.get("John Doe", function(err, person) {
299+
should.equal(err, null);
300+
301+
person.location.should.be.an.instanceOf(Object);
302+
person.location.should.have.property('x', 51.5177);
303+
person.location.should.have.property('y', -0.0968);
304+
return done();
305+
});
306+
});
307+
});
279308
});

test/integration2/model-save.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,14 @@ describe("Model.save()", function() {
202202

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

210-
John.name.should.be.an.instanceOf(Array);
211-
John.name.should.have.length(2);
212-
John.name[0].should.equal(51.5177);
213-
John.name[1].should.equal(-0.0968);
210+
John.name.should.be.an.instanceOf(Object);
211+
John.name.should.have.property('x', 51.5177);
212+
John.name.should.have.property('y', -0.0968);
214213
return done();
215214
});
216215
});

0 commit comments

Comments
 (0)