trailblazer-finder 0.10.1 → 0.70.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +16 -0
  3. data/.rubocop.yml +7 -1
  4. data/CHANGES.md +15 -0
  5. data/Gemfile +3 -1
  6. data/README.md +4 -4
  7. data/Rakefile +0 -6
  8. data/lib/trailblazer/finder/activities/find.rb +20 -21
  9. data/lib/trailblazer/finder/activities/prepare.rb +2 -3
  10. data/lib/trailblazer/finder/activities/prepare_adapter.rb +25 -0
  11. data/lib/trailblazer/finder/activities/prepare_entity.rb +5 -5
  12. data/lib/trailblazer/finder/activities/prepare_paging.rb +5 -11
  13. data/lib/trailblazer/finder/activities/prepare_params.rb +3 -3
  14. data/lib/trailblazer/finder/activities/prepare_properties.rb +1 -5
  15. data/lib/trailblazer/finder/activities/prepare_sorting.rb +3 -8
  16. data/lib/trailblazer/finder/activities/process.rb +0 -1
  17. data/lib/trailblazer/finder/activities/process_adapters.rb +25 -23
  18. data/lib/trailblazer/finder/adapters/active_record/paging.rb +1 -1
  19. data/lib/trailblazer/finder/adapters/active_record/predicates.rb +14 -14
  20. data/lib/trailblazer/finder/adapters/active_record/sorting.rb +1 -1
  21. data/lib/trailblazer/finder/adapters/basic/paging.rb +1 -1
  22. data/lib/trailblazer/finder/adapters/basic/predicates.rb +14 -14
  23. data/lib/trailblazer/finder/adapters/basic/sorting.rb +1 -1
  24. data/lib/trailblazer/finder/adapters/kaminari/paging.rb +2 -3
  25. data/lib/trailblazer/finder/adapters/sequel/paging.rb +1 -1
  26. data/lib/trailblazer/finder/adapters/sequel/predicates.rb +14 -14
  27. data/lib/trailblazer/finder/adapters/sequel/sorting.rb +1 -1
  28. data/lib/trailblazer/finder/adapters/will_paginate/paging.rb +2 -3
  29. data/lib/trailblazer/finder/dsl.rb +12 -9
  30. data/lib/trailblazer/finder/find.rb +4 -2
  31. data/lib/trailblazer/finder/helpers/sorting.rb +4 -1
  32. data/lib/trailblazer/finder/version.rb +1 -1
  33. data/lib/trailblazer/finder.rb +1 -7
  34. data/lib/trailblazer/operation/finder.rb +3 -3
  35. data/spec/spec_helper.rb +0 -1
  36. data/spec/trailblazer/finder/adapters/active_record_spec.rb +5 -5
  37. data/spec/trailblazer/finder/adapters/basic_spec.rb +12 -3
  38. data/spec/trailblazer/finder/adapters/kaminari_spec.rb +13 -8
  39. data/spec/trailblazer/finder/adapters/sequel_spec.rb +5 -5
  40. data/spec/trailblazer/finder/adapters/will_paginate_spec.rb +12 -7
  41. data/spec/trailblazer/finder/dsl_spec.rb +4 -13
  42. data/spec/trailblazer/operation/finder_spec.rb +18 -3
  43. data/trailblazer-finder.gemspec +4 -5
  44. metadata +21 -36
  45. data/.rubocop_todo.yml +0 -78
  46. data/.travis.yml +0 -7
  47. data/lib/trailblazer/finder/activities/prepare_adapters.rb +0 -52
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_eq_handler
13
- lambda do |entity, attribute, value|
13
+ ->(entity, attribute, value) do
14
14
  return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
15
15
 
16
16
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s == value.to_s && !v.nil? }, entity
@@ -18,7 +18,7 @@ module Trailblazer
18
18
  end
19
19
 
20
20
  def set_not_eq_handler
21
- lambda do |entity, attribute, value|
21
+ ->(entity, attribute, value) do
22
22
  return if Utils::String.blank?(value.to_s)
23
23
 
