trailblazer-finder 0.1.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +101 -0
  4. data/.rubocop.yml +3 -43
  5. data/.rubocop_todo.yml +42 -196
  6. data/.travis.yml +5 -8
  7. data/Gemfile +2 -2
  8. data/LICENSE.txt +7 -21
  9. data/README.md +177 -292
  10. data/Rakefile +12 -12
  11. data/lib/trailblazer/finder.rb +48 -23
  12. data/lib/trailblazer/finder/activity/find.rb +57 -0
  13. data/lib/trailblazer/finder/activity/prepare.rb +29 -0
  14. data/lib/trailblazer/finder/activity/prepare/adapters.rb +66 -0
  15. data/lib/trailblazer/finder/activity/prepare/entity.rb +32 -0
  16. data/lib/trailblazer/finder/activity/prepare/filters.rb +36 -0
  17. data/lib/trailblazer/finder/activity/prepare/paging.rb +49 -0
  18. data/lib/trailblazer/finder/activity/prepare/params.rb +33 -0
  19. data/lib/trailblazer/finder/activity/prepare/properties.rb +47 -0
  20. data/lib/trailblazer/finder/activity/prepare/sorting.rb +57 -0
  21. data/lib/trailblazer/finder/activity/process.rb +18 -0
  22. data/lib/trailblazer/finder/activity/process/adapters.rb +48 -0
  23. data/lib/trailblazer/finder/activity/process/filters.rb +28 -0
  24. data/lib/trailblazer/finder/activity/process/paging.rb +26 -0
  25. data/lib/trailblazer/finder/activity/process/predicates.rb +30 -0
  26. data/lib/trailblazer/finder/activity/process/sorting.rb +26 -0
  27. data/lib/trailblazer/finder/adapters/active_record/paging.rb +9 -8
  28. data/lib/trailblazer/finder/adapters/active_record/predicates.rb +78 -17
  29. data/lib/trailblazer/finder/adapters/active_record/sorting.rb +14 -12
  30. data/lib/trailblazer/finder/adapters/basic/paging.rb +21 -0
  31. data/lib/trailblazer/finder/adapters/basic/predicates.rb +115 -0
  32. data/lib/trailblazer/finder/adapters/basic/sorting.rb +40 -0
  33. data/lib/trailblazer/finder/adapters/kaminari/paging.rb +21 -0
  34. data/lib/trailblazer/finder/adapters/sequel/paging.rb +9 -8
  35. data/lib/trailblazer/finder/adapters/sequel/predicates.rb +78 -17
  36. data/lib/trailblazer/finder/adapters/sequel/sorting.rb +17 -15
  37. data/lib/trailblazer/finder/adapters/will_paginate/paging.rb +21 -0
  38. data/lib/trailblazer/finder/base.rb +20 -83
  39. data/lib/trailblazer/finder/dsl.rb +56 -0
  40. data/lib/trailblazer/finder/find.rb +28 -15
  41. data/lib/trailblazer/finder/helpers/basic.rb +44 -0
  42. data/lib/trailblazer/finder/helpers/sorting.rb +54 -0
  43. data/lib/trailblazer/finder/utils/array.rb +20 -0
  44. data/lib/trailblazer/finder/utils/extra.rb +10 -20
  45. data/lib/trailblazer/finder/utils/hash.rb +36 -0
  46. data/lib/trailblazer/finder/utils/splitter.rb +16 -17
  47. data/lib/trailblazer/finder/utils/string.rb +20 -10
  48. data/lib/trailblazer/finder/version.rb +3 -1
  49. data/lib/trailblazer/operation/finder.rb +20 -19
  50. data/spec/spec_helper.rb +5 -11
  51. data/spec/spec_helper_active_record.rb +11 -12
  52. data/spec/spec_helper_sequel.rb +4 -4
  53. data/spec/spec_helper_will_paginate.rb +13 -0
  54. data/spec/trailblazer/finder/adapters/active_record_spec.rb +267 -0
  55. data/spec/trailblazer/finder/adapters/basic_spec.rb +251 -0
  56. data/spec/trailblazer/finder/adapters/kaminari_spec.rb +78 -32
  57. data/spec/trailblazer/finder/adapters/sequel_spec.rb +267 -0
  58. data/spec/trailblazer/finder/adapters/will_paginate_spec.rb +81 -40
  59. data/spec/trailblazer/finder/base_spec.rb +292 -204
  60. data/spec/trailblazer/finder/dsl_spec.rb +213 -0
  61. data/spec/trailblazer/finder/utils/hash_spec.rb +26 -0
  62. data/spec/trailblazer/finder/utils/splitter_spec.rb +39 -0
  63. data/spec/trailblazer/finder/utils/string_spec.rb +52 -9
  64. data/spec/trailblazer/operation/finder_spec.rb +35 -32
  65. data/trailblazer-finder.gemspec +31 -30
  66. metadata +119 -137
  67. data/lib/trailblazer/finder/adapters.rb +0 -26
  68. data/lib/trailblazer/finder/adapters/active_record.rb +0 -32
  69. data/lib/trailblazer/finder/adapters/data_mapper.rb +0 -32
  70. data/lib/trailblazer/finder/adapters/data_mapper/paging.rb +0 -20
  71. data/lib/trailblazer/finder/adapters/data_mapper/predicates.rb +0 -42
  72. data/lib/trailblazer/finder/adapters/data_mapper/sorting.rb +0 -38
  73. data/lib/trailblazer/finder/adapters/friendly_id.rb +0 -31
  74. data/lib/trailblazer/finder/adapters/kaminari.rb +0 -18
  75. data/lib/trailblazer/finder/adapters/sequel.rb +0 -32
  76. data/lib/trailblazer/finder/adapters/will_paginate.rb +0 -18
  77. data/lib/trailblazer/finder/errors/block_ignored.rb +0 -11
  78. data/lib/trailblazer/finder/errors/invalid_defined_by_value.rb +0 -11
  79. data/lib/trailblazer/finder/errors/invalid_number.rb +0 -16
  80. data/lib/trailblazer/finder/errors/missing_entity_type.rb +0 -11
  81. data/lib/trailblazer/finder/errors/with_ignored.rb +0 -11
  82. data/lib/trailblazer/finder/features.rb +0 -23
  83. data/lib/trailblazer/finder/features/paging.rb +0 -55
  84. data/lib/trailblazer/finder/features/predicate.rb +0 -32
  85. data/lib/trailblazer/finder/features/sorting.rb +0 -108
  86. data/lib/trailblazer/finder/filter.rb +0 -66
  87. data/lib/trailblazer/finder/predicates.rb +0 -39
  88. data/lib/trailblazer/finder/utils/deep_locate.rb +0 -30
  89. data/lib/trailblazer/finder/utils/params.rb +0 -28
  90. data/lib/trailblazer/finder/utils/parse.rb +0 -25
  91. data/spec/spec_helper_data_mapper.rb +0 -35
  92. data/spec/support/paging_shared_example.rb +0 -65
  93. data/spec/support/sorting_shared_example.rb +0 -125
  94. data/spec/trailblazer/finder/adapters/active_record/base_spec.rb +0 -112
  95. data/spec/trailblazer/finder/adapters/active_record/paging_spec.rb +0 -64
  96. data/spec/trailblazer/finder/adapters/active_record/predicates_spec.rb +0 -101
  97. data/spec/trailblazer/finder/adapters/active_record/sorting_spec.rb +0 -99
  98. data/spec/trailblazer/finder/adapters/data_mapper/base_spec.rb +0 -112
  99. data/spec/trailblazer/finder/adapters/data_mapper/paging_spec.rb +0 -64
  100. data/spec/trailblazer/finder/adapters/data_mapper/predicates_spec.rb +0 -100
  101. data/spec/trailblazer/finder/adapters/data_mapper/sorting_spec.rb +0 -97
  102. data/spec/trailblazer/finder/adapters/friendly_id_spec.rb +0 -46
  103. data/spec/trailblazer/finder/adapters/sequel/base_spec.rb +0 -125
  104. data/spec/trailblazer/finder/adapters/sequel/paging_spec.rb +0 -64
  105. data/spec/trailblazer/finder/adapters/sequel/predicates_spec.rb +0 -89
  106. data/spec/trailblazer/finder/adapters/sequel/sorting_spec.rb +0 -110
  107. data/spec/trailblazer/finder/adapters_spec.rb +0 -110
  108. data/spec/trailblazer/finder/features/paging_spec.rb +0 -104
  109. data/spec/trailblazer/finder/features/predicates_spec.rb +0 -99
  110. data/spec/trailblazer/finder/features/sorting_spec.rb +0 -96
  111. data/spec/trailblazer/finder/features_spec.rb +0 -55
  112. data/spec/trailblazer/finder/filter_spec.rb +0 -133
  113. data/spec/trailblazer/finder/find_spec.rb +0 -72
  114. data/spec/trailblazer/finder/utils/extra_spec.rb +0 -41
  115. data/spec/trailblazer/finder/utils/params_spec.rb +0 -39
  116. data/spec/trailblazer/finder/utils/parse_spec.rb +0 -33
  117. data/spec/trailblazer/operation/paging_spec.rb +0 -68
  118. data/spec/trailblazer/operation/predicates_spec.rb +0 -127
  119. data/spec/trailblazer/operation/sorting_spec.rb +0 -80
  120. data/spec/trailblazer/test_spec.rb +0 -41
