不要怂,就是干,撸起袖子干!

Commit 4a072a5d by Jan Aagaard Meier

Merge pull request #4014 from dickie81/master

fixes problem with order in scope when counting
2 parents 96cd1a2c 90afc987
...@@ -1354,6 +1354,8 @@ Model.prototype.count = function(options) { ...@@ -1354,6 +1354,8 @@ Model.prototype.count = function(options) {
options.dataType = new DataTypes.INTEGER(); options.dataType = new DataTypes.INTEGER();
options.includeIgnoreAttributes = false; options.includeIgnoreAttributes = false;
options.limit = null; options.limit = null;
options.offset = null;
options.order = null;
return this.aggregate(col, 'count', options); return this.aggregate(col, 'count', options);
}; };
......
...@@ -1641,6 +1641,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1641,6 +1641,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
}); });
it('returns multiple rows when using group', function() { it('returns multiple rows when using group', function() {
var self = this; var self = this;
return this.User.bulkCreate([ return this.User.bulkCreate([
...@@ -1665,6 +1666,54 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1665,6 +1666,54 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
describe("options sent to aggregate", function () {
var options, aggregateSpy;
beforeEach(function () {
options = { where: { username: 'user1'}};
aggregateSpy = sinon.spy(this.User, "aggregate");
});
afterEach(function () {
expect(aggregateSpy).to.have.been.calledWith(
sinon.match.any, sinon.match.any,
sinon.match.object.and(sinon.match.has('where', { username: 'user1'})));
aggregateSpy.restore();
});
it('modifies option "limit" by setting it to null', function() {
options.limit = 5;
return this.User.count(options).then(function() {
expect(aggregateSpy).to.have.been.calledWith(
sinon.match.any, sinon.match.any,
sinon.match.object.and(sinon.match.has('limit', null)));
});
});
it('modifies option "offset" by setting it to null', function() {
options.offset = 10;
return this.User.count(options).then(function() {
expect(aggregateSpy).to.have.been.calledWith(
sinon.match.any, sinon.match.any,
sinon.match.object.and(sinon.match.has('offset', null)));
});
});
it('modifies option "order" by setting it to null', function() {
options.order = "username";
return this.User.count(options).then(function() {
expect(aggregateSpy).to.have.been.calledWith(
sinon.match.any, sinon.match.any,
sinon.match.object.and(sinon.match.has('order', null)));
});
});
});
it('allows sql logging', function() { it('allows sql logging', function() {
var test = false; var test = false;
return this.User.count({ return this.User.count({
......
...@@ -31,6 +31,9 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -31,6 +31,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
lte: 5 lte: 5
} }
} }
},
withOrder: {
order: 'username'
} }
} }
}); });
...@@ -65,6 +68,10 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -65,6 +68,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it('should be able to merge scopes with where', function () { it('should be able to merge scopes with where', function () {
return expect(this.ScopeMe.scope('lowAccess').count({ where: { username: 'dan'}})).to.eventually.equal(1); return expect(this.ScopeMe.scope('lowAccess').count({ where: { username: 'dan'}})).to.eventually.equal(1);
}); });
it('should ignore the order option if it is found within the scope', function () {
return expect(this.ScopeMe.scope('withOrder').count()).to.eventually.equal(4);
});
}); });
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!