24
24
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s != value.to_s && !v.nil? }, entity
@@ -26,43 +26,43 @@ module Trailblazer
26
26
  end
27
27
 
28
28
  def set_blank_handler
29
- lambda do |entity, attribute, _value|
29
+ ->(entity, attribute, _value) do
30
30
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && Utils::String.blank?(v.to_s) }, entity
31
31
  end
32
32
  end
33
33
 
34
34
  def set_not_blank_handler
35
- lambda do |entity, attribute, _value|
35
+ ->(entity, attribute, _value) do
36
36
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !Utils::String.blank?(v.to_s) }, entity
37
37
  end
38
38
  end
39
39
 
40
40
  def set_gt_handler
41
- lambda do |entity, attribute, value|
41
+ ->(entity, attribute, value) do
42
42
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_f > value.to_f }, entity
43
43
  end
44
44
  end
45
45
 
46
46
  def set_gte_handler
47
- lambda do |entity, attribute, value|
47
+ ->(entity, attribute, value) do
48
48
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_f >= value.to_f }, entity
49
49
  end
50
50
  end
51
51
 
52
52
  def set_lt_handler
53
- lambda do |entity, attribute, value|
53
+ ->(entity, attribute, value) do
54
54
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_f < value.to_f }, entity
55
55
  end
56
56
  end
57
57
 
58
58
  def set_lte_handler
59
- lambda do |entity, attribute, value|
59
+ ->(entity, attribute, value) do
60
60
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_i <= value.to_f }, entity
61
61
  end
62
62
  end
63
63
 
64
64
  def set_cont_handler
65
- lambda do |entity, attribute, value|
65
+ ->(entity, attribute, value) do
66
66
  return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
67
67
 
68
68
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s.include?(value.to_s) && !v.nil? }, entity
@@ -70,7 +70,7 @@ module Trailblazer
70
70
  end
71
71
 
72
72
  def set_not_cont_handler
73
- lambda do |entity, attribute, value|
73
+ ->(entity, attribute, value) do
74
74
  return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
75
75
 
76
76
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !v.to_s.include?(value.to_s) && !v.nil? }, entity
@@ -78,7 +78,7 @@ module Trailblazer
78
78
  end
79
79
 
80
80
  def set_sw_handler
81
- lambda do |entity, attribute, value|
81
+ ->(entity, attribute, value) do
82
82
  return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
83
83
 
84
84
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s.start_with?(value.to_s) && !v.nil? }, entity
@@ -86,7 +86,7 @@ module Trailblazer
86
86
  end
87
87
 
88
88
  def set_not_sw_handler
89
- lambda do |entity, attribute, value|
89
+ ->(entity, attribute, value) do
90
90
  return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
91
91
 
92
92
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !v.to_s.start_with?(value.to_s) && !v.nil? }, entity
@@ -94,7 +94,7 @@ module Trailblazer
94
94
  end
95
95
 
96
96
  def set_ew_handler
97
- lambda do |entity, attribute, value|
97
+ ->(entity, attribute, value) do
98
98
  return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
99
99
 
100
100
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s.end_with?(value.to_s) && !v.nil? }, entity
@@ -102,7 +102,7 @@ module Trailblazer
102
102
  end
103
103
 
104
104
  def set_not_ew_handler
105
- lambda do |entity, attribute, value|
105
+ ->(entity, attribute, value) do
106
106
  return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
107
107
 
108
108
  Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !v.to_s.end_with?(value.to_s) && !v.nil? }, entity
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_sorting_handler
13
- lambda do |sort_attributes, entity|
13
+ ->(sort_attributes, entity) do
14
14
  sort_attributes.delete(:handler)
15
15
  attributes = []
16
16
  sort_attributes.each do |attr|
@@ -3,14 +3,13 @@
3
3
  module Trailblazer
4
4
  class Finder
5
5
  module Adapters
6
- # ActiveRecord Adapter
7
6
  module Kaminari
8
- # Kaminari Paging Adapter
7
+ # Kaminari Paginator
9
8
  module Paging
10
9
  module_function
11
10
 
12
11
  def set_paging_handler