@@ -0,0 +1,213 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ module Trailblazer
6
+ class Finder # rubocop:disable Metrics/ClassLength
7
+ describe Dsl do
8
+ def define_finder_class(&block)
9
+ Class.new(Trailblazer::Finder) do
10
+ class_eval(&block)
11
+ end
12
+ end
13
+
14
+ def finder_class(default_entity = [], &block)
15
+ define_finder_class do
16
+ entity { default_entity }
17
+
18
+ class_eval(&block) unless block.nil?
19
+ end
20
+ end
21
+
22
+ def new_finder(default_entity = [], filter = {}, &block)
23
+ finder_class(default_entity, &block).new params: filter
24
+ end
25
+
26
+ describe "entity" do
27
+ def empty_finder_class
28
+ define_finder_class do
29
+ filter_by :name do
30
+ end
31
+ end
32
+ end
33
+
34
+ it "accepts entity as argument" do
35
+ expect(finder_class.new(entity: "entity").result).to eq "entity"
36
+ end
37
+
38
+ it "raises an error if no entity is provided" do
39
+ expect(empty_finder_class.new.errors).to eq [{entity: "Invalid entity specified"}]
40
+ end
41
+
42
+ it "can overwrite the finder entity" do
43
+ finder_class = define_finder_class do
44
+ entity { "entity" }
45
+ end
46
+
47
+ expect(finder_class.new(entity: "other entity").result).to eq "other entity"
48
+ end
49
+
50
+ it "passing nil as entity in constructor, falls back to default entity" do
51
+ finder_class = define_finder_class do
52
+ entity { "entity" }
53
+ end
54
+
55
+ expect(finder_class.new(entity: nil).result).to eq "entity"
56
+ end
57
+ end
58
+
59
+ describe "#adapters" do
60
+ it "checks for a valid adapter and returns an error" do
61
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
62
+ finder = new_finder entity, value_eq: "Test 1" do
63
+ adapters :NonExisting
64
+ end
65
+
66
+ expect(finder.errors).to eq [{adapters: "One or more of the specified adapters are invalid"}]
67
+ end
68
+
69
+ it "checks if multiple orm adapters are requested and returns an error" do
70
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
71
+ finder = new_finder entity, value_eq: "Test 1" do
72
+ adapters :ActiveRecord, :Sequel
73
+ end
74
+
75
+ expect(finder.errors).to eq [{adapters: "More then one ORM adapter specified"}]
76
+ end
77
+
78
+ it "sets the adapter in the config" do
79
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
80
+ finder = new_finder entity, value_eq: "Test 1" do
81
+ adapters ActiveRecord
82
+ property :value, type: Base
83
+ end
84
+
85
+ expect(finder.class.config[:adapters]).to eq ["ActiveRecord"]
86
+ end
87
+ end
88
+
89
+ describe "#property" do
90
+ it "checks for a valid property type and returns an error" do
91
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
92
+ finder = new_finder entity, value_eq: "Test 1" do
93
+ property :value, type: Base
94
+ end
95
+
96
+ expect(finder.errors).to eq [{properties: "One or more properties are missing a valid type"}]
97
+ end
98
+
99
+ it "sets the property and it's type properly in the config" do
100
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
101
+ finder = new_finder entity, value_eq: "Test 1" do
102
+ property :value, type: Base
103
+ end
104
+
105
+ expect(finder.class.config[:properties]).to eq value: {type: Trailblazer::Finder::Base}
106
+ end
107
+ end
108
+
109
+ describe "#paging" do
110
+ it "sets the paging values" do
111
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
112
+ finder = new_finder entity do
113
+ paging per_page: 2, min_per_page: 1, max_per_page: 5
114
+ property :value, type: Types::String
115
+ end
116
+
117
+ expect(finder.class.config[:paging][:per_page]).to eq 2
118
+ expect(finder.class.config[:paging][:min_per_page]).to eq 1
119
+ expect(finder.class.config[:paging][:max_per_page]).to eq 5
120
+ end
121
+
122
+ it "does not load paging stuff if paging isn't called in the finder class" do
123
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
124
+ finder = new_finder entity do
125
+ property :value, type: Types::String
126
+ end
127
+
128
+ expect(finder.class.config[:paging]).to be_empty
129
+ end
130
+ end
131
+
132
+ describe "#filter_by" do
133
+ it "returns an error when supplied with a non symbol" do
134
+ entity = [1, 2, 3]
135
+ finder = new_finder entity, value_test: "some" do
136
+ filter_by :value_test, with: "test"
137
+ end
138
+
139
+ expect(finder.result).to eq errors: [{filters: "One or more filters are missing a with method definition"}]
140
+ end
141
+
142
+ it "has a default filter" do
143
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
144
+ finder = new_finder entity, value: "Test 1" do
145
+ filter_by :value
146
+ end
147
+
148
+ expect(finder.result.map { |n| n[:value] }).to eq ["Test 1"]
149
+ end
150
+
151
+ it "has a default filter working when it's nested" do
152
+ entity = [{id: 1, value: [id: 4, value: "Test 1"]}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
153
+ finder = new_finder entity, value: "Test 1" do
154
+ filter_by :value
155
+ end
156
+
157
+ expect(finder.result.map { |n| n[:value] }).to eq ["Test 1"]
158
+ expect(finder.result.map { |n| n[:id] }).to eq [4]
159
+ end
160
+
161
+ it "has another default filter" do
162
+ entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
163
+ finder = new_finder entity, id: 2 do
164
+ filter_by :id
165
+ end
166
+
167
+ expect(finder.result.map { |n| n[:value] }).to eq ["Test 2"]
168
+ end
169
+
170
+ it "returns the entity if nil is returned" do
171
+ entity = [1, 2, 3]
172
+ finder = new_finder entity, value_test: "some" do
173
+ filter_by :value_test do
174
+ nil
175
+ end
176
+ end
177
+
178
+ expect(finder.result).to eq entity
179
+ end
180
+
181
+ it "can use methods from the object" do
182
+ finder_1 = new_finder [1, 2, 3], filter: 1 do
183
+ filter_by :filter do |entity, attribute, value|
184
+ some_instance_method(entity, attribute, value)
185
+ end
186
+
187
+ private
188
+
189
+ def some_instance_method(entity, _attribute, _value)
190
+ entity - [2, 3]
191
+ end
192
+ end
193
+
194
+ expect(finder_1.result).to eq [1]
195
+ end
196
+
197
+ it "can dispatch with instance methods" do
198
+ finder = new_finder [1, 2, 3], filter: 1 do
199
+ filter_by :filter, with: :some_instance_method
200
+
201
+ private
202
+
203
+ def some_instance_method(entity, _attribute, value)
204
+ entity.select { |v| v == value }
205
+ end
206
+ end
207
+
208
+ expect(finder.result).to eq [1]
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ module Trailblazer
6
+ class Finder
7
+ module Utils
8
+ describe Hash do
9
+ let(:hash) do
10
+ [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: ""}, {id: 4, value: "Test 4"}]
11
+ end
12
+
13
+ describe ".deep_locate" do
14
+ it "locates enumerables for which the given comparator returns true for at least one element" do
15
+ expect(described_class.deep_locate(->(k, v, _) { k == :value && v.to_s == "Test 2" && !v.nil? }, hash))
16
+ .to eq [{id: 2, value: "Test 2"}]
17
+ end
18
+ end
19
+
20
+ it "returns an empty array if nothing was found" do
21
+ expect(described_class.deep_locate(:muff, foo: "bar")).to eq([])
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ module Trailblazer
6
+ class Finder
7
+ module Utils
8
+ describe Splitter do
9
+ describe ".initialize" do
10
+ it "sets key and value" do
11
+ splitter = described_class.new "attribute_eq", "value"
12
+ expect(splitter.key).to eq "attribute_eq"
13
+ expect(splitter.value).to eq "value"
14
+ end
15
+ end
16
+
17
+ describe ".split_key" do
18
+ it "checks if specified split key exists" do
19
+ splitter = described_class.new "attribute_eq", "value"
20
+ expect(splitter.split_key("random")).to eq false
21
+ expect(splitter.split_key("eq")).to eq true
22
+ end
23
+
24
+ it "fills field value when split key exists" do
25
+ splitter = described_class.new "attribute_eq", "value"
26
+ splitter.split_key("eq")
27
+ expect(splitter.field).to eq "attribute"
28
+ end
29
+
30
+ it "fills predicate value when split key exists" do
31
+ splitter = described_class.new "attribute_eq", "value"
32
+ splitter.split_key("eq")
33
+ expect(splitter.predicate).to eq :eq
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,22 +1,65 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  module Trailblazer
4
6
  class Finder
