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
@@ -1,89 +0,0 @@
1
- require 'spec_helper_sequel'
2
- # require 'spec_helper'
3
-
4
- describe "Trailblazer::Finder::Adapters::Sequel::Predicates" do
5
- class TestSequelFinder < Trailblazer::Finder
6
- features Predicate
7
- adapters Sequel
8
-
9
- entity_type { SProduct }
10
-
11
- predicates_for :name, :price, :created_at
12
-
13
- filter_by(:category) { |entity_type, _| entity_type.joins(:category) }
14
- end
15
-
16
- def finder_with_predicate(filter = nil, value = nil, filters = {})
17
- TestSequelFinder.new filter: { filter => value }.merge(filters)
18
- end
19
-
20
- describe 'equals' do
21
- before do
22
- SProduct.order(:id).delete
23
- 10.times do |i|
24
- next SProduct.create name: "", price: "1#{i}" if i == 7
25
- next SProduct.create name: nil, price: "1#{i}" if i == 8
26
- next SProduct.create name: "product_4", price: "1#{i}" if i == 9
27
- SProduct.create name: "product_#{i}", price: "1#{i}"
28
- end
29
- end
30
-
31
- it 'it finds single row with name equal to product_5' do
32
- finder = finder_with_predicate 'name_eq', 'product_5'
33
- expect(finder.results.all.map(&:price)).to eq [15]
34
- end
35
-
36
- it 'it finds multiple rows with name equal to product_4' do
37
- finder = finder_with_predicate 'name_eq', 'product_4'
38
- expect(finder.results.all.map(&:price)).to eq [14, 19]
39
- end
40
-
41
- it 'it finds rows with name not equal to product_4' do
42
- finder = finder_with_predicate 'name_not_eq', 'product_4'
43
- expect(finder.results.all.map(&:name)).to eq ["product_0", "product_1", "product_2", "product_3", "product_5", "product_6", ""]
44
- expect(finder.results.all.map(&:price)).to eq [10, 11, 12, 13, 15, 16, 17]
45
- end
46
-
47
- it 'it finds multiple rows with name blank (empty/nil)' do
48
- finder = finder_with_predicate 'name_blank', ''
49
- expect(finder.results.all.map(&:price)).to eq [17, 18]
50
- end
51
-
52
- it 'it finds multiple rows with name not blank (empty/nil)' do
53
- finder = finder_with_predicate 'name_not_blank', ''
54
- expect(finder.results.all.map(&:name)).to eq ["product_0", "product_1", "product_2", "product_3", "product_4", "product_5", "product_6", "product_4"]
55
- end
56
-
57
- it 'it finds multiple rows with price less than 15' do
58
- finder = finder_with_predicate 'price_lt', 15
59
- expect(finder.results.all.map(&:name)).to eq ["product_0", "product_1", "product_2", "product_3", "product_4"]
60
- expect(finder.results.all.map(&:price)).to eq [10, 11, 12, 13, 14]
61
- end
62
-
63
- it 'it finds multiple rows with price equal to and less than 15' do
64
- finder = finder_with_predicate 'price_lte', 15
65
- expect(finder.results.all.map(&:name)).to eq ["product_0", "product_1", "product_2", "product_3", "product_4", "product_5"]
66
- expect(finder.results.all.map(&:price)).to eq [10, 11, 12, 13, 14, 15]
67
- end
68
-
69
- it 'it finds multiple rows with price greater than 15' do
70
- finder = finder_with_predicate 'price_gt', 15
71
- expect(finder.results.all.map(&:name)).to eq ["product_6", "", nil, "product_4"]
72
- expect(finder.results.all.map(&:price)).to eq [16, 17, 18, 19]
73
- end
74
-
75
- it 'it finds multiple rows with price equal to and greater than 15' do
76
- finder = finder_with_predicate 'price_gte', 15
77
- expect(finder.results.all.map(&:name)).to eq ["product_5", "product_6", "", nil, "product_4"]
78
- expect(finder.results.all.map(&:price)).to eq [15, 16, 17, 18, 19]
79
- end
80
-
81
- it 'it finds rows with name not equal to product_4 and name not blank and price greater than 14' do
82
- params = { name_not_blank: true, price_gt: 14 }
83
- finder = finder_with_predicate 'name_not_eq', 'product_4', params
84
-
85
- expect(finder.results.map(&:name)).to eq ["product_5", "product_6"]
86
- expect(finder.results.map(&:price)).to eq [15, 16]
87
- end
88
- end
89
- end
@@ -1,110 +0,0 @@
1
- require 'spec_helper_sequel'
2
-
3
- describe 'Trailblazer::Finder::Adapters::Sequel::Sorting', :sorting do
4
- after do
5
- SProduct.order(:id).delete
6
- end
7
-
8
- before do
9
- SProduct.order(:id).delete
10
- end
11
-
12
- class TestSequelSortFinder < Trailblazer::Finder
13
- features Sorting
14
- adapters Sequel
15
-
16
- entity_type { SProduct }
17
-
18
- sortable_by :name, :price, :created_at
19
-
20
- filter_by :name, with: :apply_name_filter
21
- filter_by :price
22
- filter_by(:s_category) { |entity_type, _| entity_type.association_join(:s_category) }
23
-
24
- def apply_name_filter(entity_type, value)
25
- end
26
- end
27
-
28
- def finder_with_sort(sort = nil, filters = {})
29
- TestSequelSortFinder.new filter: (sort.nil? ? {} : { name: 'test', sort: sort }).merge(filters)
30
- end
31
-
32
- def finder_with_nil_sort
33
- TestSequelSortFinder.new filter: { sort: nil }
34
- end
35
-
36
- describe 'sorting' do
37
- it 'loads results if no sort options are supplied in the params' do
38
- 5.times { |i| SProduct.create price: i }
39
- finder = finder_with_nil_sort
40
- expect(finder.results.map(&:price)).to eq [0, 1, 2, 3, 4]
41
- end
42
-
43
- it 'sorts results based on the sort option desc' do
44
- 5.times { |i| SProduct.create price: i }
45
-
46
- finder = finder_with_sort 'price desc'
47
- expect(finder.results.map(&:price)).to eq [4, 3, 2, 1, 0]
48
- end
49
-
50
- it 'sorts results based on the sort option asc' do
51
- 5.times { |i| SProduct.create price: i }
52
-
53
- finder = finder_with_sort 'price asc'
54
- expect(finder.results.map(&:price)).to eq [0, 1, 2, 3, 4]
55
- end
56
-
57
- it 'defaults to first sort by option' do
58
- 5.times { |i| SProduct.create name: "Name#{i}" }
59
-
60
- finder = finder_with_sort
61
- expect(finder.results.map(&:name)).to eq %w[Name0 Name1 Name2 Name3 Name4]
62
- end
63
-
64
- it 'ignores invalid sort values' do
65
- finder = finder_with_sort 'invalid attribute'
66
- expect { finder.results.to_a }.not_to raise_error
67
- end
68
-
69
- it 'can handle renames of sorting in joins' do
70
- older_category = SCategory.create title: 'older'
71
- newer_category = SCategory.create title: 'newer'
72
-
73
- product_of_newer_category = SProduct.create name: 'older product', s_category: newer_category
74
- product_of_older_category = SProduct.create name: 'newer product', s_category: older_category
75
-
76
- finder = finder_with_sort 'created_at desc', s_category: ''
77
-
78
- expect(finder.results.map(&:name)).to eq [product_of_older_category.name, product_of_newer_category.name]
79
- end
80
- end
81
-
82
- describe 'sorting by multiple' do
83
- before do
84
- 5.times do |i|
85
- SProduct.create name: "Name#{i}", price: "1#{i}"
86
- end
87
- SProduct.create name: 'Name3', price: '8'
88
- end
89
-
90
- it 'sorts by multiple columns name asc and price asc' do
91
- finder = finder_with_sort 'name asc, price asc'
92
- expect(finder.results.map(&:name)).to eq %w[Name0 Name1 Name2 Name3 Name3 Name4]
93
- expect(finder.results.map(&:price)).to eq [10, 11, 12, 8, 13, 14]
94
- end
95
-
96
- it 'sorts by multiple columns name asc and price desc' do
97
- finder = finder_with_sort 'name asc, price desc'
98
- expect(finder.results.map(&:name)).to eq %w[Name0 Name1 Name2 Name3 Name3 Name4]
99
- expect(finder.results.map(&:price)).to eq [10, 11, 12, 13, 8, 14]
100
- end
101
-
102
- it 'sorts by multiple columns name desc and price desc' do
103
- finder = finder_with_sort 'name desc, price desc'
104
- expect(finder.results.map(&:name)).to eq %w[Name4 Name3 Name3 Name2 Name1 Name0]
105
- expect(finder.results.map(&:price)).to eq [14, 13, 8, 12, 11, 10]
106
- end
107
- end
108
-
109
- it_behaves_like 'a sorting feature'
110
- end
@@ -1,110 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_record'
3
-
4
- module Trailblazer
5
- class Finder
6
- describe Adapters do
7
- def define_finder_class(&block)
8
- Class.new do
9
- include Trailblazer::Finder::Base
10
- include Trailblazer::Finder::Adapters
11
-
12
- instance_eval(&block) if block_given?
13
- end
14
- end
15
-
16
- describe '.adapters' do
17
- it 'responds to adapters method' do
18
- finder_class = define_finder_class do
19
- entity_type { 'entity_type' }
20
- end
21
-
22
- expect(finder_class).to respond_to(:adapters)
23
- end
24
- end
25
-
26
- describe ActiveRecord do
27
- it 'can load ActiveRecord adapter' do
28
- expect do
29
- define_finder_class do
30
- entity_type { 'entity_type' }
31
- adapters ActiveRecord
32
- end
33
- end.not_to raise_error
34
- end
35
- end
36
-
37
- describe Sequel do
38
- it 'can load Sequel adapter' do
39
- expect do
40
- define_finder_class do
41
- entity_type { 'entity_type' }
42
- adapters Sequel
43
- end
44
- end.not_to raise_error
45
- end
46
- end
47
-
48
- describe DataMapper do
49
- it 'can load DataMapper adapter' do
50
- expect do
51
- define_finder_class do
52
- entity_type { 'entity_type' }
53
- adapters DataMapper
54
- end
55
- end.not_to raise_error
56
- end
57
- end
58
-
59
- describe Kaminari do
60
- it 'can load Kaminari adapter' do
61
- expect do
62
- define_finder_class do
63
- entity_type { 'entity_type' }
64
- adapters Kaminari
65
- end
66
- end.not_to raise_error
67
- end
68
- end
69
-
70
- describe WillPaginate do
71
- it 'can load WillPaginate adapter' do
72
- expect do
73
- define_finder_class do
74
- entity_type { 'entity_type' }
75
- adapters WillPaginate
76
- end
77
- end.not_to raise_error
78
- end
79
- end
80
- describe FriendlyId do
81
- it 'can load FriendlyId adapter' do
82
- expect do
83
- define_finder_class do
84
- entity_type { 'entity_type' }
85
- adapters FriendlyId
86
- end
87
- end.not_to raise_error
88
- end
89
- end
90
-
91
- it 'raises an error on non-existing adapter' do
92
- expect do
93
- define_finder_class do
94
- entity_type { 'entity_type' }
95
- adapters Unknown
96
- end
97
- end.to raise_error NameError
98
- end
99
-
100
- it 'can load multiple adapters' do
101
- expect do
102
- define_finder_class do
103
- entity_type { 'entity_type' }
104
- adapters ActiveRecord, Kaminari
105
- end
106
- end.not_to raise_error
107
- end
108
- end
109
- end
110
- end
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/paging_shared_example'
3
-
4
- module Trailblazer
5
- class Finder
6
- module Features
7
- describe Paging do
8
- it_behaves_like 'a paging feature'
9
-
10
- it 'uses a pre-defined Hash entity_type instead of any ORM' do
11
- true
12
- end
13
-
14
- def define_finder_class(&block)
15
- Class.new do
16
- include Trailblazer::Finder::Base
17
- include Trailblazer::Finder::Features::Paging
18
-
19
- instance_eval(&block) if block_given?
20
- end
21
- end
22
-
23
- def finder_class
24
- define_finder_class do
25
- entity_type do
26
- [
27
- {
28
- id: 1,
29
- name: 'product_1',
30
- price: '11',
31
- created_at: Time.now,
32
- updated_at: Time.now
33
- },
34
- {
35
- id: 2,
36
- name: 'product_2',
37
- price: '12',
38
- created_at: Time.now,
39
- updated_at: Time.now
40
- },
41
- {
42
- id: 3,
43
- name: 'product_3',
44
- price: '13',
45
- created_at: Time.now,
46
- updated_at: Time.now
47
- },
48
- {
49
- id: 4,
50
- name: 'product_4',
51
- price: '14',
52
- created_at: Time.now,
53
- updated_at: Time.now
54
- },
55
- {
56
- id: 5,
57
- name: 'product_5',
58
- price: '15',
59
- created_at: Time.now,
60
- updated_at: Time.now
61
- },
62
- {
63
- id: 6,
64
- name: 'product_6',
65
- price: '15',
66
- created_at: Time.now,
67
- updated_at: Time.now
68
- }
69
- ]
70
- end
71
-
72
- per_page 2
73
-
74
- min_per_page 2
75
- max_per_page 10
76
- end
77
- end
78
-
79
- def finder_with_page(page = nil, per_page = nil)
80
- finder_class.new page: page, per_page: per_page
81
- end
82
-
83
- it 'can be inherited' do
84
- child_class = Class.new(finder_class)
85
- expect(child_class.new.per_page).to eq 2
86
- end
87
-
88
- describe '#results' do
89
- it 'paginates results' do
90
- finder = finder_with_page 2, 2
91
- expect(finder.results.map { |n| n[:name] }).to eq %w[product_3 product_4]
92
- end
93
- end
94
-
95
- describe '#count' do
96
- it 'gives the real count' do
97
- finder = finder_with_page 1
98
- expect(finder.count).to eq 6
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end
@@ -1,99 +0,0 @@
1
- # require 'spec_helper_sequel'
2
- require 'spec_helper'
3
-
4
- module Trailblazer
5
- class Finder
6
- module Features
7
- describe Predicate do
8
- class TestFinder < Trailblazer::Finder
9
- features Predicate
10
-
11
- def create_product(id, name, price)
12
- {
13
- id: id,
14
- name: name,
15
- price: price,
16
- created_at: Time.now,
17
- updated_at: Time.now
18
- }
19
- end
20
-
21
- entity_type do
22
- Array.new(10) do |i|
23
- next create_product(i+1, "", "1#{i}".to_i)if i == 7
24
- next create_product(i+1, nil, "1#{i}".to_i) if i == 8
25
- next create_product(i+1, "product_4", "1#{i}".to_i) if i == 9
26
- create_product(i+1, "product_#{i}", "1#{i}".to_i)
27
- end
28
- end
29
-
30
- predicates_for :name, :price, :created_at
31
- end
32
-
33
- def finder_with_predicate(filter = nil, value = nil, filters = {})
34
- TestFinder.new filter: { filter => value }.merge(filters)
35
- end
36
-
37
- describe 'eqauls' do
38
- it 'it finds single row with name equal to product_5' do
39
- finder = finder_with_predicate 'name_eq', 'product_5'
40
- expect(finder.results.map { |n| n[:price] }).to eq [15]
41
- end
42
-
43
- it 'it finds multiple rows with name equal to product_4' do
44
- finder = finder_with_predicate 'name_eq', 'product_4'
45
- expect(finder.results.map { |n| n[:price] }).to eq [14, 19]
46
- end
47
-
48
- it 'it finds rows with name not equal to product_4' do
49
- finder = finder_with_predicate 'name_not_eq', 'product_4'
50
- expect(finder.results.map { |n| n[:name] }).to eq ["product_0", "product_1", "product_2", "product_3", "product_5", "product_6", ""]
51
- expect(finder.results.map { |n| n[:price] }).to eq [10, 11, 12, 13, 15, 16, 17]
52
- end
53
-
54
- it 'it finds multiple rows with name blank (empty/nil)' do
55
- finder = finder_with_predicate 'name_blank', ''
56
- expect(finder.results.map { |n| n[:price] }).to eq [17, 18]
57
- end
58
-
59
- it 'it finds multiple rows with name not blank (empty/nil)' do
60
- finder = finder_with_predicate 'name_not_blank', ''
61
- expect(finder.results.map { |n| n[:name] }).to eq ["product_0", "product_1", "product_2", "product_3", "product_4", "product_5", "product_6", "product_4"]
62
- end
63
-
64
- it 'it finds multiple rows with price less than 15' do
65
- finder = finder_with_predicate 'price_lt', 15
66
- expect(finder.results.map { |n| n[:name] }).to eq ["product_0", "product_1", "product_2", "product_3", "product_4"]
67
- expect(finder.results.map { |n| n[:price] }).to eq [10, 11, 12, 13, 14]
68
- end
69
-
70
- it 'it finds multiple rows with price equal to and less than 15' do
71
- finder = finder_with_predicate 'price_lte', 15
72
- expect(finder.results.map { |n| n[:name] }).to eq ["product_0", "product_1", "product_2", "product_3", "product_4", "product_5"]
73
- expect(finder.results.map { |n| n[:price] }).to eq [10, 11, 12, 13, 14, 15]
74
- end
75
-
76
- it 'it finds multiple rows with price greater than 15' do
77
- finder = finder_with_predicate 'price_gt', 15
78
- expect(finder.results.map { |n| n[:name] }).to eq ["product_6", "", nil, "product_4"]
79
- expect(finder.results.map { |n| n[:price] }).to eq [16, 17, 18, 19]
80
- end
81
-
82
- it 'it finds multiple rows with price equal to and greater than 15' do
83
- finder = finder_with_predicate 'price_gte', 15
84
- expect(finder.results.map { |n| n[:name] }).to eq ["product_5", "product_6", "", nil, "product_4"]
85
- expect(finder.results.map { |n| n[:price] }).to eq [15, 16, 17, 18, 19]
86
- end
87
-
88
- it 'it finds rows with name not equal to product_4 and name not blank and price greater than 14' do
89
- params = { name_not_blank: true, price_gt: 14 }
90
- finder = finder_with_predicate 'name_not_eq', 'product_4', params
91
-
92
- expect(finder.results.map { |n| n[:name] }).to eq ["product_5", "product_6"]
93
- expect(finder.results.map { |n| n[:price] }).to eq [15, 16]
94
- end
95
- end
96
- end
97
- end
98
- end
99
- end