13
- lambda do |current_page, per_page, entity|
12
+ ->(current_page, per_page, entity) do
14
13
  entity.page(current_page).per(per_page)
15
14
  end
16
15
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_paging_handler
13
- lambda do |current_page, per_page, entity|
13
+ ->(current_page, per_page, entity) do
14
14
  entity.limit(per_page).offset(([current_page, 1].max - 1) * per_page)
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_eq_handler
13
- lambda do |entity, attribute, value|
13
+ ->(entity, attribute, value) do
14
14
  return if Utils::String.blank?(value.to_s)
15
15
 
16
16
  entity.where { ::Sequel[attribute.to_sym] =~ value }
@@ -18,7 +18,7 @@ module Trailblazer
18
18
  end
19
19
 
20
20
  def set_not_eq_handler
21
- lambda do |entity, attribute, value|
21
+ ->(entity, attribute, value) do
22
22
  return if Utils::String.blank?(value.to_s)
23
23
 
24
24
  entity.where { ::Sequel[attribute.to_sym] !~ value }
@@ -26,74 +26,74 @@ module Trailblazer
26
26
  end
27
27
 
28
28
  def set_blank_handler
29
- lambda do |entity, attribute, _value|
29
+ ->(entity, attribute, _value) do
30
30
  entity.where { ::Sequel.|({::Sequel[attribute.to_sym] => nil}, {::Sequel[attribute.to_sym] => ""}) }
31
31
  end
32
32
  end
33
33
 
34
34
  def set_not_blank_handler
35
- lambda do |entity, attribute, _value|
35
+ ->(entity, attribute, _value) do
36
36
  entity.exclude(::Sequel[attribute.to_sym] => nil, ::Sequel[attribute.to_sym] => "")
37
37
  # entity.exclude(attribute.to_sym => nil).exclude(attribute.to_sym => "")
38
38
  end
39
39
  end
40
40
 
41
41
  def set_gt_handler
42
- lambda do |entity, attribute, value|
42
+ ->(entity, attribute, value) do
43
43
  entity.where { ::Sequel[attribute.to_sym] > value.to_f }
44
44
  end
45
45
  end
46
46
 
47
47
  def set_gte_handler
48
- lambda do |entity, attribute, value|
48
+ ->(entity, attribute, value) do
49
49
  entity.where { ::Sequel[attribute.to_sym] >= value.to_f }
50
50
  end
51
51
  end
52
52
 
53
53
  def set_lt_handler
54
- lambda do |entity, attribute, value|
54
+ ->(entity, attribute, value) do
55
55
  entity.where { ::Sequel[attribute.to_sym] < value.to_f }
56
56
  end
57
57
  end
58
58
 
59
59
  def set_lte_handler
60
- lambda do |entity, attribute, value|
60
+ ->(entity, attribute, value) do
61
61
  entity.where { ::Sequel[attribute.to_sym] <= value.to_f }
62
62
  end
63
63
  end
64
64
 
65
65
  def set_cont_handler
66
- lambda do |entity, attribute, value|
66
+ ->(entity, attribute, value) do
67
67
  entity.where(::Sequel.like(attribute.to_sym, "%#{value}%"))
68
68
  end
69
69
  end
70
70
 
71
71
  def set_not_cont_handler
72
- lambda do |entity, attribute, value|
72
+ ->(entity, attribute, value) do
73
73
  entity.where(~::Sequel.like(attribute.to_sym, "%#{value}%"))
74
74
  end
75
75
  end
76
76
 
77
77
  def set_sw_handler
78
- lambda do |entity, attribute, value|
78
+ ->(entity, attribute, value) do
79
79
  entity.where(::Sequel.like(attribute.to_sym, "#{value}%"))
80
80
  end
81
81
  end
82
82
 
83
83
  def set_not_sw_handler
84
- lambda do |entity, attribute, value|
84
+ ->(entity, attribute, value) do
85
85
  entity.where(~::Sequel.like(attribute.to_sym, "#{value}%"))
86
86
  end
87
87
  end
88
88
 
89
89
  def set_ew_handler
