@@ -55,6 +55,56 @@ describe("Model.aggregate()", function() {
5555 } ) ;
5656 } ) ;
5757
58+ describe ( "with call()" , function ( ) {
59+ before ( setup ( ) ) ;
60+
61+ it ( "should accept a function" , function ( done ) {
62+ Person . aggregate ( ) . call ( 'COUNT' ) . get ( function ( err , count ) {
63+ should . equal ( err , null ) ;
64+
65+ count . should . equal ( 3 ) ;
66+
67+ return done ( ) ;
68+ } ) ;
69+ } ) ;
70+
71+ it ( "should accept arguments to the funciton as an Array" , function ( done ) {
72+ Person . aggregate ( ) . call ( 'COUNT' , [ 'id' ] ) . get ( function ( err , count ) {
73+ should . equal ( err , null ) ;
74+
75+ count . should . equal ( 3 ) ;
76+
77+ return done ( ) ;
78+ } ) ;
79+ } ) ;
80+
81+ describe ( "if function is DISTINCT" , function ( ) {
82+ it ( "should work as calling .distinct() directly" , function ( done ) {
83+ Person . aggregate ( ) . call ( 'DISTINCT' , [ 'name' ] ) . as ( 'name' ) . order ( 'name' ) . get ( function ( err , rows ) {
84+ should . equal ( err , null ) ;
85+
86+ should ( Array . isArray ( rows ) ) ;
87+ rows . length . should . equal ( 2 ) ;
88+
89+ rows [ 0 ] . should . equal ( 'Jane Doe' ) ;
90+ rows [ 1 ] . should . equal ( 'John Doe' ) ;
91+
92+ return done ( ) ;
93+ } ) ;
94+ } ) ;
95+ } ) ;
96+ } ) ;
97+
98+ describe ( "with as() without previous aggregates" , function ( ) {
99+ before ( setup ( ) ) ;
100+
101+ it ( "should throw" , function ( done ) {
102+ Person . aggregate ( ) . as . should . throw ( ) ;
103+
104+ return done ( ) ;
105+ } ) ;
106+ } ) ;
107+
58108 describe ( "with select() without arguments" , function ( ) {
59109 before ( setup ( ) ) ;
60110
0 commit comments