5
7
  module Utils
6
8
  describe String do
7
- describe '.camelize' do
8
- it "transforms :paging to 'Paging'" do
9
- expect(Finder::Utils::String.camelize(:paging)).to eq 'Paging'
9
+ describe ".blank?" do
10
+ it "checks if value is blank or nil" do
11
+ expect(described_class.blank?("")).to eq true
12
+ expect(described_class.blank?(nil)).to eq true
13
+ expect(described_class.blank?("what")).to eq false
14
+ expect(described_class.blank?(1)).to eq false
15
+ end
16
+ end
17
+
18
+ describe ".numeric?" do
19
+ it "checks if value is numeric" do
20
+ expect(described_class.numeric?("")).to eq false
21
+ expect(described_class.numeric?(nil)).to eq false
22
+ expect(described_class.numeric?(1)).to eq true
23
+ expect(described_class.numeric?(0)).to eq true
24
+ expect(described_class.numeric?(1.00000)).to eq true
25
+ expect(described_class.numeric?("1")).to eq true
10
26
  end
11
27
  end
12
28
 
13
- describe '.underscore' do
14
- it "transforms 'veryPopular' to 'very_popular'" do
15
- expect(Finder::Utils::String.underscore(:veryPopular)).to eq 'very_popular'
29
+ describe ".date?" do
30
+ it "checks if value is a date" do
31
+ expect(described_class.date?("2018-01-01")).to eq true
32
+ expect(described_class.date?(nil)).to eq false
33
+ expect(described_class.date?("random")).to eq false
34
+ expect(described_class.date?(1)).to eq false
35
+ expect(described_class.date?("2018/01/01")).to eq true
36
+ expect(described_class.date?("2018.01.01")).to eq true
37
+ expect(described_class.date?("21-12-2018")).to eq true
16
38
  end