90
- lambda do |entity, attribute, value|
90
+ ->(entity, attribute, value) do
91
91
  entity.where(::Sequel.like(attribute.to_sym, "%#{value}"))
92
92
  end
93
93
  end
94
94
 
95
95
  def set_not_ew_handler
96
- lambda do |entity, attribute, value|
96
+ ->(entity, attribute, value) do
97
97
  entity.where(~::Sequel.like(attribute.to_sym, "%#{value}"))
98
98
  end
99
99
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_sorting_handler
13
- lambda do |sort_attributes, entity|
13
+ ->(sort_attributes, entity) do
14
14
  sort_attributes.delete(:handler)
15
15
  attributes = []
16
16
  sort_attributes.each do |attr|
@@ -3,14 +3,13 @@
3
3
  module Trailblazer
4
4
  class Finder
5
5
  module Adapters
6
- # ActiveRecord Adapter
7
6
  module WillPaginate
8
- # Kaminari Paging Adapter
7
+ # Kaminari Paginator
9
8
  module Paging
10
9
  module_function
11
10
 
12
11
  def set_paging_handler
13
- lambda do |current_page, per_page, entity|
12
+ ->(current_page, per_page, entity) do
14
13
  entity.paginate per_page: per_page, page: current_page.zero? ? nil : current_page
15
14
  end
16
15
  end
@@ -13,7 +13,7 @@ module Trailblazer
13
13
  config[:entity] = block
14
14
  end
15
15
 
16
- def paging(options, **)
16
+ def paging(**options)
17
17
  config[:paging][:per_page] = options[:per_page] || 25
18
18
  config[:paging][:min_per_page] = options[:min_per_page] || 10
19
19
  config[:paging][:max_per_page] = options[:max_per_page] || 100
@@ -26,16 +26,19 @@ module Trailblazer
26
26
  end
27
27
 
28
28
  def filter_by(name, options = {}, &block)
29
- config[:filters][name] = {}
30
- config[:filters][name][:name] = name
31
- config[:filters][name][:with] = options[:with] if options.include?(:with)
32
- config[:filters][name][:block] = block || nil
29
+ filter_name = name.to_sym
30
+ config[:filters][filter_name] = {}
31
+ config[:filters][filter_name][:name] = name
32
+ config[:filters][filter_name][:with] = options[:with] if options.include?(:with)
33
+ config[:filters][filter_name][:block] = block || nil
33
34
  end
34
35
 
35
- def adapters(*adapters)
36
- adapters.each do |adapter|
37
- config[:adapters].push adapter.to_s.split("::").last.gsub("}>", "") if config[:adapters]
38
- end
36
+ def adapter(adapter)
37
+ config[:adapter] = adapter.to_s
38
+ end
39
+
40
+ def paginator(paginator)
41
+ config[:paginator] = paginator.to_s
39
42
  end
40
43
 
41
44
  def apply_config(options, **)
@@ -17,13 +17,15 @@ module Trailblazer
17
17
  def process_filters(ctx)
18
18
  @params.reduce(@entity) do |entity, (name, value)|
19
19
  value = Utils::String.to_date(value) if Utils::String.date?(value)
20
- new_entity = ctx.instance_exec entity, @filters[name.to_sym][:name], value, &@filters[name.to_sym][:handler]
20
+ filter = @filters[name.to_sym] || @filters[name]
21
+ new_entity = ctx.instance_exec entity, filter[:name], value, &filter[:handler]
21
22
  new_entity || entity
22
23
  end
23
24
  end
24
25
 
25
26
  def process_paging(ctx)
26
- ctx.instance_exec @paging[:current_page], @paging[:per_page], (@sorting.empty? ? (process_filters ctx) : (process_sorting ctx)), &@paging[:handler]
27
+ ctx.instance_exec @paging[:current_page], @paging[:per_page],
28
+ (@sorting.empty? ? (process_filters ctx) : (process_sorting ctx)), &@paging[:handler]
27
29
  end
28
30
 
29
31
  def process_sorting(ctx)
@@ -31,7 +31,10 @@ module Trailblazer
31
31
  if sorting.nil?
