hoodoo 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,10 +58,20 @@ module Hoodoo; module Services
58
58
  #
59
59
  attr_reader :search
60
60
 
61
+ # Array of prohibited framework search keys as Strings; empty for none
62
+ # defined.
63
+ #
64
+ attr_reader :do_not_search
65
+
61
66
  # Array of supported filter keys as Strings; empty for none defined.
62
67
  #
63
68
  attr_reader :filter
64
69
 
70
+ # Array of prohibited framewor filter keys as Strings; empty for none
71
+ # defined.
72
+ #
73
+ attr_reader :do_not_filter
74
+
65
75
  # Create an instance with default settings.
66
76
  #
67
77
  def initialize
@@ -74,7 +84,9 @@ module Hoodoo; module Services
74
84
  @sort = { 'created_at' => Set.new( [ 'desc', 'asc' ] ) }
75
85
  @default_sort_key = 'created_at'
76
86
  @search = []
87
+ @do_not_search = []
77
88
  @filter = []
89
+ @do_not_filter = []
78
90
  end
79
91
 
80
92
  private
@@ -103,12 +115,24 @@ module Hoodoo; module Services
103
115
  #
104
116
  attr_writer :search
105
117
 
118
+ # Private writer - see #do_not_search - but there's a special contract
119
+ # with Hoodoo::Services::Interface::ToListDSL which permits it to call
120
+ # here bypassing +private+ via +send()+.
121
+ #
122
+ attr_writer :do_not_search
123
+
106
124
  # Private writer - see #filter - but there's a special contract with
107
125
  # Hoodoo::Services::Interface::ToListDSL which permits it to call here
108
126
  # bypassing +private+ via +send()+.
109
127
  #
110
128
  attr_writer :filter
111
129
 
130
+ # Private writer - see #do_not_filter - but there's a special contract
131
+ # with Hoodoo::Services::Interface::ToListDSL which permits it to call
132
+ # here bypassing +private+ via +send()+.
133
+ #
134
+ attr_writer :do_not_filter
135
+
112
136
  end # 'class ToList'
113
137
 
114
138
  ###########################################################################
@@ -223,25 +247,59 @@ module Hoodoo; module Services
223
247
  # value escaping and validation, if necessary, is up to the service
224
248
  # implementation.
225
249
  #
226
- # +search+:: Array of permitted search keys, as symbols or strings.
227
- # The order of array entries is arbitrary.
250
+ # +keys+:: Array of permitted search keys, as symbols or strings.
251
+ # The order of array entries is arbitrary.
228
252
  #
229
253
  # Example - allow searches specifying +first_name+ and +last_name+ keys:
230
254
  #
231
255
  # search :first_name, :last_name
232
256
  #
233
- def search( *search )
234
- @tl.send( :search=, search.map { | item | item.to_s } )
257
+ def search( *keys )
258
+ @tl.send( :search=, keys.map { | item | item.to_s } )
259
+ end
260
+
261
+ # Similar to #search, but for default Hoodoo framework exclusions. The
262
+ # Hoodoo::Services::Middleware +FRAMEWORK_QUERY_DATA+ array lists the
263
+ # known framework keys for a given Hoodoo version. An exception is
264
+ # raised if an attempt is made to exclude unknown keys.
265
+ #
266
+ # +keys+:: Array of prohibited framework search keys, as symbols or
267
+ # strings. The order of array entries is arbitrary.
268
+ #
269
+ def do_not_search( *keys )
270
+ @tl.send( :do_not_search=, keys.map { | item | item.to_s } )
271
+
272
+ unknown = @tl.do_not_search() - Hoodoo::Services::Middleware::FRAMEWORK_QUERY_DATA.keys
273
+
274
+ unless unknown.empty?
275
+ raise "Hoodoo::Services::Interface::ToListDSL\#do_not_search was given one or more unknown keys: #{ unknown.join( ', ' ) }"
276
+ end
235
277
  end
236
278
 
237
279
  # As #search, but for filtering.
238
280
  #
239
- # +filter+:: Array of permitted filter keys, as symbols or strings.
240
- # The order of array entries is arbitrary.
281
+ # +keys+:: Array of permitted filter keys, as symbols or strings.
282
+ # The order of array entries is arbitrary.
241
283
  #
242
- def filter( *filter )
243
- @tl.send( :filter=, filter.map { | item | item.to_s } )
284
+ def filter( *keys )
285
+ @tl.send( :filter=, keys.map { | item | item.to_s } )
244
286
  end
287
+
288
+ # As #do_not_search, but for default Hoodoo framework exclusions.
289
+ #
290
+ # +keys+:: Array of prohibited framework filter keys, as symbols or
291
+ # strings. The order of array entries is arbitrary.
292
+ #
293
+ def do_not_filter( *keys )
294
+ @tl.send( :do_not_filter=, keys.map { | item | item.to_s } )
295
+
296
+ unknown = @tl.do_not_filter() - Hoodoo::Services::Middleware::FRAMEWORK_QUERY_DATA.keys
297
+
298
+ unless unknown.empty?
299
+ raise "Hoodoo::Services::Interface::ToListDSL\#do_not_filter was given one or more unknown keys: #{ unknown.join( ', ' ) }"
300
+ end
301
+ end
302
+
245
303
  end # 'class ToListDSL'
246
304
 
247
305
  ###########################################################################
@@ -12,6 +12,6 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, ensure that the date in
13
13
  # "hoodoo.gemspec" is correct and run "bundle install" (or "update").
14
14
  #
15
- VERSION = '1.11.0'
15
+ VERSION = '1.12.0'
16
16
 
17
17
  end
@@ -73,31 +73,31 @@ describe Hoodoo::ActiveRecord::Finder do
73
73
  self.table_name = :r_spec_model_finder_tests
74
74
  sh = Hoodoo::ActiveRecord::Finder::SearchHelper
75
75
 
76
- search_with(
76
+ search_and_filter_map = {
77
77
  'mapped_code' => sh.cs_match( 'code' ),
78
78
  :mapped_field_one => sh.ci_match_generic( 'field_one' ),
79
79
  :wild_field_one => sh.ciaw_match_generic( 'field_one '),
80
80
  :field_two => sh.cs_match_csv(),
81
- 'field_three' => sh.cs_match_array()
82
- )
81
+ 'field_three' => sh.cs_match_array(),
82
+ 'created_after' => sh.cs_gte( 'updated_at' )
83
+ }
83
84
 
84
- filter_with(
85
- 'mapped_code' => sh.cs_match( 'code' ),
86
- :mapped_field_one => sh.ci_match_postgres( 'field_one' ),
87
- :wild_field_one => sh.ciaw_match_postgres( 'field_one '),
88
- :field_two => sh.cs_match_csv(),
89
- 'field_three' => sh.cs_match_array()
90
- )
85
+ search_with( search_and_filter_map )
86
+ filter_with( search_and_filter_map )
91
87
  end
92
88
  end
93
89
 
94
90
  before :each do
91
+ @tn = Time.now.round()
92
+
95
93
  @a = RSpecModelFinderTest.new
96
94
  @a.id = "one"
97
95
  @a.code = 'A' # Must be set else SQLite fails to find this if you search for "code != 'C'" (!)
98
96
  @a.field_one = 'group 1'
99
97
  @a.field_two = 'two a'
100
98
  @a.field_three = 'three a'
99
+ @a.created_at = @tn - 1.year
100
+ @a.updated_at = @tn - 1.month
101
101
  @a.save!
