Skip to content

Commit a6f458b

Browse files
committed
Add mapsTo test
1 parent a30488d commit a6f458b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/integration/model-get.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
var _ = require('lodash');
12
var should = require('should');
23
var helper = require('../support/spec_helper');
34
var common = require('../common');
45
var ORM = require('../../');
6+
var protocol = common.protocol();
57

68
describe("Model.get()", function() {
79
var db = null;
@@ -11,7 +13,7 @@ describe("Model.get()", function() {
1113
var setup = function (cache) {
1214
return function (done) {
1315
Person = db.define("person", {
14-
name : String
16+
name : { type: 'text', mapsTo: 'fullname' }
1517
}, {
1618
cache : cache,
1719
methods: {
@@ -49,6 +51,33 @@ describe("Model.get()", function() {
4951
return db.close();
5052
});
5153

54+
describe("mapsTo", function () {
55+
if (protocol == 'mongodb') return;
56+
57+
before(setup(true));
58+
59+
it("should create the table with a different column name than property name", function (done) {
60+
var sql;
61+
62+
if (protocol == 'sqlite') {
63+
sql = "PRAGMA table_info(?)";
64+
} else {
65+
sql = "SELECT column_name FROM information_schema.columns WHERE table_name = ?";
66+
}
67+
68+
db.driver.execQuery(sql, [Person.table], function (err, data) {
69+
should.not.exist(err);
70+
71+
var names = _.pluck(data, protocol == 'sqlite' ? 'name' : 'column_name')
72+
73+
should.equal(typeof Person.properties.name, 'object');
74+
should.notEqual(names.indexOf('fullname'), -1);
75+
76+
done();
77+
});
78+
});
79+
});
80+
5281
describe("with cache", function () {
5382
before(setup(true));
5483

0 commit comments

Comments
 (0)