@@ -11,6 +11,7 @@ module ForestLiana
1111 let ( :date_condition_1 ) { { 'field' => 'created_at' , 'operator' => 'before' , 'value' => 2 . hours . ago } }
1212 let ( :date_condition_2 ) { { 'field' => 'created_at' , 'operator' => 'today' } }
1313 let ( :date_condition_3 ) { { 'field' => 'created_at' , 'operator' => 'previous_x_days' , 'value' => 2 } }
14+ let ( :presence_condition ) { { 'field' => 'name' , 'operator' => 'present' } }
1415
1516 before {
1617 island = Island . create! ( name : "L'île de la muerta" )
@@ -274,14 +275,39 @@ module ForestLiana
274275 let ( :filters ) { { 'aggregator' => 'or' , 'conditions' => [ simple_condition_2 , simple_condition_3 ] } }
275276 it { expect ( resource . where ( query ) . count ) . to eq 2 }
276277 end
278+
279+ context "'name ends_with \" 3\" ' 'or' 'name is not null'" do
280+ let ( :filters ) { { 'aggregator' => 'or' , 'conditions' => [ simple_condition_2 , presence_condition ] } }
281+ it { expect ( resource . where ( query ) . count ) . to eq 3 }
282+ end
277283 end
278284
279285 describe 'parse_condition' do
280286 let ( :condition ) { simple_condition_2 }
281287 let ( :result ) { filter_parser . parse_condition ( condition ) }
282288
283289 context 'on valid condition' do
284- it { expect ( result ) . to eq "\" trees\" .\" name\" LIKE ('%3')" }
290+ context 'when the condition uses the contains operator' do
291+ it { expect ( result ) . to eq "\" trees\" .\" name\" LIKE '%3'" }
292+ end
293+
294+ context 'when the condition uses the blank operator' do
295+ let ( :condition ) { { 'field' => 'name' , 'operator' => 'blank' } }
296+
297+ it { expect ( result ) . to eq "\" trees\" .\" name\" IS NULL" }
298+ end
299+
300+ context 'when the condition uses the presence operator' do
301+ let ( :condition ) { presence_condition }
302+
303+ it { expect ( result ) . to eq "\" trees\" .\" name\" IS NOT NULL" }
304+ end
305+
306+ context 'when the condition uses the in operator' do
307+ let ( :condition ) { { 'field' => 'name' , 'operator' => 'in' , 'value' => [ 'Tree n1' , 'Tree n3' ] } }
308+
309+ it { expect ( result ) . to eq "\" trees\" .\" name\" IN ('Tree n1','Tree n3')" }
310+ end
285311 end
286312
287313 context 'on belongs_to condition' do
0 commit comments