102
102
  @id = @a.id
103
103
 
@@ -108,6 +108,8 @@ describe Hoodoo::ActiveRecord::Finder do
108
108
  @b.field_one = 'group 1'
109
109
  @b.field_two = 'two b'
110
110
  @b.field_three = 'three b'
111
+ @b.created_at = @tn - 1.month
112
+ @b.updated_at = @tn - 1.week
111
113
  @b.save!
112
114
  @uuid = @b.uuid
113
115
 
@@ -117,6 +119,8 @@ describe Hoodoo::ActiveRecord::Finder do
117
119
  @c.field_one = 'group 2'
118
120
  @c.field_two = 'two c'
119
121
  @c.field_three = 'three c'
122
+ @c.created_at = @tn
123
+ @c.updated_at = @tn + 1.day
120
124
  @c.save!
121
125
  @code = @c.code
122
126
 
@@ -610,6 +614,27 @@ describe Hoodoo::ActiveRecord::Finder do
610
614
 
611
615
  finder = RSpecModelFinderTest.list( @list_params )
612
616
  expect( finder ).to eq([@c])
617
+
618
+ @list_params.search_data = {
619
+ 'created_after' => @tn - 1.month
620
+ }
621
+
622
+ finder = RSpecModelFinderTest.list( @list_params )
623
+ expect( finder ).to eq([@c])
624
+
625
+ @list_params.search_data = {
626
+ 'created_before' => @tn - 1.month
627
+ }
628
+
629
+ finder = RSpecModelFinderTest.list( @list_params )
630
+ expect( finder ).to eq([@a])
631
+
632
+ @list_params.search_data = {
633
+ 'created_before' => @tn - 1.month + 1.day
634
+ }
635
+
636
+ finder = RSpecModelFinderTest.list( @list_params )
637
+ expect( finder ).to eq([@b, @a])
613
638
  end
614
639
 
615
640
  it 'searches with chain' do
@@ -650,6 +675,27 @@ describe Hoodoo::ActiveRecord::Finder do
650
675
 
651
676
  finder = constraint.list( @list_params )
652
677
  expect( finder ).to eq([])
678
+
679
+ @list_params.search_data = {
680
+ 'created_after' => @tn - 1.month
681
+ }
682
+
683
+ finder = constraint.list( @list_params )
684
+ expect( finder ).to eq([])
685
+
686
+ @list_params.search_data = {
687
+ 'created_before' => @tn - 1.month
688
+ }
689
+
690
+ finder = constraint.list( @list_params )
691
+ expect( finder ).to eq([@a])
692
+
693
+ @list_params.search_data = {
694
+ 'created_before' => @tn - 1.month + 1.day
695
+ }
696
+
697
+ finder = constraint.list( @list_params )
698
+ expect( finder ).to eq([@b, @a])
653
699
  end
654
700
  end
655
701
 
@@ -707,6 +753,22 @@ describe Hoodoo::ActiveRecord::Finder do
707
753
  finder = RSpecModelFinderTestWithHelpers.list( @list_params )
708
754
  expect( finder ).to eq( [ @c_wh, @b_wh ] )
709
755
  end
756
+
757
+ it 'finds with framework override' do
758
+ @list_params.search_data = {
759
+ 'created_after' => @tn - 1.week
760
+ }
761
+
762
+ finder = RSpecModelFinderTestWithHelpers.list( @list_params )
763
+ expect( finder ).to eq( [ @c_wh, @b_wh ] )
764
+
765
+ @list_params.search_data = {
766
+ 'created_after' => @tn + 1.day
767
+ }
768
+
769
+ finder = RSpecModelFinderTestWithHelpers.list( @list_params )
770
+ expect( finder ).to eq( [ @c_wh ] )
771
+ end
710
772
  end
711
773
 
712
774
  # ==========================================================================
@@ -748,6 +810,27 @@ describe Hoodoo::ActiveRecord::Finder do
748
810
 
749
811
  finder = RSpecModelFinderTest.list( @list_params )
750
812
  expect( finder ).to eq([@b])
813
+
814
+ @list_params.filter_data = {
815
+ 'created_after' => @tn - 1.month
816
+ }
817
+
818
+ finder = RSpecModelFinderTest.list( @list_params )
819
+ expect( finder ).to eq([@b, @a])
820
+
821
+ @list_params.filter_data = {
822
+ 'created_before' => @tn - 1.month
823
+ }
824
+
825
+ finder = RSpecModelFinderTest.list( @list_params )
826
+ expect( finder ).to eq([@c, @b])
827
+
828
+ @list_params.filter_data = {
829
+ 'created_before' => @tn - 1.month + 1.day
830
+ }
831
+
832
+ finder = RSpecModelFinderTest.list( @list_params )
833
+ expect( finder ).to eq([@c])
751
834
  end
752
835
 
753
836
  it 'filters with chain' do
@@ -792,6 +875,27 @@ describe Hoodoo::ActiveRecord::Finder do
792
875
 
793
876
  finder = constraint.list( @list_params )
794
877
  expect( finder ).to eq([])
878
+
879
+ @list_params.filter_data = {
880
+ 'created_after' => @tn - 1.month
881
+ }
882
+
883
+ finder = constraint.list( @list_params )
884
+ expect( finder ).to eq([])
885
+
886
+ @list_params.filter_data = {
887
+ 'created_before' => @tn - 1.month
888
+ }
889
+
890
+ finder = constraint.list( @list_params )
891
+ expect( finder ).to eq([@c])
892
+
893
+ @list_params.filter_data = {
894
+ 'created_before' => @tn - 1.month + 1.day
895
+ }
896
+
897
+ finder = constraint.list( @list_params )
898
+ expect( finder ).to eq([@c])
795
899
  end
796
900
  end
797
901
 
@@ -837,7 +941,6 @@ describe Hoodoo::ActiveRecord::Finder do
837
941
  expect( finder ).to eq( [ @c_wh, @b_wh, @a_wh ] )
838
942
  end
839
943
 
840
-
841
944
  it 'filters by comma-separated list' do
