pursuit 0.4.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubygem.yaml +46 -0
- data/Gemfile +14 -13
- data/Gemfile.lock +14 -13
- data/README.md +210 -27
- data/bin/console +10 -0
- data/lib/pursuit/aggregate_modifier_not_found.rb +20 -0
- data/lib/pursuit/aggregate_modifier_required.rb +20 -0
- data/lib/pursuit/aggregate_modifiers_not_available.rb +13 -0
- data/lib/pursuit/attribute_not_found.rb +20 -0
- data/lib/pursuit/constants.rb +1 -1
- data/lib/pursuit/error.rb +7 -0
- data/lib/pursuit/predicate_parser.rb +181 -0
- data/lib/pursuit/predicate_search.rb +86 -0
- data/lib/pursuit/predicate_transform.rb +231 -0
- data/lib/pursuit/query_error.rb +7 -0
- data/lib/pursuit/simple_search.rb +66 -0
- data/lib/pursuit/term_parser.rb +44 -0
- data/lib/pursuit/term_search.rb +74 -0
- data/lib/pursuit/term_transform.rb +35 -0
- data/lib/pursuit.rb +18 -4
- data/pursuit.gemspec +4 -3
- data/spec/internal/app/models/application_record.rb +5 -0
- data/spec/internal/app/models/product.rb +3 -14
- data/spec/internal/app/models/product_category.rb +3 -1
- data/spec/internal/app/models/product_variation.rb +3 -1
- data/spec/internal/app/searches/product_category_search.rb +50 -0
- data/spec/internal/app/searches/product_search.rb +53 -0
- data/spec/internal/app/searches/product_variation_search.rb +53 -0
- data/spec/lib/pursuit/predicate_parser_spec.rb +1604 -0
- data/spec/lib/pursuit/predicate_search_spec.rb +116 -0
- data/spec/lib/pursuit/predicate_transform_spec.rb +624 -0
- data/spec/lib/pursuit/simple_search_spec.rb +73 -0
- data/spec/lib/pursuit/term_parser_spec.rb +271 -0
- data/spec/lib/pursuit/term_search_spec.rb +85 -0
- data/spec/lib/pursuit/term_transform_spec.rb +105 -0
- metadata +50 -25
- data/.travis.yml +0 -26
- data/lib/pursuit/dsl.rb +0 -28
- data/lib/pursuit/railtie.rb +0 -13
- data/lib/pursuit/search.rb +0 -172
- data/lib/pursuit/search_options.rb +0 -86
- data/lib/pursuit/search_term_parser.rb +0 -46
- data/spec/lib/pursuit/dsl_spec.rb +0 -22
- data/spec/lib/pursuit/search_options_spec.rb +0 -146
- data/spec/lib/pursuit/search_spec.rb +0 -516
- data/spec/lib/pursuit/search_term_parser_spec.rb +0 -34
- data/travis/gemfiles/5.2.gemfile +0 -8
- data/travis/gemfiles/6.0.gemfile +0 -8
- data/travis/gemfiles/6.1.gemfile +0 -8
- data/travis/gemfiles/7.0.gemfile +0 -8
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Pursuit::PredicateSearch do
|
4
|
+
subject(:predicate_search) do
|
5
|
+
described_class.new(default_table: Product.arel_table, permit_aggregate_modifiers: true)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'is expected to set #default_table eq `default_table`' do
|
10
|
+
expect(predicate_search).to have_attributes(default_table: Product.arel_table)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is expected to set #permit_aggregate_modifiers eq `permit_aggregate_modifiers`' do
|
14
|
+
expect(predicate_search).to have_attributes(permit_aggregate_modifiers: true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is expected to invoke the passed block' do
|
18
|
+
expect { |block| described_class.new(&block) }.to yield_control
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#permit_attribute' do
|
23
|
+
subject(:permit_attribute) { predicate_search.permit_attribute(name, attribute) }
|
24
|
+
|
25
|
+
context 'when `attribute` is nil' do
|
26
|
+
let(:name) { :title }
|
27
|
+
let(:attribute) { nil }
|
28
|
+
|
29
|
+
it 'is expected to add the attribute from #default_table to #permitted_attributes' do
|
30
|
+
permit_attribute
|
31
|
+
expect(predicate_search.permitted_attributes).to match(
|
32
|
+
hash_including(
|
33
|
+
title: Product.arel_table[:title]
|
34
|
+
)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when `attribute` is a Symbol' do
|
40
|
+
let(:name) { :name }
|
41
|
+
let(:attribute) { :title }
|
42
|
+
|
43
|
+
it 'is expected to add the attribute from #default_table to #permitted_attributes' do
|
44
|
+
permit_attribute
|
45
|
+
expect(predicate_search.permitted_attributes).to match(
|
46
|
+
hash_including(
|
47
|
+
name: Product.arel_table[:title]
|
48
|
+
)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when `attribute` is an Arel::Attributes::Attribute' do
|
54
|
+
let(:name) { :variation_currency }
|
55
|
+
let(:attribute) { ProductVariation.arel_table[:currency] }
|
56
|
+
|
57
|
+
it 'is expected to add the attribute to #permitted_attributes' do
|
58
|
+
permit_attribute
|
59
|
+
expect(predicate_search.permitted_attributes).to match(
|
60
|
+
hash_including(
|
61
|
+
variation_currency: ProductVariation.arel_table[:currency]
|
62
|
+
)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#parser' do
|
69
|
+
subject(:parser) { predicate_search.parser }
|
70
|
+
|
71
|
+
it { is_expected.to be_a(Pursuit::PredicateParser) }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#transform' do
|
75
|
+
subject(:transform) { predicate_search.transform }
|
76
|
+
|
77
|
+
it { is_expected.to be_a(Pursuit::PredicateTransform) }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#parse' do
|
81
|
+
subject(:parse) { predicate_search.parse('title ~ Shirt & #variation > 0') }
|
82
|
+
|
83
|
+
before do
|
84
|
+
predicate_search.permitted_attributes[:title] = Product.arel_table[:title]
|
85
|
+
predicate_search.permitted_attributes[:variation] = ProductVariation.arel_table[:id]
|
86
|
+
predicate_search.permitted_attributes[:variation_title] = ProductVariation.arel_table[:title]
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'is expected to equal a Hash containing the ARel nodes' do
|
90
|
+
expect(parse).to eq(
|
91
|
+
{
|
92
|
+
where: Product.arel_table[:title].matches('%Shirt%'),
|
93
|
+
having: ProductVariation.arel_table[:id].count.gt(0)
|
94
|
+
}
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#apply' do
|
100
|
+
subject(:apply) { predicate_search.apply('title ~ Shirt', Product.left_outer_joins(:variations).group(:id)) }
|
101
|
+
|
102
|
+
before do
|
103
|
+
predicate_search.permitted_attributes[:title] = Product.arel_table[:title]
|
104
|
+
predicate_search.permitted_attributes[:variation] = ProductVariation.arel_table[:id]
|
105
|
+
predicate_search.permitted_attributes[:variation_title] = ProductVariation.arel_table[:title]
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'is expected to equal `relation` with predicate clauses applied' do
|
109
|
+
expect(apply).to eq(
|
110
|
+
Product.left_outer_joins(:variations).group(:id).where(
|
111
|
+
Product.arel_table[:title].matches('%Shirt%')
|
112
|
+
)
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|