39
+ end
40
+
41
+ describe ".to_date" do
42
+ it "transforms a date like value to a valid date" do
43
+ expect(described_class.to_date("28/09/2018")).to eq "2018-09-28"
44
+ expect(described_class.to_date("2018/09/28")).to eq "2018-09-28"
45
+ expect(described_class.to_date("28 september 2018")).to eq "2018-09-28"
46
+ expect(described_class.to_date("third month of this year")).to eq nil
47
+ end
48
+ end
49
+
50
+ describe ".camelize" do
51
+ it "transforms a string by capatalizing each word's first letter" do
52
+ expect(described_class.camelize(:paging)).to eq "Paging"
53
+ expect(described_class.camelize(:some_random_test)).to eq "SomeRandomTest"
54
+ end
55
+ end
17
56
 
18
- it "transforms 'Very Popular' to 'very_popular'" do
19
- expect(Finder::Utils::String.underscore('Very Popular')).to eq 'very_popular'
57
+ describe ".underscore" do
58
+ it "transforms a string by dividing words with underscores" do
59
+ expect(described_class.underscore(:veryPopular)).to eq "very_popular"
60
+ expect(described_class.underscore(:VeryPopular)).to eq "very_popular"
61
+ expect(described_class.underscore(:SomethingveryPopularButRandom)).to eq "somethingvery_popular_but_random"
62
+ expect(described_class.underscore("Very Popular")).to eq "very_popular"
20
63
  end