842
945
  @list_params.filter_data = {
843
946
  'field_two' => 'two a,something else,two c,more'
@@ -855,6 +958,22 @@ describe Hoodoo::ActiveRecord::Finder do
855
958
  finder = RSpecModelFinderTestWithHelpers.list( @list_params )
856
959
  expect( finder ).to eq( [ @a_wh ] )
857
960
  end
961
+
962
+ it 'filters with framework override' do
963
+ @list_params.filter_data = {
964
+ 'created_after' => @tn - 1.week
965
+ }
966
+
967
+ finder = RSpecModelFinderTestWithHelpers.list( @list_params )
968
+ expect( finder ).to eq( [ @a_wh ] )
969
+
970
+ @list_params.filter_data = {
971
+ 'created_after' => @tn + 1.day
972
+ }
973
+
974
+ finder = RSpecModelFinderTestWithHelpers.list( @list_params )
975
+ expect( finder ).to eq( [ @b_wh, @a_wh ] )
976
+ end
858
977
  end
859
978
 
860
979
  # ==========================================================================
@@ -866,6 +985,7 @@ describe Hoodoo::ActiveRecord::Finder do
866
985
  @scoped_1.uuid = 'uuid 1'
867
986
  @scoped_1.code = 'code 1'
868
987
  @scoped_1.field_one = 'scoped 1'
988
+ @scoped_1.created_at = @tn - 1.year
869
989
  @scoped_1.save!
870
990
 
871
991
  @scoped_2 = RSpecModelFinderTest.new
@@ -27,17 +27,6 @@ describe Hoodoo::ActiveRecord::Finder::SearchHelper do
27
27
  end
28
28
  end
29
29
 
30
- before :each do
31
- @f1 = RSpecModelSearchHelperTest.create
32
- @f2 = RSpecModelSearchHelperTest.create( :field => 'hello' )
33
- @f3 = RSpecModelSearchHelperTest.create( :field => 'hello' )
34
- @f4 = RSpecModelSearchHelperTest.create( :field => 'HELLO' )
35
- @f5 = RSpecModelSearchHelperTest.create
36
- @f6 = RSpecModelSearchHelperTest.create( :field => 'world' )
37
- @f7 = RSpecModelSearchHelperTest.create( :field => 'world' )
38
- @f8 = RSpecModelSearchHelperTest.create( :field => 'WORLD' )
39
- end
40
-
41
30
  def find( clause )
42
31
  RSpecModelSearchHelperTest.where( *clause ).all
43
32
  end
@@ -46,387 +35,625 @@ describe Hoodoo::ActiveRecord::Finder::SearchHelper do
46
35
  RSpecModelSearchHelperTest.where.not( *clause ).all
47
36
  end
48
37
 
38
+ #############################################################################
39
+ # Although the queries in this section can match things other than strings
40
+ # in some cases, they're aimed at string comparison most of the time.
49
41
  #############################################################################
50
42
 
51
- context '#cs_match' do
52
- it 'generates expected no-input-parameter output' do
53
- result = described_class.cs_match
54
- expect( result.call( 'a', 'b' ) ).to eq( [ 'a = ? AND a IS NOT NULL', 'b' ] )
43
+ context 'equality' do
44
+ before :each do
45
+ @f1 = RSpecModelSearchHelperTest.create
46
+ @f2 = RSpecModelSearchHelperTest.create( :field => 'hello' )
47
+ @f3 = RSpecModelSearchHelperTest.create( :field => 'hello' )
48
+ @f4 = RSpecModelSearchHelperTest.create( :field => 'HELLO' )
49
+ @f5 = RSpecModelSearchHelperTest.create
50
+ @f6 = RSpecModelSearchHelperTest.create( :field => 'world' )
51
+ @f7 = RSpecModelSearchHelperTest.create( :field => 'world' )
52
+ @f8 = RSpecModelSearchHelperTest.create( :field => 'WORLD' )
55
53
  end
56
54
 
57
- it 'generates expected one-input-parameter output' do
58
- result = described_class.cs_match( :bar )
59
- expect( result.call( 'a', 'b' ) ).to eq( [ 'bar = ? AND bar IS NOT NULL', 'b' ] )
60
- end
55
+ ###########################################################################
61
56
 
62
- it 'finds expected things' do
63
- result = find( described_class.cs_match.call( 'field', 'hello' ) )
64
- expect( result ).to match_array( [ @f2, @f3 ] )
57
+ context '#cs_match' do
58
+ it 'generates expected no-input-parameter output' do
59
+ result = described_class.cs_match
60
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'a = ? AND a IS NOT NULL', 'b' ] )
61
+ end
65
62
 
66
- result = find( described_class.cs_match.call( 'field', 'HELLO' ) )
67
- expect( result ).to match_array( [ @f4 ] )
63
+ it 'generates expected one-input-parameter output' do
64
+ result = described_class.cs_match( :bar )
65
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'bar = ? AND bar IS NOT NULL', 'b' ] )
66
+ end
68
67
 
69
- result = find( described_class.cs_match.call( 'field', 'hell' ) )
70
- expect( result ).to match_array( [] )
68
+ it 'finds expected things' do
69
+ result = find( described_class.cs_match.call( 'field', 'hello' ) )
70
+ expect( result ).to match_array( [ @f2, @f3 ] )
71
71
 
72
- result = find( described_class.cs_match.call( 'field', 'llo' ) )
73
- expect( result ).to match_array( [] )
72
+ result = find( described_class.cs_match.call( 'field', 'HELLO' ) )
73
+ expect( result ).to match_array( [ @f4 ] )
74
74
 
75
- result = find( described_class.cs_match.call( 'field', 'heLLo' ) )
76
- expect( result ).to match_array( [] )
77
- end
75
+ result = find( described_class.cs_match.call( 'field', 'hell' ) )
76
+ expect( result ).to match_array( [] )
78
77
 
79
- it 'finds expected things negated' do
80
- result = find_not( described_class.cs_match.call( 'field', 'hello' ) )
81
- expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
78
+ result = find( described_class.cs_match.call( 'field', 'llo' ) )
79
+ expect( result ).to match_array( [] )
82
80
 
83
- result = find_not( described_class.cs_match.call( 'field', 'HELLO' ) )
84
- expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7, @f8 ] )
81
+ result = find( described_class.cs_match.call( 'field', 'heLLo' ) )
82
+ expect( result ).to match_array( [] )
83
+ end
85
84
 
86
- result = find_not( described_class.cs_match.call( 'field', 'hell' ) )
87
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
85
+ it 'finds expected things negated' do
86
+ result = find_not( described_class.cs_match.call( 'field', 'hello' ) )
87
+ expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
88
88
 
89
- result = find_not( described_class.cs_match.call( 'field', 'llo' ) )
90
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
89
+ result = find_not( described_class.cs_match.call( 'field', 'HELLO' ) )
90
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7, @f8 ] )
91
91
 
92
- result = find_not( described_class.cs_match.call( 'field', 'heLLo' ) )
93
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
94
- end
95
- end
92
+ result = find_not( described_class.cs_match.call( 'field', 'hell' ) )
93
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
96
94
 
97
- #############################################################################
95
+ result = find_not( described_class.cs_match.call( 'field', 'llo' ) )
96
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
98
97
 
99
- context '#cs_match_csv' do
100
- it 'generates expected no-input-parameter output' do
101
- result = described_class.cs_match_csv()
102
- expect( result.call( 'a', 'b,c,d' ) ).to eq( [ 'a IN (?) AND a IS NOT NULL', [ 'b', 'c', 'd' ] ] )
98
+ result = find_not( described_class.cs_match.call( 'field', 'heLLo' ) )
99
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
100
+ end
103
101
  end
104
102
 
105
- it 'generates expected one-input-parameter output' do
106
- result = described_class.cs_match_csv( :bar )
107
- expect( result.call( 'a', 'b,c,d' ) ).to eq( [ 'bar IN (?) AND bar IS NOT NULL', [ 'b', 'c', 'd' ] ] )
108
- end
103
+ ###########################################################################
109
104
 
110
- it 'finds expected things' do
111
- result = find( described_class.cs_match_csv.call( 'field', 'hello,world' ) )
112
- expect( result ).to match_array( [ @f2, @f3, @f6, @f7 ] )
105
+ context '#cs_match_csv' do
106
+ it 'generates expected no-input-parameter output' do
107
+ result = described_class.cs_match_csv()
108
+ expect( result.call( 'a', 'b,c,d' ) ).to eq( [ 'a IN (?) AND a IS NOT NULL', [ 'b', 'c', 'd' ] ] )
109
+ end
113
110
 
114
- result = find( described_class.cs_match_csv.call( 'field', 'HELLO,WORLD' ) )
115
- expect( result ).to match_array( [ @f4, @f8 ] )
111
+ it 'generates expected one-input-parameter output' do
112
+ result = described_class.cs_match_csv( :bar )
113
+ expect( result.call( 'a', 'b,c,d' ) ).to eq( [ 'bar IN (?) AND bar IS NOT NULL', [ 'b', 'c', 'd' ] ] )
114
+ end
116
115
 
