findall.test.js
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, sinon = require('sinon')
, DataTypes = require(__dirname + '/../../../lib/data-types');
describe(Support.getTestDialectTeaser('Model'), function() {
describe('method findAll', function () {
var Model = current.define('model', {
name: DataTypes.STRING
}, { timestamps: false });
before(function () {
this.stub = sinon.stub(current.getQueryInterface(), 'select', function () {
return Model.build({});
});
});
beforeEach(function () {
this.stub.reset();
});
after(function () {
this.stub.restore();
});
describe('attributes include / exclude', function () {
it('allows me to include additional attributes', function () {
return Model.findAll({
attributes: {
include: ['foobar']
}
}).bind(this).then(function () {
expect(this.stub.getCall(0).args[2].attributes).to.deep.equal([
'id',
'name',
'foobar'
]);
});
});
it('allows me to exclude attributes', function () {
return Model.findAll({
attributes: {
exclude: ['name']
}
}).bind(this).then(function () {
expect(this.stub.getCall(0).args[2].attributes).to.deep.equal([
'id'
]);
});
});
it('include takes precendence over exclude', function () {
return Model.findAll({
attributes: {
exclude: ['name'],
include: ['name']
}
}).bind(this).then(function () {
expect(this.stub.getCall(0).args[2].attributes).to.deep.equal([
'id',
'name'
]);
});
});
it('works for models without PK #4607', function () {
var Model = current.define('model', {}, { timestamps: false });
var Foo = current.define('foo');
Model.hasOne(Foo);
Model.removeAttribute('id');
return Model.findAll({
attributes: {
include: ['name']
},
include: [Foo]
}).bind(this).then(function () {
expect(this.stub.getCall(0).args[2].attributes).to.deep.equal([
'name'
]);
});
});
});
});
});