21
64
  end
22
65
  end
@@ -1,32 +1,36 @@
1
- require 'delegate'
2
- require 'trailblazer'
3
- require 'spec_helper_active_record'
1
+ # frozen_string_literal: true
2
+
3
+ require "delegate"
4
+ require "trailblazer"
5
+ require "spec_helper_active_record"
4
6
 
5
7
  class Product::FinderNoEntity < Trailblazer::Finder
6
8
  adapters ActiveRecord
7
9
 
8
- filter_by :id
9
- filter_by :name
10
+ property :id, type: Types::Integer
11
+ property :name, type: Types::String, sortable: true
10
12
  filter_by :escaped_name, with: :apply_escaped_name
11
13
 
12
- def apply_escaped_name(entity_type, value)
14
+ def apply_escaped_name(entity, _attribute, value)
13
15
  return unless value.present?
14
- entity_type.where 'lower(name) LIKE ?', Utils::Parse.term(value.downcase)
16
+
17
+ entity.where "lower(name) LIKE ?", "%#{value.downcase}%"
15
18
  end
16
19
  end
17
20
 
18
21
  class Product::FinderWithEntity < Trailblazer::Finder
19
22
  adapters ActiveRecord
20
23
 
21
- entity_type { Product }
24
+ entity { Product }
22
25
 