117
- result = find( described_class.cs_match_csv.call( 'field', 'hell,worl' ) )
118
- expect( result ).to match_array( [] )
116
+ it 'finds expected things' do
117
+ result = find( described_class.cs_match_csv.call( 'field', 'hello,world' ) )
118
+ expect( result ).to match_array( [ @f2, @f3, @f6, @f7 ] )
119
119
 
120
- result = find( described_class.cs_match_csv.call( 'field', 'llo,ld' ) )
121
- expect( result ).to match_array( [] )
120
+ result = find( described_class.cs_match_csv.call( 'field', 'HELLO,WORLD' ) )
121
+ expect( result ).to match_array( [ @f4, @f8 ] )
122
122
 
123
- result = find( described_class.cs_match_csv.call( 'field', 'heLLo,WORld' ) )
124
- expect( result ).to match_array( [] )
125
- end
123
+ result = find( described_class.cs_match_csv.call( 'field', 'hell,worl' ) )
124
+ expect( result ).to match_array( [] )
126
125
 
127
- it 'finds expected things negated' do
128
- result = find_not( described_class.cs_match_csv.call( 'field', 'hello,world' ) )
129
- expect( result ).to match_array( [ @f1, @f4, @f5, @f8 ] )
126
+ result = find( described_class.cs_match_csv.call( 'field', 'llo,ld' ) )
127
+ expect( result ).to match_array( [] )
130
128
 
131
- result = find_not( described_class.cs_match_csv.call( 'field', 'HELLO,WORLD' ) )
132
- expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7 ] )
129
+ result = find( described_class.cs_match_csv.call( 'field', 'heLLo,WORld' ) )
130
+ expect( result ).to match_array( [] )
131
+ end
133
132
 
134
- result = find_not( described_class.cs_match_csv.call( 'field', 'hell,worl' ) )
135
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
133
+ it 'finds expected things negated' do
134
+ result = find_not( described_class.cs_match_csv.call( 'field', 'hello,world' ) )
135
+ expect( result ).to match_array( [ @f1, @f4, @f5, @f8 ] )
136
136
 
137
- result = find_not( described_class.cs_match_csv.call( 'field', 'llo,ld' ) )
138
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
137
+ result = find_not( described_class.cs_match_csv.call( 'field', 'HELLO,WORLD' ) )
138
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7 ] )
139
139
 
140
- result = find_not( described_class.cs_match_csv.call( 'field', 'heLLo,WORld' ) )
141
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
142
- end
143
- end
140
+ result = find_not( described_class.cs_match_csv.call( 'field', 'hell,worl' ) )
141
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
144
142
 
145
- #############################################################################
143
+ result = find_not( described_class.cs_match_csv.call( 'field', 'llo,ld' ) )
144
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
146
145
 
147
- context '#cs_match_array' do
148
- it 'generates expected no-input-parameter output' do
149
- result = described_class.cs_match_array()
150
- expect( result.call( 'a', [ 'b', 'c', 'd' ] ) ).to eq( [ 'a IN (?) AND a IS NOT NULL', [ 'b', 'c', 'd' ] ] )
146
+ result = find_not( described_class.cs_match_csv.call( 'field', 'heLLo,WORld' ) )
147
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
148
+ end
151
149
  end
152
150
 
153
- it 'generates expected one-input-parameter output' do
154
- result = described_class.cs_match_array( :bar )
155
- expect( result.call( 'a', [ 'b', 'c', 'd' ] ) ).to eq( [ 'bar IN (?) AND bar IS NOT NULL', [ 'b', 'c', 'd' ] ] )
156
- end
151
+ ###########################################################################
157
152
 
158
- it 'finds expected things' do
159
- result = find( described_class.cs_match_array.call( 'field', [ 'hello', 'world' ] ) )
160
- expect( result ).to match_array( [ @f2, @f3, @f6, @f7 ] )
153
+ context '#cs_match_array' do
154
+ it 'generates expected no-input-parameter output' do
155
+ result = described_class.cs_match_array()
156
+ expect( result.call( 'a', [ 'b', 'c', 'd' ] ) ).to eq( [ 'a IN (?) AND a IS NOT NULL', [ 'b', 'c', 'd' ] ] )
157
+ end
161
158
 
162
- result = find( described_class.cs_match_array.call( 'field', [ 'HELLO', 'WORLD' ] ) )
163
- expect( result ).to match_array( [ @f4, @f8 ] )
159
+ it 'generates expected one-input-parameter output' do
160
+ result = described_class.cs_match_array( :bar )
161
+ expect( result.call( 'a', [ 'b', 'c', 'd' ] ) ).to eq( [ 'bar IN (?) AND bar IS NOT NULL', [ 'b', 'c', 'd' ] ] )
162
+ end
164
163
 
165
- result = find( described_class.cs_match_array.call( 'field', [ 'hell', 'worl' ] ) )
166
- expect( result ).to match_array( [] )
164
+ it 'finds expected things' do
165
+ result = find( described_class.cs_match_array.call( 'field', [ 'hello', 'world' ] ) )
166
+ expect( result ).to match_array( [ @f2, @f3, @f6, @f7 ] )
167
167
 
168
- result = find( described_class.cs_match_array.call( 'field', [ 'llo', 'ld' ] ) )
169
- expect( result ).to match_array( [] )
168
+ result = find( described_class.cs_match_array.call( 'field', [ 'HELLO', 'WORLD' ] ) )
169
+ expect( result ).to match_array( [ @f4, @f8 ] )
170
170
 
171
- result = find( described_class.cs_match_array.call( 'field', [ 'heLLo', 'WORld' ] ) )
172
- expect( result ).to match_array( [] )
173
- end
171
+ result = find( described_class.cs_match_array.call( 'field', [ 'hell', 'worl' ] ) )
172
+ expect( result ).to match_array( [] )
174
173
 
175
- it 'finds expected things negated' do
176
- result = find_not( described_class.cs_match_array.call( 'field', [ 'hello', 'world' ] ) )
177
- expect( result ).to match_array( [ @f1, @f4, @f5, @f8 ] )
174
+ result = find( described_class.cs_match_array.call( 'field', [ 'llo', 'ld' ] ) )
175
+ expect( result ).to match_array( [] )
178
176
 
179
- result = find_not( described_class.cs_match_array.call( 'field', [ 'HELLO', 'WORLD' ] ) )
180
- expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7 ] )
177
+ result = find( described_class.cs_match_array.call( 'field', [ 'heLLo', 'WORld' ] ) )
178
+ expect( result ).to match_array( [] )
179
+ end
181
180
 
182
- result = find_not( described_class.cs_match_array.call( 'field', [ 'hell', 'worl' ] ) )
183
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
181
+ it 'finds expected things negated' do
182
+ result = find_not( described_class.cs_match_array.call( 'field', [ 'hello', 'world' ] ) )
183
+ expect( result ).to match_array( [ @f1, @f4, @f5, @f8 ] )
184
184
 
185
- result = find_not( described_class.cs_match_array.call( 'field', [ 'llo', 'ld' ] ) )
186
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
185
+ result = find_not( described_class.cs_match_array.call( 'field', [ 'HELLO', 'WORLD' ] ) )
186
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7 ] )
187
187
 
