@@ -23,90 +23,113 @@ module ForestLiana
2323 }
2424 end
2525
26- let ( :model ) { Tree }
27- let ( :collection ) { 'trees' }
28- let ( :params ) {
29- {
30- type : 'Pie' ,
31- sourceCollectionName : collection ,
32- timezone : 'Europe/Paris' ,
33- aggregator : 'Count' ,
34- groupByFieldName : groupByFieldName
26+ describe 'with not allowed aggregator' do
27+ let ( :scopes ) { { } }
28+ let ( :model ) { Tree }
29+ let ( :collection ) { 'trees' }
30+ let ( :params ) {
31+ {
32+ type : 'Pie' ,
33+ sourceCollectionName : collection ,
34+ timezone : 'Europe/Paris' ,
35+ aggregator : 'eval' ,
36+ groupByFieldName : '`ls`'
37+ }
3538 }
36- }
3739
38- subject { PieStatGetter . new ( model , params , user ) }
40+ it 'should raise an error' do
41+ expect {
42+ PieStatGetter . new ( model , params , user )
43+ } . to raise_error ( ForestLiana ::Errors ::HTTP422Error , 'Invalid aggregate function' )
44+ end
45+ end
3946
40- describe 'with empty scopes' do
41- let ( :scopes ) { { } }
47+ describe 'with valid aggregate function' do
48+ let ( :model ) { Tree }
49+ let ( :collection ) { 'trees' }
50+ let ( :params ) {
51+ {
52+ type : 'Pie' ,
53+ sourceCollectionName : collection ,
54+ timezone : 'Europe/Paris' ,
55+ aggregator : 'Count' ,
56+ groupByFieldName : groupByFieldName
57+ }
58+ }
4259
43- describe 'with an aggregate on the name field' do
44- let ( :groupByFieldName ) { 'name' }
45-
46- it 'should be as many categories as records count' do
47- subject . perform
48- expect ( subject . record . value ) . to match_array ( [
49- { :key => "Old Tree n1" , :value => 1 } ,
50- { :key => "Old Tree n2" , :value => 1 } ,
51- { :key => "Old Tree n3" , :value => 1 } ,
52- { :key => "Old Tree n4" , :value => 1 } ,
53- { :key => "Young Tree n1" , :value => 1 } ,
54- { :key => "Young Tree n2" , :value => 1 } ,
55- { :key => "Young Tree n3" , :value => 1 } ,
56- { :key => "Young Tree n4" , :value => 1 } ,
57- { :key => "Young Tree n5" , :value => 1 }
58- ] )
60+ subject { PieStatGetter . new ( model , params , user ) }
61+
62+ describe 'with empty scopes' do
63+ let ( :scopes ) { { } }
64+
65+ describe 'with an aggregate on the name field' do
66+ let ( :groupByFieldName ) { 'name' }
67+
68+ it 'should be as many categories as records count' do
69+ subject . perform
70+ expect ( subject . record . value ) . to match_array ( [
71+ { :key => "Old Tree n1" , :value => 1 } ,
72+ { :key => "Old Tree n2" , :value => 1 } ,
73+ { :key => "Old Tree n3" , :value => 1 } ,
74+ { :key => "Old Tree n4" , :value => 1 } ,
75+ { :key => "Young Tree n1" , :value => 1 } ,
76+ { :key => "Young Tree n2" , :value => 1 } ,
77+ { :key => "Young Tree n3" , :value => 1 } ,
78+ { :key => "Young Tree n4" , :value => 1 } ,
79+ { :key => "Young Tree n5" , :value => 1 }
80+ ] )
81+ end
5982 end
60- end
6183
62- describe 'with an aggregate on the age field' do
63- let ( :groupByFieldName ) { 'age' }
84+ describe 'with an aggregate on the age field' do
85+ let ( :groupByFieldName ) { 'age' }
6486
65- it 'should be as many categories as different ages among records' do
66- subject . perform
67- expect ( subject . record . value ) . to eq [ { :key => 3 , :value => 5 } , { :key => 15 , :value => 4 } ]
87+ it 'should be as many categories as different ages among records' do
88+ subject . perform
89+ expect ( subject . record . value ) . to eq [ { :key => 3 , :value => 5 } , { :key => 15 , :value => 4 } ]
90+ end
6891 end
6992 end
70- end
7193
72- describe 'with scopes' do
73- let ( :scopes ) {
74- {
75- 'Tree' => {
76- 'scope' => {
77- 'filter' => {
78- 'aggregator' => 'and' ,
79- 'conditions' => [
80- { 'field' => 'age' , 'operator' => 'less_than' , 'value' => 10 }
81- ]
82- } ,
83- 'dynamicScopesValues' => { }
94+ describe 'with scopes' do
95+ let ( :scopes ) {
96+ {
97+ 'Tree' => {
98+ 'scope' => {
99+ 'filter' => {
100+ 'aggregator' => 'and' ,
101+ 'conditions' => [
102+ { 'field' => 'age' , 'operator' => 'less_than' , 'value' => 10 }
103+ ]
104+ } ,
105+ 'dynamicScopesValues' => { }
106+ }
84107 }
85108 }
86109 }
87- }
88110
89- describe 'with an aggregate on the name field' do
90- let ( :groupByFieldName ) { 'name' }
91-
92- it 'should be as many categories as records inside the scope' do
93- subject . perform
94- expect ( subject . record . value ) . to match_array ( [
95- { :key => "Young Tree n1" , :value => 1 } ,
96- { :key => "Young Tree n2" , :value => 1 } ,
97- { :key => "Young Tree n3" , :value => 1 } ,
98- { :key => "Young Tree n4" , :value => 1 } ,
99- { :key => "Young Tree n5" , :value => 1 }
100- ] )
111+ describe 'with an aggregate on the name field' do
112+ let ( :groupByFieldName ) { 'name' }
113+
114+ it 'should be as many categories as records inside the scope' do
115+ subject . perform
116+ expect ( subject . record . value ) . to match_array ( [
117+ { :key => "Young Tree n1" , :value => 1 } ,
118+ { :key => "Young Tree n2" , :value => 1 } ,
119+ { :key => "Young Tree n3" , :value => 1 } ,
120+ { :key => "Young Tree n4" , :value => 1 } ,
121+ { :key => "Young Tree n5" , :value => 1 }
122+ ] )
123+ end
101124 end
102- end
103125
104- describe 'with an aggregate on the age field' do
105- let ( :groupByFieldName ) { 'age' }
126+ describe 'with an aggregate on the age field' do
127+ let ( :groupByFieldName ) { 'age' }
106128
107- it 'should be only one category' do
108- subject . perform
109- expect ( subject . record . value ) . to eq [ { :key => 3 , :value => 5 } ]
129+ it 'should be only one category' do
130+ subject . perform
131+ expect ( subject . record . value ) . to eq [ { :key => 3 , :value => 5 } ]
132+ end
110133 end
111134 end
112135 end
0 commit comments