32
32
  params.merge! sort: "#{attribute} #{sort_direction_for(attribute)}"
33
33
  elsif sorting.include?(attribute.to_s)
34
- params.merge! sort: sorting.gsub(/#{attribute} #{sort_direction_for(attribute)}/, "#{attribute} #{reverse_sort_direction_for(attribute)}")
34
+ params.merge! sort: sorting.gsub(
35
+ /#{attribute} #{sort_direction_for(attribute)}/,
36
+ "#{attribute} #{reverse_sort_direction_for(attribute)}"
37
+ )
35
38
  else
36
39
  params.merge! sort: "#{sorting}, #{attribute} #{sort_direction_for(attribute)}"
37
40
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trailblazer
4
4
  class Finder
5
- VERSION = "0.10.1".freeze
5
+ VERSION = "0.70.0"
6
6
  end
7
7
  end
@@ -33,14 +33,8 @@ require "trailblazer/operation/finder"
33
33
 
34
34
  module Trailblazer
35
35
  class Finder
36
- DRY_TYPES_VERSION = Gem::Version.new(Dry::Types::VERSION)
37
- LEGACY_DRY_TYPES = DRY_TYPES_VERSION <= Gem::Version.new('1')
38
36
  module Types
39
- if LEGACY_DRY_TYPES
40
- include Dry::Types.module
41
- else
42
- include Dry.Types(default: :nominal)
43
- end
37
+ include Dry.Types(default: :nominal)
44
38
  end
45
39
 
46
40
  include Base
@@ -12,13 +12,12 @@ Trailblazer::Operation.instance_eval do
12
12
  end
13
13
 
14
14
  class Finder
15
- def call(ctx, options, **)
15
+ def call(ctx, **options)
16
16
  builder = Finder::Builder.new
17
17
  ctx[:finder] = finder = builder.call(options, options[:params])
18
18
  ctx[:model] = finder # Don't like it, but somehow it's needed if contracts are loaded
19
19
  ctx[:"result.finder"] = Trailblazer::Operation::Result.new(!finder.nil?, {})
20
20
 
21
-
22
21
  ctx[:"result.finder"].success?
23
22
  end
24
23
 
@@ -49,7 +48,8 @@ Trailblazer::Operation.instance_eval do
49
48
 
50
49
  def apply_id(params)
51
50
  return if params[:id].nil?
52
- params[:id_eq] = params[:id] unless params.key?("id")
51
+
52
+ params[:id_eq] = params[:id]
53
53
  end
54
54
  end
55
55
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/setup"
4
- require "pry-byebug"
5
4
  require "trailblazer/developer"
6
5
  require "trailblazer/activity"
7
6
  require "trailblazer/activity/testing"
@@ -13,7 +13,7 @@ module Trailblazer
13
13
 
14
14
  def define_finder_class(&block)
15
15
  Class.new(Trailblazer::Finder) do
16
- adapters ActiveRecord
16
+ adapter "ActiveRecord"
17
17
  entity { Product }
18
18
 
19
19
  class_eval(&block)
@@ -132,7 +132,7 @@ module Trailblazer
132
132
 
133
133
  it "sets the property and works with sw predicate" do
134
134
  5.times { |i| Product.create name: "product_#{i}" }
135
- 1.times { |i| Product.create name: "predicate_#{i}" }
135
+ Product.create name: "predicate_0"
136
136
  4.times { |i| Product.create name: "none_#{i}" }
137
137
  finder = new_finder name_sw: "pr" do
138
138
  property :name, type: Types::String
@@ -144,7 +144,7 @@ module Trailblazer
144
144
 
145
145
  it "sets the property and works with not_sw predicate" do
146
146
  5.times { |i| Product.create name: "product_#{i}" }
147
- 1.times { |i| Product.create name: "predicate_#{i}" }
147
+ Product.create name: "predicate_0"
148
148
  4.times { |i| Product.create name: "none_#{i}" }
149
149
  finder = new_finder name_not_sw: "pr" do
150
150
  property :name, type: Types::String
@@ -156,7 +156,7 @@ module Trailblazer
156
156
 
157
157
  it "sets the property and works with ew predicate" do
158
158
  5.times { |i| Product.create name: "product_#{i}_end" }
159
- 1.times { |i| Product.create name: "predicate_#{i}_endwow" }
159
+ Product.create name: "predicate_0_endwow"
160
160
  4.times { |i| Product.create name: "none_#{i}" }
161
161
  finder = new_finder name_ew: "end" do
162
162
  property :name, type: Types::String
@@ -168,7 +168,7 @@ module Trailblazer
168
168
 
169
169
  it "sets the property and works with not_ew predicate" do
170
170
  5.times { |i| Product.create name: "product_#{i}_end" }
171
- 1.times { |i| Product.create name: "predicate_#{i}_endwow" }
171
+ Product.create name: "predicate_0_endwow"
172
172
  4.times { |i| Product.create name: "none_#{i}" }
173
173
  finder = new_finder name_not_ew: "end" do
174
174
  property :name, type: Types::String
@@ -173,7 +173,10 @@ module Trailblazer
173
173
  end
174
174
 
175
175
  it "accepts per_page as a parameter" do
176
- entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"}, {id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}]
176
+ entity = [
177
+ {id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"},
178
+ {id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}
179
+ ]
177
180
  finder = new_finder entity, page: 2, per_page: 4 do
178
181
  paging per_page: 5, min_per_page: 2, max_per_page: 8
179
182
  end
@@ -183,7 +186,10 @@ module Trailblazer
183
186
  end
184
187
 
185
188
  it "uses max_per_page in finder as maximum per_page" do
186
- entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"}, {id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}]
189
+ entity = [
190
+ {id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"},
191
+ {id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}
192
+ ]
187
193
  finder = new_finder entity, page: 2, per_page: 9 do
188
194
  paging per_page: 5, min_per_page: 2, max_per_page: 8
189
195
  end
@@ -193,7 +199,10 @@ module Trailblazer
193
199
  end
194
200
 
195
201
  it "uses min_per_page in finder as minimum per_page" do
196
- entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"}, {id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}]
202
+ entity = [
203
+ {id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"},
204
+ {id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}
205
+ ]
197
206
  finder = new_finder entity, page: 2, per_page: 1 do
198
207
  paging per_page: 5, min_per_page: 2, max_per_page: 8
199
208
  end
@@ -32,15 +32,15 @@ module Trailblazer
32
32
  finder_class(&block).new params: filter
33
33
  end
34
34
 
35
- describe "#adapters" do
35
+ describe "#adapter" do
36
36
  it "cannot use kaminari without an actual orm" do
37
37
  10.times { |i| Product.create name: "product_#{i}" }
38
38
  finder = new_finder do
39
- adapters Kaminari
39
+ paginator :Kaminari
40
40
  paging per_page: 2, min_per_page: 1, max_per_page: 5
41
41
  end
42
42
 
43
- expect(finder.errors).to eq [{adapters: "Can't use paging adapters like Kaminari without using an ORM like ActiveRecord or Sequel"}]
43
+ expect(finder.errors).to eq [{paginator: "Can't use paginator Kaminari without using an ORM like ActiveRecord or Sequel"}]
44
44
  end
45
45
  end
46
46
 
@@ -48,7 +48,8 @@ module Trailblazer
48
48
  it "sets the paging values and shows only the first page results" do
49
49
  10.times { |i| Product.create name: "product_#{i}" }
50
50
  finder = new_finder do
51
- adapters ActiveRecord, Kaminari
51
+ adapter :ActiveRecord
52
+ paginator "Kaminari"
52
53
  paging per_page: 2, min_per_page: 1, max_per_page: 5
53
54
  end
54
55
 
@@ -58,7 +59,8 @@ module Trailblazer
58
59
  it "accepts per_page as a parameter" do
59
60
  10.times { |i| Product.create name: "product_#{i}" }
60
61
  finder = new_finder page: 2, per_page: 4 do
61
- adapters ActiveRecord, Kaminari
62
+ adapter "ActiveRecord"
63
+ paginator "Kaminari"
62
64
  paging per_page: 5, min_per_page: 2, max_per_page: 8
63
65
  end
64
66
 
@@ -69,7 +71,8 @@ module Trailblazer
69
71
  it "uses max_per_page in finder as maximum per_page" do
70
72
  10.times { |i| Product.create name: "product_#{i}" }
71
73
  finder = new_finder page: 2, per_page: 9 do
72
- adapters ActiveRecord, Kaminari
74
+ adapter "ActiveRecord"
75
+ paginator "Kaminari"
73
76
  paging per_page: 5, min_per_page: 2, max_per_page: 8
74
77
  end
75
78
 
@@ -80,7 +83,8 @@ module Trailblazer
80
83
  it "uses min_per_page in finder as minimum per_page" do
81
84
  10.times { |i| Product.create name: "product_#{i}" }
82
85
  finder = new_finder page: 2, per_page: 1 do
83
- adapters ActiveRecord, Kaminari
86
+ adapter "ActiveRecord"
87
+ paginator "Kaminari"
84
88
  paging per_page: 5, min_per_page: 2, max_per_page: 8
85
89
  end
86
90
 
@@ -94,7 +98,8 @@ module Trailblazer
94
98
  5.times { |i| Product.create name: "product_#{i}" }
95
99
  5.times { |_i| Product.create name: "product" }
96
100
  finder = new_finder name_eq: "product", sort: "id desc", page: 2 do
97
- adapters ActiveRecord, Kaminari
101
+ adapter "ActiveRecord"
102
+ paginator "Kaminari"
98
103
  paging per_page: 2, min_per_page: 1, max_per_page: 5
99
104
  property :name, type: Types::String
100
105
  property :id, type: Types::Integer, sortable: true
@@ -13,7 +13,7 @@ module Trailblazer
13
13
 
14
14
  def define_finder_class(&block)
15
15
  Class.new(Trailblazer::Finder) do
16
- adapters Sequel
16
+ adapter "Sequel"
17
17
  entity { SProduct }
18
18
 
19
19
  class_eval(&block)
@@ -132,7 +132,7 @@ module Trailblazer
132
132
 
133
133
  it "sets the property and works with sw predicate" do
134
134
  5.times { |i| SProduct.create name: "product_#{i}" }
135
- 1.times { |i| SProduct.create name: "predicate_#{i}" }
135
+ SProduct.create name: "predicate_0"
136
136
  4.times { |i| SProduct.create name: "none_#{i}" }
137
137
  finder = new_finder name_sw: "pr" do
138
138
  property :name, type: Types::String
@@ -144,7 +144,7 @@ module Trailblazer
144
144
 
145
145
  it "sets the property and works with not_sw predicate" do
146
146
  5.times { |i| SProduct.create name: "product_#{i}" }
147
- 1.times { |i| SProduct.create name: "predicate_#{i}" }
147
+ SProduct.create name: "predicate_0"
148
148
  4.times { |i| SProduct.create name: "none_#{i}" }
149
149
  finder = new_finder name_not_sw: "pr" do
150
150
  property :name, type: Types::String
@@ -156,7 +156,7 @@ module Trailblazer
156
156
 
157
157
  it "sets the property and works with ew predicate" do
158
158
  5.times { |i| SProduct.create name: "product_#{i}_end" }
159
- 1.times { |i| SProduct.create name: "predicate_#{i}_endwow" }
159
+ SProduct.create name: "predicate_0_endwow"
160
160
  4.times { |i| SProduct.create name: "none_#{i}" }
161
161
  finder = new_finder name_ew: "end" do
162
162
  property :name, type: Types::String
@@ -168,7 +168,7 @@ module Trailblazer
168
168
 
169
169
  it "sets the property and works with not_ew predicate" do
170
170
  5.times { |i| SProduct.create name: "product_#{i}_end" }
171
- 1.times { |i| SProduct.create name: "predicate_#{i}_endwow" }
171
+ SProduct.create name: "predicate_0_endwow"
172
172
  4.times { |i| SProduct.create name: "none_#{i}" }
173
173
  finder = new_finder name_not_ew: "end" do
174
174
  property :name, type: Types::String