188
- result = find_not( described_class.cs_match_array.call( 'field', [ 'heLLo', 'WORld' ] ) )
189
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
190
- end
191
- end
188
+ result = find_not( described_class.cs_match_array.call( 'field', [ 'hell', 'worl' ] ) )
189
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
192
190
 
193
- #############################################################################
191
+ result = find_not( described_class.cs_match_array.call( 'field', [ 'llo', 'ld' ] ) )
192
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
194
193
 
195
- context '#ci_match_generic' do
196
- it 'generates expected no-input-parameter output' do
197
- result = described_class.ci_match_generic()
198
- expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(a) = ? AND a IS NOT NULL', 'b' ] )
194
+ result = find_not( described_class.cs_match_array.call( 'field', [ 'heLLo', 'WORld' ] ) )
195
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
196
+ end
199
197
  end
200
198
 
201
- it 'generates expected one-input-parameter output' do
202
- result = described_class.ci_match_generic( :bar )
203
- expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(bar) = ? AND bar IS NOT NULL', 'b' ] )
204
- end
199
+ ###########################################################################
205
200
 
206
- it 'finds expected things' do
207
- result = find( described_class.ci_match_generic.call( 'field', 'hello' ) )
208
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
201
+ context '#ci_match_generic' do
202
+ it 'generates expected no-input-parameter output' do
203
+ result = described_class.ci_match_generic()
204
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(a) = ? AND a IS NOT NULL', 'b' ] )
205
+ end
209
206
 
210
- result = find( described_class.ci_match_generic.call( 'field', 'HELLO' ) )
211
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
207
+ it 'generates expected one-input-parameter output' do
208
+ result = described_class.ci_match_generic( :bar )
209
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(bar) = ? AND bar IS NOT NULL', 'b' ] )
210
+ end
212
211
 
213
- result = find( described_class.ci_match_generic.call( 'field', 'hell' ) )
214
- expect( result ).to match_array( [] )
212
+ it 'finds expected things' do
213
+ result = find( described_class.ci_match_generic.call( 'field', 'hello' ) )
214
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
215
215
 
216
- result = find( described_class.ci_match_generic.call( 'field', 'llo' ) )
217
- expect( result ).to match_array( [] )
216
+ result = find( described_class.ci_match_generic.call( 'field', 'HELLO' ) )
217
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
218
218
 
219
- result = find( described_class.ci_match_generic.call( 'field', 'heLLo' ) )
220
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
221
- end
219
+ result = find( described_class.ci_match_generic.call( 'field', 'hell' ) )
220
+ expect( result ).to match_array( [] )
222
221
 
223
- it 'finds expected things negated' do
224
- result = find_not( described_class.ci_match_generic.call( 'field', 'hello' ) )
225
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
222
+ result = find( described_class.ci_match_generic.call( 'field', 'llo' ) )
223
+ expect( result ).to match_array( [] )
226
224
 
227
- result = find_not( described_class.ci_match_generic.call( 'field', 'HELLO' ) )
228
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
225
+ result = find( described_class.ci_match_generic.call( 'field', 'heLLo' ) )
226
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
227
+ end
229
228
 
230
- result = find_not( described_class.ci_match_generic.call( 'field', 'hell' ) )
231
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
229
+ it 'finds expected things negated' do
230
+ result = find_not( described_class.ci_match_generic.call( 'field', 'hello' ) )
231
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
232
232
 
233
- result = find_not( described_class.ci_match_generic.call( 'field', 'llo' ) )
234
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
233
+ result = find_not( described_class.ci_match_generic.call( 'field', 'HELLO' ) )
234
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
235
235
 
236
- result = find_not( described_class.ci_match_generic.call( 'field', 'heLLo' ) )
237
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
238
- end
239
- end
236
+ result = find_not( described_class.ci_match_generic.call( 'field', 'hell' ) )
237
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
240
238
 
241
- #############################################################################
239
+ result = find_not( described_class.ci_match_generic.call( 'field', 'llo' ) )
240
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
242
241
 
243
- context '#ciaw_match_generic' do
244
- it 'generates expected no-input-parameter output' do
245
- result = described_class.ciaw_match_generic()
246
- expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(a) LIKE ? AND a IS NOT NULL', '%b%' ] )
242
+ result = find_not( described_class.ci_match_generic.call( 'field', 'heLLo' ) )
243
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
244
+ end
247
245
  end
248
246
 
249
- it 'generates expected one-input-parameter output' do
250
- result = described_class.ciaw_match_generic( :bar )
251
- expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(bar) LIKE ? AND bar IS NOT NULL', '%b%' ] )
252
- end
247
+ ###########################################################################
253
248
 
254
- it 'finds expected things' do
255
- result = find( described_class.ciaw_match_generic.call( 'field', 'hello' ) )
256
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
249
+ context '#ciaw_match_generic' do
250
+ it 'generates expected no-input-parameter output' do
251
+ result = described_class.ciaw_match_generic()
252
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(a) LIKE ? AND a IS NOT NULL', '%b%' ] )
253
+ end
257
254
 
258
- result = find( described_class.ciaw_match_generic.call( 'field', 'HELLO' ) )
259
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
255
+ it 'generates expected one-input-parameter output' do
256
+ result = described_class.ciaw_match_generic( :bar )
257
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'lower(bar) LIKE ? AND bar IS NOT NULL', '%b%' ] )
258
+ end
260
259
 
261
- result = find( described_class.ciaw_match_generic.call( 'field', 'hell' ) )
262
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
260
+ it 'finds expected things' do
261
+ result = find( described_class.ciaw_match_generic.call( 'field', 'hello' ) )
262
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
263
263
 
264
- result = find( described_class.ciaw_match_generic.call( 'field', 'llo' ) )
265
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
264
+ result = find( described_class.ciaw_match_generic.call( 'field', 'HELLO' ) )
265
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
266
266
 
267
- result = find( described_class.ciaw_match_generic.call( 'field', 'heLLo' ) )
268
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
269
- end
267
+ result = find( described_class.ciaw_match_generic.call( 'field', 'hell' ) )
268
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
270
269
 
271
- it 'finds expected things negated' do
272
- result = find_not( described_class.ciaw_match_generic.call( 'field', 'hello' ) )
273
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
270
+ result = find( described_class.ciaw_match_generic.call( 'field', 'llo' ) )
271
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
274
272
 
275
- result = find_not( described_class.ciaw_match_generic.call( 'field', 'HELLO' ) )
276
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
273
+ result = find( described_class.ciaw_match_generic.call( 'field', 'heLLo' ) )
274
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
275
+ end
277
276
 
278
- result = find_not( described_class.ciaw_match_generic.call( 'field', 'hell' ) )
279
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
277
+ it 'finds expected things negated' do
278
+ result = find_not( described_class.ciaw_match_generic.call( 'field', 'hello' ) )
279
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
280
280
 
281
- result = find_not( described_class.ciaw_match_generic.call( 'field', 'llo' ) )
282
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
281
+ result = find_not( described_class.ciaw_match_generic.call( 'field', 'HELLO' ) )
282
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
283
283
 
284
- result = find_not( described_class.ciaw_match_generic.call( 'field', 'heLLo' ) )
285
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
286
- end
287
- end
284
+ result = find_not( described_class.ciaw_match_generic.call( 'field', 'hell' ) )
285
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
288
286
 
289
- #############################################################################
287
+ result = find_not( described_class.ciaw_match_generic.call( 'field', 'llo' ) )
288
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
290
289
 