23
- filter_by :id
24
- filter_by :name
26
+ property :id, type: Types::Integer
27
+ property :name, type: Types::String, sortable: true
25
28
  filter_by :escaped_name, with: :apply_escaped_name
26
29
 
27
- def apply_escaped_name(entity_type, value)
30
+ def apply_escaped_name(entity, _attribute, value)
28
31
  return unless value.present?
29
- entity_type.where 'lower(name) LIKE ?', Utils::Parse.term(value.downcase)
32
+
33
+ entity.where "lower(name) LIKE ?", "%#{value.downcase}%"
30
34
  end
31
35
  end
32
36
 
@@ -46,8 +50,7 @@ class Product::ShowNoEntity < Trailblazer::Operation
46
50
  step Finder(Product::FinderWithEntity, :single)
47
51
  end
48
52
 
49
-
50
- describe 'Trailblazer::Operation - Finder Macro' do
53
+ describe "Trailblazer::Operation - Finder Macro" do
51
54
  before do
52
55
  Product.destroy_all
53
56
  Product.reset_pk_sequence
@@ -59,45 +62,45 @@ describe 'Trailblazer::Operation - Finder Macro' do
59
62
  Product.reset_pk_sequence
60
63
  end
61
64
 
62
- it 'Can find a single row by id' do
63
- params = { id: 5 }
65
+ it "Can find a single row by id" do
66
+ params = {id: 5}
64
67
  result = Product::Show.call(params: params)
65
68
 
66
- expect(result[:finder].name).to eq 'product_4'
69
+ expect(result[:finder].name).to eq "product_4"
67
70
  end
68
71
 
69
- it 'Can find a single row by name' do
70
- params = { f: { name: 'product_2' } }
72
+ it "Can find a single row by name" do
73
+ params = {name_eq: "product_2"}
71
74
  result = Product::Show.call(params: params)
72
75
 
73
- expect(result[:finder].name).to eq 'product_2'
76
+ expect(result[:finder].name).to eq "product_2"
74
77
  end
75
78
 
76
- it 'Can find multiple rows by escaped name' do
77
- params = { f: { escaped_name: 'product_1' } }
79
+ it "Can find multiple rows by escaped name" do
80
+ params = {escaped_name: "product_1"}
78
81
  result = Product::Index.call(params: params)
79
82
 
80
- expect(result[:finder].results.last.name).to eq 'product_19'
83
+ expect(result[:finder].result.last.name).to eq "product_19"
81
84
  end
82
85
 
83
- it 'Can find a single row by id when no entity type is given in macro' do
84
- params = { id: 8 }
86
+ it "Can find a single row by id when no entity type is given in macro" do
87
+ params = {id: 8}
85
88
  result = Product::ShowNoEntity.call(params: params)
86
89
 
87
- expect(result[:finder].name).to eq 'product_7'
90
+ expect(result[:finder].name).to eq "product_7"
88
91
  end
89
92
 
90
- it 'Can find a single row by name when no entity type is given in macro' do
91
- params = { f: { name: 'product_2' } }
93
+ it "Can find a single row by name when no entity type is given in macro" do
94
+ params = {name_eq: "product_2"}
92
95
  result = Product::ShowNoEntity.call(params: params)
93
96
 
94
- expect(result[:finder].name).to eq 'product_2'
97
+ expect(result[:finder].name).to eq "product_2"
95
98
  end
96
99
 
97
- it 'Can find multiple rows by escaped name when no entity type is given in macro' do
98
- params = { f: { escaped_name: 'product_1' } }
100
+ it "Can find multiple rows by escaped name when no entity type is given in macro" do
101
+ params = {escaped_name: "product_1"}
99
102
  result = Product::IndexNoEntity.call(params: params)
100
103
 
101
- expect(result[:finder].results.last.name).to eq 'product_19'
104
+ expect(result[:finder].result.last.name).to eq "product_19"
102
105
  end
103
106
  end