291
- context '#csaw_match' do
292
- it 'generates expected no-input-parameter output' do
293
- result = described_class.csaw_match()
294
- expect( result.call( 'a', 'B' ) ).to eq( [ 'a LIKE ? AND a IS NOT NULL', '%B%' ] )
290
+ result = find_not( described_class.ciaw_match_generic.call( 'field', 'heLLo' ) )
291
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
292
+ end
295
293
  end
296
294
 
297
- it 'generates expected one-input-parameter output' do
298
- result = described_class.csaw_match( :bar )
299
- expect( result.call( 'a', 'B' ) ).to eq( [ 'bar LIKE ? AND bar IS NOT NULL', '%B%' ] )
295
+ ###########################################################################
296
+
297
+ context '#csaw_match' do
298
+ it 'generates expected no-input-parameter output' do
299
+ result = described_class.csaw_match()
300
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'a LIKE ? AND a IS NOT NULL', '%B%' ] )
301
+ end
302
+
303
+ it 'generates expected one-input-parameter output' do
304
+ result = described_class.csaw_match( :bar )
305
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'bar LIKE ? AND bar IS NOT NULL', '%B%' ] )
306
+ end
307
+
308
+ it 'finds expected things' do
309
+ result = find( described_class.csaw_match.call( 'field', 'hello' ) )
310
+ expect( result ).to match_array( [ @f2, @f3 ] )
311
+
312
+ result = find( described_class.csaw_match.call( 'field', 'HELLO' ) )
313
+ expect( result ).to match_array( [ @f4 ] )
314
+
315
+ result = find( described_class.csaw_match.call( 'field', 'hell' ) )
316
+ expect( result ).to match_array( [ @f2, @f3 ] )
317
+
318
+ result = find( described_class.csaw_match.call( 'field', 'llo' ) )
319
+ expect( result ).to match_array( [ @f2, @f3 ] )
320
+
321
+ result = find( described_class.csaw_match.call( 'field', 'heLLo' ) )
322
+ expect( result ).to match_array( [ ] )
323
+ end
324
+
325
+ it 'finds expected things negated' do
326
+ result = find_not( described_class.csaw_match.call( 'field', 'hello' ) )
327
+ expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
328
+
329
+ result = find_not( described_class.csaw_match.call( 'field', 'HELLO' ) )
330
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7, @f8 ] )
331
+
332
+ result = find_not( described_class.csaw_match.call( 'field', 'hell' ) )
333
+ expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
334
+
335
+ result = find_not( described_class.csaw_match.call( 'field', 'llo' ) )
336
+ expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
337
+
338
+ result = find_not( described_class.csaw_match.call( 'field', 'heLLo' ) )
339
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
340
+ end
300
341
  end
301
342
 
302
- it 'finds expected things' do
303
- result = find( described_class.csaw_match.call( 'field', 'hello' ) )
304
- expect( result ).to match_array( [ @f2, @f3 ] )
343
+ ###########################################################################
344
+
345
+ context '#ci_match_postgres' do
346
+ it 'generates expected no-input-parameter output' do
347
+ result = described_class.ci_match_postgres()
348
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'a ILIKE ? AND a IS NOT NULL', 'B' ] )
349
+ end
350
+
351
+ it 'generates expected one-input-parameter output' do
352
+ result = described_class.ci_match_postgres( :bar )
353
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'bar ILIKE ? AND bar IS NOT NULL', 'B' ] )
354
+ end
305
355
 
306
- result = find( described_class.csaw_match.call( 'field', 'HELLO' ) )
307
- expect( result ).to match_array( [ @f4 ] )
356
+ it 'finds expected things' do
357
+ result = find( described_class.ci_match_postgres.call( 'field', 'hello' ) )
358
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
308
359
 
309
- result = find( described_class.csaw_match.call( 'field', 'hell' ) )
310
- expect( result ).to match_array( [ @f2, @f3 ] )
360
+ result = find( described_class.ci_match_postgres.call( 'field', 'HELLO' ) )
361
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
362
+
363
+ result = find( described_class.ci_match_postgres.call( 'field', 'hell' ) )
364
+ expect( result ).to match_array( [] )
365
+
366
+ result = find( described_class.ci_match_postgres.call( 'field', 'llo' ) )
367
+ expect( result ).to match_array( [] )
368
+
369
+ result = find( described_class.ci_match_postgres.call( 'field', 'heLLo' ) )
370
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
371
+ end
311
372
 
312
- result = find( described_class.csaw_match.call( 'field', 'llo' ) )
313
- expect( result ).to match_array( [ @f2, @f3 ] )
373
+ it 'finds expected things negated' do
374
+ result = find_not( described_class.ci_match_postgres.call( 'field', 'hello' ) )
375
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
314
376
 
315
- result = find( described_class.csaw_match.call( 'field', 'heLLo' ) )
316
- expect( result ).to match_array( [ ] )
377
+ result = find_not( described_class.ci_match_postgres.call( 'field', 'HELLO' ) )
378
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
379
+
380
+ result = find_not( described_class.ci_match_postgres.call( 'field', 'hell' ) )
381
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
382
+
383
+ result = find_not( described_class.ci_match_postgres.call( 'field', 'llo' ) )
384
+ expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
385
+
386
+ result = find_not( described_class.ci_match_postgres.call( 'field', 'heLLo' ) )
387
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
388
+ end
317
389
  end
318
390
 
319
- it 'finds expected things negated' do
320
- result = find_not( described_class.csaw_match.call( 'field', 'hello' ) )
321
- expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
391
+ ###########################################################################
392
+
393
+ context '#ciaw_match_postgres' do
394
+ it 'generates expected no-input-parameter output' do
395
+ result = described_class.ciaw_match_postgres()
396
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'a ILIKE ? AND a IS NOT NULL', '%B%' ] )
397
+ end
398
+
399
+ it 'generates expected one-input-parameter output' do
400
+ result = described_class.ciaw_match_postgres( :bar )
401
+ expect( result.call( 'a', 'B' ) ).to eq( [ 'bar ILIKE ? AND bar IS NOT NULL', '%B%' ] )
402
+ end
403
+
404
+ it 'finds expected things' do
405
+ result = find( described_class.ciaw_match_postgres.call( 'field', 'hello' ) )
406
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
322
407
 
323
- result = find_not( described_class.csaw_match.call( 'field', 'HELLO' ) )
324
- expect( result ).to match_array( [ @f1, @f2, @f3, @f5, @f6, @f7, @f8 ] )
408
+ result = find( described_class.ciaw_match_postgres.call( 'field', 'HELLO' ) )
409
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
325
410
 
326
- result = find_not( described_class.csaw_match.call( 'field', 'hell' ) )
327
- expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
411
+ result = find( described_class.ciaw_match_postgres.call( 'field', 'hell' ) )
412
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
328
413
 
329
- result = find_not( described_class.csaw_match.call( 'field', 'llo' ) )
330
- expect( result ).to match_array( [ @f1, @f4, @f5, @f6, @f7, @f8 ] )
414
+ result = find( described_class.ciaw_match_postgres.call( 'field', 'llo' ) )
415
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
331
416
 
332
- result = find_not( described_class.csaw_match.call( 'field', 'heLLo' ) )
333
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
417
+ result = find( described_class.ciaw_match_postgres.call( 'field', 'heLLo' ) )
418
+ expect( result ).to match_array( [ @f2, @f3, @f4 ] )
419
+ end
420
+
421
+ it 'finds expected things negated' do
422
+ result = find_not( described_class.ciaw_match_postgres.call( 'field', 'hello' ) )
423
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
424
+
425
+ result = find_not( described_class.ciaw_match_postgres.call( 'field', 'HELLO' ) )
426
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
427
+
428
+ result = find_not( described_class.ciaw_match_postgres.call( 'field', 'hell' ) )
429
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
430
+
431
+ result = find_not( described_class.ciaw_match_postgres.call( 'field', 'llo' ) )
432
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
433
+
434
+ result = find_not( described_class.ciaw_match_postgres.call( 'field', 'heLLo' ) )
435
+ expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
436
+ end
334
437
  end
438
+
439
+ ###########################################################################
440
+
335
441
  end
336
442
 
443
+ #############################################################################
444
+ # Although the queries in this section can match things other than dates
445
+ # easily - e.g. compare integers or strings - they were created initially
446
+ # for date comparisons so the seed data for tests is based on dates only.
337
447
  #############################################################################
338
448
 
339
- context '#ci_match_postgres' do
340
- it 'generates expected no-input-parameter output' do
341
- result = described_class.ci_match_postgres()
342
- expect( result.call( 'a', 'B' ) ).to eq( [ 'a ILIKE ? AND a IS NOT NULL', 'B' ] )
343
- end
449
+ context 'difference' do
450
+ before :each do
451
+ @tn = Time.now.round()
452
+ @t1 = RSpecModelSearchHelperTest.create( :created_at => @tn )
453
+ @t2 = RSpecModelSearchHelperTest.create( :created_at => @tn )
454
+ @t3 = RSpecModelSearchHelperTest.create( :created_at => @tn - 1.month )
455
+ @t4 = RSpecModelSearchHelperTest.create( :created_at => @tn - 1.month )
456
+ @t5 = RSpecModelSearchHelperTest.create( :created_at => @tn - 1.year )
457
+ @t6 = RSpecModelSearchHelperTest.create( :created_at => @tn - 1.year )
458
+ @t7 = RSpecModelSearchHelperTest.create
344
459
 
345
- it 'generates expected one-input-parameter output' do
346
- result = described_class.ci_match_postgres( :bar )
347
- expect( result.call( 'a', 'B' ) ).to eq( [ 'bar ILIKE ? AND bar IS NOT NULL', 'B' ] )
460
+ sql = "UPDATE r_spec_model_search_helper_tests SET created_at=NULL WHERE id=#{ @t7.id }"
461
+ ActiveRecord::Base.connection.execute( sql )
348
462
  end
349
463
 
350
- it 'finds expected things' do
351
- result = find( described_class.ci_match_postgres.call( 'field', 'hello' ) )
352
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
464
+ ###########################################################################
353
465
 
354
- result = find( described_class.ci_match_postgres.call( 'field', 'HELLO' ) )
355
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
466
+ context '#cs_lt' do
467
+ it 'generates expected no-input-parameter output' do
468
+ result = described_class.cs_lt()
469
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'a < ? AND a IS NOT NULL', 'b' ] )
470
+ end
356
471
 
357
- result = find( described_class.ci_match_postgres.call( 'field', 'hell' ) )
358
- expect( result ).to match_array( [] )
472
+ it 'generates expected one-input-parameter output' do
473
+ result = described_class.cs_lt( :bar )
474
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'bar < ? AND bar IS NOT NULL', 'b' ] )
475
+ end
359
476
 
360
- result = find( described_class.ci_match_postgres.call( 'field', 'llo' ) )
361
- expect( result ).to match_array( [] )
477
+ it 'finds expected things' do
478
+ result = find( described_class.cs_lt.call( 'created_at', @tn ) )
479
+ expect( result ).to match_array( [ @t3, @t4, @t5, @t6 ] )
362
480
 
363
- result = find( described_class.ci_match_postgres.call( 'field', 'heLLo' ) )
364
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
365
- end
481
+ result = find( described_class.cs_lt.call( 'created_at', ( @tn - 2.months ) ) )
482
+ expect( result ).to match_array( [ @t5, @t6 ] )
366
483
 
367
- it 'finds expected things negated' do
368
- result = find_not( described_class.ci_match_postgres.call( 'field', 'hello' ) )
369
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
484
+ result = find( described_class.cs_lt.call( 'created_at', ( @tn + 1.month ) ) )
485
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6 ] )
370
486
 
371
- result = find_not( described_class.ci_match_postgres.call( 'field', 'HELLO' ) )
372
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
487
+ result = find( described_class.cs_lt.call( 'created_at', ( @tn - 1.year ) ) )
488
+ expect( result ).to match_array( [] )
373
489
 
374
- result = find_not( described_class.ci_match_postgres.call( 'field', 'hell' ) )
375
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
490
+ result = find( described_class.cs_lt.call( 'created_at', ( @tn - 2.years ) ) )
491
+ expect( result ).to match_array( [] )
492
+ end
376
493
 
377
- result = find_not( described_class.ci_match_postgres.call( 'field', 'llo' ) )
378
- expect( result ).to match_array( [ @f1, @f2, @f3, @f4, @f5, @f6, @f7, @f8 ] )
494
+ it 'finds expected things negated' do
495
+ result = find_not( described_class.cs_lt.call( 'created_at', @tn ) )
496
+ expect( result ).to match_array( [ @t1, @t2, @t7 ] )
379
497
 
380
- result = find_not( described_class.ci_match_postgres.call( 'field', 'heLLo' ) )
381
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
382
- end
383
- end
498
+ result = find_not( described_class.cs_lt.call( 'created_at', ( @tn - 2.months ) ) )
499
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t7 ] )
384
500
 
385
- #############################################################################
501
+ result = find_not( described_class.cs_lt.call( 'created_at', ( @tn + 1.month ) ) )
502
+ expect( result ).to match_array( [ @t7 ] )
386
503
 
387
- context '#ciaw_match_postgres' do
388
- it 'generates expected no-input-parameter output' do
389
- result = described_class.ciaw_match_postgres()
390
- expect( result.call( 'a', 'B' ) ).to eq( [ 'a ILIKE ? AND a IS NOT NULL', '%B%' ] )
504
+ result = find_not( described_class.cs_lt.call( 'created_at', ( @tn - 1.year ) ) )
505
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6, @t7 ] )
506
+
507
+ result = find_not( described_class.cs_lt.call( 'created_at', ( @tn - 2.years ) ) )
508
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6, @t7 ] )
509
+ end
391
510
  end
392
511
 
393
- it 'generates expected one-input-parameter output' do
394
- result = described_class.ciaw_match_postgres( :bar )
395
- expect( result.call( 'a', 'B' ) ).to eq( [ 'bar ILIKE ? AND bar IS NOT NULL', '%B%' ] )
512
+ ###########################################################################
513
+
514
+ context '#cs_lte' do
515
+ it 'generates expected no-input-parameter output' do
516
+ result = described_class.cs_lte()
517
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'a <= ? AND a IS NOT NULL', 'b' ] )
518
+ end
519
+
520
+ it 'generates expected one-input-parameter output' do
521
+ result = described_class.cs_lte( :bar )
522
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'bar <= ? AND bar IS NOT NULL', 'b' ] )
523
+ end
524
+
525
+ it 'finds expected things' do
526
+ result = find( described_class.cs_lte.call( 'created_at', @tn ) )
527
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6 ] )
528
+
529
+ result = find( described_class.cs_lte.call( 'created_at', ( @tn - 2.months ) ) )
530
+ expect( result ).to match_array( [ @t5, @t6 ] )
531
+
532
+ result = find( described_class.cs_lte.call( 'created_at', ( @tn + 1.month ) ) )
533
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6 ] )
534
+
535
+ result = find( described_class.cs_lte.call( 'created_at', ( @tn - 1.year ) ) )
536
+ expect( result ).to match_array( [ @t5, @t6 ] )
537
+
538
+ result = find( described_class.cs_lte.call( 'created_at', ( @tn - 2.years ) ) )
539
+ expect( result ).to match_array( [] )
540
+ end
541
+
542
+ it 'finds expected things negated' do
543
+ result = find_not( described_class.cs_lte.call( 'created_at', @tn ) )
544
+ expect( result ).to match_array( [ @t7 ] )
545
+
546
+ result = find_not( described_class.cs_lte.call( 'created_at', ( @tn - 2.months ) ) )
547
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t7 ] )
548
+
549
+ result = find_not( described_class.cs_lte.call( 'created_at', ( @tn + 1.month ) ) )
550
+ expect( result ).to match_array( [ @t7 ] )
551
+
552
+ result = find_not( described_class.cs_lte.call( 'created_at', ( @tn - 1.year ) ) )
553
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t7 ] )
554
+
555
+ result = find_not( described_class.cs_lte.call( 'created_at', ( @tn - 2.years ) ) )
556
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6, @t7 ] )
557
+ end
396
558
  end
397
559
 
398
- it 'finds expected things' do
399
- result = find( described_class.ciaw_match_postgres.call( 'field', 'hello' ) )
400
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
560
+ ###########################################################################
401
561
 
402
- result = find( described_class.ciaw_match_postgres.call( 'field', 'HELLO' ) )
403
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
562
+ context '#cs_gt' do
563
+ it 'generates expected no-input-parameter output' do
564
+ result = described_class.cs_gt()
565
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'a > ? AND a IS NOT NULL', 'b' ] )
566
+ end
567
+
568
+ it 'generates expected one-input-parameter output' do
569
+ result = described_class.cs_gt( :bar )
570
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'bar > ? AND bar IS NOT NULL', 'b' ] )
571
+ end
572
+
573
+ it 'finds expected things' do
574
+ result = find( described_class.cs_gt.call( 'created_at', @tn ) )
575
+ expect( result ).to match_array( [] )
576
+
577
+ result = find( described_class.cs_gt.call( 'created_at', ( @tn - 2.months ) ) )
578
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4 ] )
579
+
580
+ result = find( described_class.cs_gt.call( 'created_at', ( @tn - 1.month ) ) )
581
+ expect( result ).to match_array( [ @t1, @t2 ] )
582
+
583
+ result = find( described_class.cs_gt.call( 'created_at', ( @tn - 1.year ) ) )
584
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4 ] )
585
+
586
+ result = find( described_class.cs_gt.call( 'created_at', ( @tn - 2.years ) ) )
587
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6 ] )
588
+ end
404
589
 
405
- result = find( described_class.ciaw_match_postgres.call( 'field', 'hell' ) )
406
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
590
+ it 'finds expected things negated' do
591
+ result = find_not( described_class.cs_gt.call( 'created_at', @tn ) )
592
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6, @t7 ] )
407
593
 
408
- result = find( described_class.ciaw_match_postgres.call( 'field', 'llo' ) )
409
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
594
+ result = find_not( described_class.cs_gt.call( 'created_at', ( @tn - 2.months ) ) )
595
+ expect( result ).to match_array( [ @t5, @t6, @t7 ] )
410
596
 
411
- result = find( described_class.ciaw_match_postgres.call( 'field', 'heLLo' ) )
412
- expect( result ).to match_array( [ @f2, @f3, @f4 ] )
597
+ result = find_not( described_class.cs_gt.call( 'created_at', ( @tn - 1.month ) ) )
598
+ expect( result ).to match_array( [ @t3, @t4, @t5, @t6, @t7 ] )
599
+
600
+ result = find_not( described_class.cs_gt.call( 'created_at', ( @tn - 1.year ) ) )
601
+ expect( result ).to match_array( [ @t5, @t6, @t7 ] )
602
+
603
+ result = find_not( described_class.cs_gt.call( 'created_at', ( @tn - 2.years ) ) )
604
+ expect( result ).to match_array( [ @t7 ] )
605
+ end
413
606
  end
414
607
 
415
- it 'finds expected things negated' do
416
- result = find_not( described_class.ciaw_match_postgres.call( 'field', 'hello' ) )
417
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
608
+ ###########################################################################
418
609
 
419
- result = find_not( described_class.ciaw_match_postgres.call( 'field', 'HELLO' ) )
420
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
610
+ context '#cs_gte' do
611
+ it 'generates expected no-input-parameter output' do
612
+ result = described_class.cs_gte()
613
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'a >= ? AND a IS NOT NULL', 'b' ] )
614
+ end
421
615
 
422
- result = find_not( described_class.ciaw_match_postgres.call( 'field', 'hell' ) )
423
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
616
+ it 'generates expected one-input-parameter output' do
617
+ result = described_class.cs_gte( :bar )
618
+ expect( result.call( 'a', 'b' ) ).to eq( [ 'bar >= ? AND bar IS NOT NULL', 'b' ] )
619
+ end
424
620
 
425
- result = find_not( described_class.ciaw_match_postgres.call( 'field', 'llo' ) )
426
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
621
+ it 'finds expected things' do
622
+ result = find( described_class.cs_gte.call( 'created_at', @tn ) )
623
+ expect( result ).to match_array( [ @t1, @t2 ] )
427
624
 
428
- result = find_not( described_class.ciaw_match_postgres.call( 'field', 'heLLo' ) )
429
- expect( result ).to match_array( [ @f1, @f5, @f6, @f7, @f8 ] )
625
+ result = find( described_class.cs_gte.call( 'created_at', ( @tn - 2.months ) ) )
626
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4 ] )
627
+
628
+ result = find( described_class.cs_gte.call( 'created_at', ( @tn - 1.month ) ) )
629
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4 ] )
630
+
631
+ result = find( described_class.cs_gte.call( 'created_at', ( @tn - 1.year ) ) )
632
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6 ] )
633
+
634
+ result = find( described_class.cs_gte.call( 'created_at', ( @tn - 2.years ) ) )
635
+ expect( result ).to match_array( [ @t1, @t2, @t3, @t4, @t5, @t6 ] )
636
+ end
637
+
638
+ it 'finds expected things negated' do
639
+ result = find_not( described_class.cs_gte.call( 'created_at', @tn ) )
640
+ expect( result ).to match_array( [ @t3, @t4, @t5, @t6, @t7 ] )
641
+
642
+ result = find_not( described_class.cs_gte.call( 'created_at', ( @tn - 2.months ) ) )
643
+ expect( result ).to match_array( [ @t5, @t6, @t7 ] )
644
+
645
+ result = find_not( described_class.cs_gte.call( 'created_at', ( @tn - 1.month ) ) )
646
+ expect( result ).to match_array( [ @t5, @t6, @t7 ] )
647
+
648
+ result = find_not( described_class.cs_gte.call( 'created_at', ( @tn - 1.year ) ) )
649
+ expect( result ).to match_array( [ @t7 ] )
650
+
651
+ result = find_not( described_class.cs_gte.call( 'created_at', ( @tn - 2.years ) ) )
652
+ expect( result ).to match_array( [ @t7 ] )
653
+ end
430
654
  end
655
+
656
+ ###########################################################################
657
+
431
658
  end
432
659
  end