chewy 0.10.1 → 7.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- data/.github/workflows/ruby.yml +74 -0
- data/.rubocop.yml +28 -23
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +480 -298
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +3 -5
- data/Guardfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +571 -333
- data/chewy.gemspec +12 -15
- data/gemfiles/rails.5.2.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
- data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
- data/lib/chewy/config.rb +48 -77
- data/lib/chewy/errors.rb +4 -10
- data/lib/chewy/fields/base.rb +88 -16
- data/lib/chewy/fields/root.rb +15 -21
- data/lib/chewy/index/actions.rb +67 -38
- data/lib/chewy/{type → index}/adapter/active_record.rb +18 -4
- data/lib/chewy/{type → index}/adapter/base.rb +11 -12
- data/lib/chewy/{type → index}/adapter/object.rb +28 -32
- data/lib/chewy/{type → index}/adapter/orm.rb +26 -24
- data/lib/chewy/index/aliases.rb +14 -5
- data/lib/chewy/index/crutch.rb +40 -0
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/{type → index}/import/bulk_request.rb +10 -9
- data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
- data/lib/chewy/{type → index}/import/routine.rb +19 -18
- data/lib/chewy/{type → index}/import.rb +82 -36
- data/lib/chewy/{type → index}/mapping.rb +63 -62
- data/lib/chewy/index/observe/active_record_methods.rb +87 -0
- data/lib/chewy/index/observe/callback.rb +34 -0
- data/lib/chewy/index/observe.rb +17 -0
- data/lib/chewy/index/settings.rb +2 -0
- data/lib/chewy/index/specification.rb +13 -10
- data/lib/chewy/{type → index}/syncer.rb +62 -63
- data/lib/chewy/{type → index}/witchcraft.rb +15 -9
- data/lib/chewy/{type → index}/wrapper.rb +16 -6
- data/lib/chewy/index.rb +68 -93
- data/lib/chewy/journal.rb +25 -14
- data/lib/chewy/minitest/helpers.rb +91 -18
- data/lib/chewy/minitest/search_index_receiver.rb +29 -33
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +8 -24
- data/lib/chewy/rake_helper.rb +141 -112
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +58 -49
- data/lib/chewy/rspec.rb +2 -0
- data/lib/chewy/runtime.rb +1 -1
- data/lib/chewy/search/loader.rb +19 -41
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/collapse.rb +16 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +6 -5
- data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/indices.rb +78 -0
- data/lib/chewy/search/parameters/none.rb +1 -3
- data/lib/chewy/search/parameters/order.rb +6 -19
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
- data/lib/chewy/search/parameters.rb +28 -8
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +207 -157
- data/lib/chewy/search/response.rb +5 -5
- data/lib/chewy/search/scoping.rb +7 -8
- data/lib/chewy/search/scrolling.rb +14 -13
- data/lib/chewy/search.rb +7 -26
- data/lib/chewy/stash.rb +27 -29
- data/lib/chewy/strategy/active_job.rb +2 -2
- data/lib/chewy/strategy/atomic.rb +1 -1
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +10 -0
- data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +148 -0
- data/lib/chewy/strategy/delayed_sidekiq/worker.rb +52 -0
- data/lib/chewy/strategy/delayed_sidekiq.rb +17 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +3 -2
- data/lib/chewy/strategy.rb +6 -19
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +37 -80
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +26 -32
- data/migration_guide.md +56 -0
- data/spec/chewy/config_spec.rb +27 -57
- data/spec/chewy/fields/base_spec.rb +457 -174
- data/spec/chewy/fields/root_spec.rb +24 -32
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +425 -60
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +110 -44
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/index/aliases_spec.rb +3 -3
- data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -12
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +22 -30
- data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
- data/spec/chewy/{type → index}/import_spec.rb +154 -95
- data/spec/chewy/index/mapping_spec.rb +135 -0
- data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
- data/spec/chewy/index/observe/callback_spec.rb +139 -0
- data/spec/chewy/index/observe_spec.rb +143 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +32 -33
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +34 -21
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +99 -114
- data/spec/chewy/journal_spec.rb +56 -101
- data/spec/chewy/minitest/helpers_spec.rb +122 -14
- data/spec/chewy/minitest/search_index_receiver_spec.rb +24 -26
- data/spec/chewy/multi_search_spec.rb +84 -0
- data/spec/chewy/rake_helper_spec.rb +325 -101
- data/spec/chewy/rspec/build_query_spec.rb +34 -0
- data/spec/chewy/rspec/helpers_spec.rb +61 -0
- data/spec/chewy/rspec/update_index_spec.rb +106 -102
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +19 -53
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
- data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
- data/spec/chewy/search/parameters/indices_spec.rb +99 -0
- data/spec/chewy/search/parameters/none_spec.rb +1 -1
- data/spec/chewy/search/parameters/order_spec.rb +18 -11
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +39 -8
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +360 -149
- data/spec/chewy/search/response_spec.rb +35 -25
- data/spec/chewy/search/scrolling_spec.rb +28 -26
- data/spec/chewy/search_spec.rb +73 -53
- data/spec/chewy/stash_spec.rb +16 -26
- data/spec/chewy/strategy/active_job_spec.rb +23 -10
- data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/delayed_sidekiq_spec.rb +190 -0
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +14 -10
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +17 -110
- data/spec/spec_helper.rb +7 -22
- data/spec/support/active_record.rb +43 -5
- metadata +123 -198
- data/.travis.yml +0 -53
- data/Appraisals +0 -79
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.0.activerecord.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.gemfile +0 -15
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.0.mongoid.6.0.gemfile +0 -15
- data/gemfiles/rails.5.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.1.mongoid.6.1.gemfile +0 -15
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/backports/deep_dup.rb +0 -46
- data/lib/chewy/backports/duplicable.rb +0 -91
- data/lib/chewy/query/compose.rb +0 -68
- data/lib/chewy/query/criteria.rb +0 -191
- data/lib/chewy/query/filters.rb +0 -227
- data/lib/chewy/query/loading.rb +0 -111
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -34
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -110
- data/lib/chewy/query/nodes/has_child.rb +0 -15
- data/lib/chewy/query/nodes/has_parent.rb +0 -15
- data/lib/chewy/query/nodes/has_relation.rb +0 -59
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -19
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -35
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination.rb +0 -25
- data/lib/chewy/query.rb +0 -1098
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/search/parameters/types.rb +0 -20
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -69
- data/lib/chewy/type/adapter/sequel.rb +0 -95
- data/lib/chewy/type/crutch.rb +0 -32
- data/lib/chewy/type/import/bulk_builder.rb +0 -122
- data/lib/chewy/type/observe.rb +0 -78
- data/lib/chewy/type.rb +0 -117
- data/lib/sequel/plugins/chewy_observe.rb +0 -78
- data/spec/chewy/query/criteria_spec.rb +0 -700
- data/spec/chewy/query/filters_spec.rb +0 -201
- data/spec/chewy/query/loading_spec.rb +0 -124
- data/spec/chewy/query/nodes/and_spec.rb +0 -12
- data/spec/chewy/query/nodes/bool_spec.rb +0 -14
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -16
- data/spec/chewy/query/nodes/not_spec.rb +0 -13
- data/spec/chewy/query/nodes/or_spec.rb +0 -12
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
- data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
- data/spec/chewy/query/pagination_spec.rb +0 -39
- data/spec/chewy/query_spec.rb +0 -636
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
- data/spec/chewy/search/parameters/types_spec.rb +0 -5
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -64
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/import/bulk_builder_spec.rb +0 -279
- data/spec/chewy/type/mapping_spec.rb +0 -142
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -98
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Search::Parameters::IgnoreUnavailable do
|
4
|
+
subject { described_class.new(true) }
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
specify { expect(subject.value).to eq(true) }
|
8
|
+
specify { expect(described_class.new.value).to eq(nil) }
|
9
|
+
specify { expect(described_class.new(42).value).to eq(true) }
|
10
|
+
specify { expect(described_class.new(false).value).to eq(false) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#replace!' do
|
14
|
+
specify { expect { subject.replace!(false) }.to change { subject.value }.from(true).to(false) }
|
15
|
+
specify { expect { subject.replace!(nil) }.to change { subject.value }.from(true).to(nil) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#update!' do
|
19
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(true) }
|
20
|
+
specify { expect { subject.update!(false) }.to change { subject.value }.from(true).to(false) }
|
21
|
+
specify { expect { subject.update!(true) }.not_to change { subject.value }.from(true) }
|
22
|
+
|
23
|
+
context do
|
24
|
+
subject { described_class.new(false) }
|
25
|
+
|
26
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(false) }
|
27
|
+
specify { expect { subject.update!(false) }.not_to change { subject.value }.from(false) }
|
28
|
+
specify { expect { subject.update!(true) }.to change { subject.value }.from(false).to(true) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context do
|
32
|
+
subject { described_class.new }
|
33
|
+
|
34
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(nil) }
|
35
|
+
specify { expect { subject.update!(false) }.to change { subject.value }.from(nil).to(false) }
|
36
|
+
specify { expect { subject.update!(true) }.to change { subject.value }.from(nil).to(true) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#merge!' do
|
41
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(true) }
|
42
|
+
specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(true).to(false) }
|
43
|
+
specify { expect { subject.merge!(described_class.new(true)) }.not_to change { subject.value }.from(true) }
|
44
|
+
|
45
|
+
context do
|
46
|
+
subject { described_class.new(false) }
|
47
|
+
|
48
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(false) }
|
49
|
+
specify { expect { subject.merge!(described_class.new(false)) }.not_to change { subject.value }.from(false) }
|
50
|
+
specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(false).to(true) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context do
|
54
|
+
subject { described_class.new }
|
55
|
+
|
56
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(nil) }
|
57
|
+
specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(nil).to(false) }
|
58
|
+
specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(nil).to(true) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#render' do
|
63
|
+
specify { expect(described_class.new.render).to be_nil }
|
64
|
+
specify { expect(described_class.new(false).render).to eq(ignore_unavailable: false) }
|
65
|
+
specify { expect(subject.render).to eq(ignore_unavailable: true) }
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Search::Parameters::Indices do
|
4
|
+
before do
|
5
|
+
stub_index(:first)
|
6
|
+
stub_index(:second)
|
7
|
+
stub_index(:third)
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { described_class.new(indices: [FirstIndex, SecondIndex]) }
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
specify { expect(described_class.new.value).to eq(indices: []) }
|
14
|
+
specify { expect(described_class.new(nil).value).to eq(indices: []) }
|
15
|
+
specify { expect(described_class.new(foo: :whatever).value).to eq(indices: []) }
|
16
|
+
specify { expect(subject.value).to eq(indices: [FirstIndex, SecondIndex]) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#replace!' do
|
20
|
+
specify do
|
21
|
+
expect { subject.replace!(nil) }
|
22
|
+
.to change { subject.value }
|
23
|
+
.from(indices: [FirstIndex, SecondIndex])
|
24
|
+
.to(indices: [])
|
25
|
+
end
|
26
|
+
|
27
|
+
specify do
|
28
|
+
expect { subject.replace!(indices: SecondIndex) }
|
29
|
+
.to change { subject.value }
|
30
|
+
.from(indices: [FirstIndex, SecondIndex])
|
31
|
+
.to(indices: [SecondIndex])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#update!' do
|
36
|
+
specify do
|
37
|
+
expect { subject.update!(nil) }
|
38
|
+
.not_to change { subject.value }
|
39
|
+
end
|
40
|
+
|
41
|
+
specify do
|
42
|
+
expect { subject.update!(indices: ThirdIndex) }
|
43
|
+
.to change { subject.value }
|
44
|
+
.from(indices: [FirstIndex, SecondIndex])
|
45
|
+
.to(indices: [FirstIndex, SecondIndex, ThirdIndex])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#merge!' do
|
50
|
+
specify do
|
51
|
+
expect { subject.merge!(described_class.new) }
|
52
|
+
.not_to change { subject.value }
|
53
|
+
end
|
54
|
+
|
55
|
+
specify do
|
56
|
+
expect { subject.merge!(described_class.new(indices: SecondIndex)) }
|
57
|
+
.not_to change { subject.value }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#render' do
|
62
|
+
specify { expect(described_class.new.render).to eq({}) }
|
63
|
+
specify do
|
64
|
+
expect(described_class.new(
|
65
|
+
indices: FirstIndex
|
66
|
+
).render).to eq(index: %w[first])
|
67
|
+
end
|
68
|
+
specify do
|
69
|
+
expect(described_class.new(
|
70
|
+
indices: :whatever
|
71
|
+
).render).to eq(index: %w[whatever])
|
72
|
+
end
|
73
|
+
specify do
|
74
|
+
expect(described_class.new(
|
75
|
+
indices: [FirstIndex, :whatever]
|
76
|
+
).render).to eq(index: %w[first whatever])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#==' do
|
81
|
+
specify { expect(described_class.new).to eq(described_class.new) }
|
82
|
+
specify do
|
83
|
+
expect(described_class.new(indices: :first))
|
84
|
+
.to eq(described_class.new(indices: FirstIndex))
|
85
|
+
end
|
86
|
+
specify do
|
87
|
+
expect(described_class.new(indices: FirstIndex))
|
88
|
+
.to eq(described_class.new(indices: FirstIndex))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#indices' do
|
93
|
+
specify do
|
94
|
+
expect(described_class.new(
|
95
|
+
indices: [FirstIndex, :whatever]
|
96
|
+
).indices).to contain_exactly(FirstIndex)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -4,26 +4,29 @@ describe Chewy::Search::Parameters::Order do
|
|
4
4
|
subject { described_class.new(%i[foo bar]) }
|
5
5
|
|
6
6
|
describe '#initialize' do
|
7
|
-
specify { expect(described_class.new.value).to eq(
|
8
|
-
specify { expect(described_class.new(nil).value).to eq(
|
9
|
-
specify { expect(described_class.new('').value).to eq(
|
10
|
-
specify { expect(described_class.new(42).value).to eq('42'
|
11
|
-
specify { expect(described_class.new([42, 43]).value).to eq(
|
12
|
-
specify { expect(described_class.new(
|
13
|
-
specify { expect(described_class.new([
|
7
|
+
specify { expect(described_class.new.value).to eq([]) }
|
8
|
+
specify { expect(described_class.new(nil).value).to eq([]) }
|
9
|
+
specify { expect(described_class.new('').value).to eq([]) }
|
10
|
+
specify { expect(described_class.new(42).value).to eq(['42']) }
|
11
|
+
specify { expect(described_class.new([42, 43]).value).to eq(%w[42 43]) }
|
12
|
+
specify { expect(described_class.new([42, 42]).value).to eq(%w[42 42]) }
|
13
|
+
specify { expect(described_class.new([42, [43, 44]]).value).to eq(%w[42 43 44]) }
|
14
|
+
specify { expect(described_class.new(a: 1).value).to eq([{'a' => 1}]) }
|
15
|
+
specify { expect(described_class.new(['a', {a: 1}, {a: 2}]).value).to eq(['a', {'a' => 1}, {'a' => 2}]) }
|
16
|
+
specify { expect(described_class.new(['', 43, {a: 1}]).value).to eq(['43', {'a' => 1}]) }
|
14
17
|
end
|
15
18
|
|
16
19
|
describe '#replace!' do
|
17
20
|
specify do
|
18
21
|
expect { subject.replace!(foo: {}) }
|
19
22
|
.to change { subject.value }
|
20
|
-
.from(
|
23
|
+
.from(%w[foo bar]).to([{'foo' => {}}])
|
21
24
|
end
|
22
25
|
|
23
26
|
specify do
|
24
27
|
expect { subject.replace!(nil) }
|
25
28
|
.to change { subject.value }
|
26
|
-
.from(
|
29
|
+
.from(%w[foo bar]).to([])
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
@@ -31,7 +34,7 @@ describe Chewy::Search::Parameters::Order do
|
|
31
34
|
specify do
|
32
35
|
expect { subject.update!(foo: {}) }
|
33
36
|
.to change { subject.value }
|
34
|
-
.from(
|
37
|
+
.from(%w[foo bar]).to(['foo', 'bar', {'foo' => {}}])
|
35
38
|
end
|
36
39
|
|
37
40
|
specify { expect { subject.update!(nil) }.not_to change { subject.value } }
|
@@ -41,7 +44,7 @@ describe Chewy::Search::Parameters::Order do
|
|
41
44
|
specify do
|
42
45
|
expect { subject.merge!(described_class.new(foo: {})) }
|
43
46
|
.to change { subject.value }
|
44
|
-
.from(
|
47
|
+
.from(%w[foo bar]).to(['foo', 'bar', {'foo' => {}}])
|
45
48
|
end
|
46
49
|
|
47
50
|
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value } }
|
@@ -51,6 +54,7 @@ describe Chewy::Search::Parameters::Order do
|
|
51
54
|
specify { expect(described_class.new.render).to be_nil }
|
52
55
|
specify { expect(described_class.new(:foo).render).to eq(sort: ['foo']) }
|
53
56
|
specify { expect(described_class.new([:foo, {bar: 42}, :baz]).render).to eq(sort: ['foo', {'bar' => 42}, 'baz']) }
|
57
|
+
specify { expect(described_class.new([:foo, {bar: 42}, {bar: 43}, :baz]).render).to eq(sort: ['foo', {'bar' => 42}, {'bar' => 43}, 'baz']) }
|
54
58
|
end
|
55
59
|
|
56
60
|
describe '#==' do
|
@@ -59,7 +63,10 @@ describe Chewy::Search::Parameters::Order do
|
|
59
63
|
specify { expect(described_class.new(:foo)).not_to eq(described_class.new(:bar)) }
|
60
64
|
specify { expect(described_class.new(%i[foo bar])).to eq(described_class.new(%i[foo bar])) }
|
61
65
|
specify { expect(described_class.new(%i[foo bar])).not_to eq(described_class.new(%i[bar foo])) }
|
66
|
+
specify { expect(described_class.new(%i[foo foo])).not_to eq(described_class.new(%i[foo])) }
|
62
67
|
specify { expect(described_class.new(foo: {a: 42})).to eq(described_class.new(foo: {a: 42})) }
|
63
68
|
specify { expect(described_class.new(foo: {a: 42})).not_to eq(described_class.new(foo: {b: 42})) }
|
69
|
+
specify { expect(described_class.new(['foo', {'foo' => 42}])).not_to eq(described_class.new([{'foo' => 42}, 'foo'])) }
|
70
|
+
specify { expect(described_class.new([{'foo' => 42}, {'foo' => 43}])).not_to eq(described_class.new([{'foo' => 43}, {'foo' => 42}])) }
|
64
71
|
end
|
65
72
|
end
|
@@ -4,19 +4,46 @@ shared_examples :query_storage do |param_name|
|
|
4
4
|
subject { described_class.new(must: {foo: 'bar'}, should: {moo: 'baz'}) }
|
5
5
|
|
6
6
|
describe '#initialize' do
|
7
|
-
specify
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
specify do
|
8
|
+
expect(described_class.new.value.to_h)
|
9
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
|
10
|
+
end
|
11
|
+
specify do
|
12
|
+
expect(described_class.new(nil).value.to_h)
|
13
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
|
14
|
+
end
|
15
|
+
specify do
|
16
|
+
expect(described_class.new(foobar: {}).value.to_h)
|
17
|
+
.to eq(must: [{foobar: {}}], should: [], must_not: [], minimum_should_match: nil)
|
18
|
+
end
|
19
|
+
specify do
|
20
|
+
expect(described_class.new(must: {}, should: {}, must_not: {}).value.to_h)
|
21
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
|
22
|
+
end
|
11
23
|
specify do
|
12
24
|
expect(described_class.new(must: {foo: 'bar'}, should: {foo: 'bar'}, foobar: {}).value.to_h)
|
13
25
|
.to eq(must: [{foo: 'bar'}], should: [{foo: 'bar'}], must_not: [], minimum_should_match: nil)
|
14
26
|
end
|
15
|
-
specify
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
specify
|
27
|
+
specify do
|
28
|
+
expect(subject.value.to_h)
|
29
|
+
.to eq(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
30
|
+
end
|
31
|
+
specify do
|
32
|
+
expect(described_class.new(proc { match foo: 'bar' }).value.to_h)
|
33
|
+
.to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil)
|
34
|
+
end
|
35
|
+
specify do
|
36
|
+
expect(described_class.new(must: proc { match foo: 'bar' }).value.to_h)
|
37
|
+
.to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil)
|
38
|
+
end
|
39
|
+
specify do
|
40
|
+
expect(described_class.new(minimum_should_match: 3).value.to_h)
|
41
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: 3)
|
42
|
+
end
|
43
|
+
specify do
|
44
|
+
expect(described_class.new(must: {foo: 'bar'}, minimum_should_match: 3).value.to_h)
|
45
|
+
.to eq(must: [{foo: 'bar'}], should: [], must_not: [], minimum_should_match: 3)
|
46
|
+
end
|
20
47
|
specify do
|
21
48
|
expect(described_class.new(must: [proc { match foo: 'bar' }, {moo: 'baz'}]).value.to_h)
|
22
49
|
.to eq(must: [{match: {foo: 'bar'}}, {moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
|
@@ -73,14 +100,16 @@ shared_examples :query_storage do |param_name|
|
|
73
100
|
expect { subject.and(moo: 'baz') }
|
74
101
|
.to change { subject.value.to_h }
|
75
102
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
76
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
103
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
104
|
+
{moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
|
77
105
|
end
|
78
106
|
|
79
107
|
specify do
|
80
108
|
expect { subject.and([{moo: 'baz'}, {doo: 'scooby'}]) }
|
81
109
|
.to change { subject.value.to_h }
|
82
110
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
83
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
111
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
112
|
+
bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], should: [], must_not: [], minimum_should_match: nil)
|
84
113
|
end
|
85
114
|
|
86
115
|
specify do
|
@@ -93,7 +122,8 @@ shared_examples :query_storage do |param_name|
|
|
93
122
|
expect { subject.and(should: {foo: 'bar'}) }
|
94
123
|
.to change { subject.value.to_h }
|
95
124
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
96
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
125
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
126
|
+
{bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
|
97
127
|
end
|
98
128
|
|
99
129
|
context do
|
@@ -113,14 +143,16 @@ shared_examples :query_storage do |param_name|
|
|
113
143
|
expect { subject.or(moo: 'baz') }
|
114
144
|
.to change { subject.value.to_h }
|
115
145
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
116
|
-
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
146
|
+
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
147
|
+
{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
117
148
|
end
|
118
149
|
|
119
150
|
specify do
|
120
151
|
expect { subject.or([{moo: 'baz'}, {doo: 'scooby'}]) }
|
121
152
|
.to change { subject.value.to_h }
|
122
153
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
123
|
-
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
154
|
+
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
155
|
+
bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], must_not: [], minimum_should_match: nil)
|
124
156
|
end
|
125
157
|
|
126
158
|
specify do
|
@@ -133,7 +165,8 @@ shared_examples :query_storage do |param_name|
|
|
133
165
|
expect { subject.or(should: {foo: 'bar'}) }
|
134
166
|
.to change { subject.value.to_h }
|
135
167
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
136
|
-
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
168
|
+
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
169
|
+
{bool: {should: {foo: 'bar'}}}], must_not: [], minimum_should_match: nil)
|
137
170
|
end
|
138
171
|
|
139
172
|
context do
|
@@ -160,7 +193,12 @@ shared_examples :query_storage do |param_name|
|
|
160
193
|
expect { subject.not([{moo: 'baz'}, {doo: 'scooby'}]) }
|
161
194
|
.to change { subject.value.to_h }
|
162
195
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
163
|
-
.to(
|
196
|
+
.to(
|
197
|
+
must: [{foo: 'bar'}],
|
198
|
+
should: [{moo: 'baz'}],
|
199
|
+
must_not: [{bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}}],
|
200
|
+
minimum_should_match: nil
|
201
|
+
)
|
164
202
|
end
|
165
203
|
|
166
204
|
specify do
|
@@ -173,7 +211,11 @@ shared_examples :query_storage do |param_name|
|
|
173
211
|
expect { subject.not(should: {foo: 'bar'}) }
|
174
212
|
.to change { subject.value.to_h }
|
175
213
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
176
|
-
.to(
|
214
|
+
.to(
|
215
|
+
must: [{foo: 'bar'}], should: [{moo: 'baz'}],
|
216
|
+
must_not: [{bool: {should: {foo: 'bar'}}}],
|
217
|
+
minimum_should_match: nil
|
218
|
+
)
|
177
219
|
end
|
178
220
|
|
179
221
|
context do
|
@@ -223,7 +265,8 @@ shared_examples :query_storage do |param_name|
|
|
223
265
|
expect { subject.update!(must: proc { match foo: 'bar' }) }
|
224
266
|
.to change { subject.value.to_h }
|
225
267
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
226
|
-
.to(must: [{foo: 'bar'},
|
268
|
+
.to(must: [{foo: 'bar'},
|
269
|
+
{match: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
227
270
|
end
|
228
271
|
|
229
272
|
specify do
|
@@ -237,7 +280,8 @@ shared_examples :query_storage do |param_name|
|
|
237
280
|
expect { subject.update!(foobar: {foo: 'bar'}) }
|
238
281
|
.to change { subject.value.to_h }
|
239
282
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
240
|
-
.to(must: [{foo: 'bar'},
|
283
|
+
.to(must: [{foo: 'bar'},
|
284
|
+
{foobar: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
241
285
|
end
|
242
286
|
|
243
287
|
specify do
|
@@ -279,7 +323,8 @@ shared_examples :query_storage do |param_name|
|
|
279
323
|
expect { subject.merge!(described_class.new(moo: 'baz')) }
|
280
324
|
.to change { subject.value.to_h }
|
281
325
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
282
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
326
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
327
|
+
{moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
|
283
328
|
end
|
284
329
|
|
285
330
|
specify do
|
@@ -292,7 +337,8 @@ shared_examples :query_storage do |param_name|
|
|
292
337
|
expect { subject.merge!(described_class.new(should: {foo: 'bar'})) }
|
293
338
|
.to change { subject.value.to_h }
|
294
339
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
295
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
340
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
341
|
+
{bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
|
296
342
|
end
|
297
343
|
|
298
344
|
context do
|
@@ -20,7 +20,10 @@ describe Chewy::Search::Parameters::SearchAfter do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#merge!' do
|
23
|
-
specify
|
23
|
+
specify do
|
24
|
+
expect { subject.merge!(described_class.new(:baz)) }
|
25
|
+
.to change { subject.value }.from([:foo, 42]).to([:baz])
|
26
|
+
end
|
24
27
|
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from([:foo, 42]) }
|
25
28
|
end
|
26
29
|
|
@@ -12,8 +12,14 @@ describe Chewy::Search::Parameters::Source do
|
|
12
12
|
specify { expect(described_class.new(true).value).to eq(includes: [], excludes: [], enabled: true) }
|
13
13
|
specify { expect(described_class.new(a: 1).value).to eq(includes: [], excludes: [], enabled: true) }
|
14
14
|
specify { expect(described_class.new(includes: :foo).value).to eq(includes: %w[foo], excludes: [], enabled: true) }
|
15
|
-
specify
|
16
|
-
|
15
|
+
specify do
|
16
|
+
expect(described_class.new(includes: :foo, excludes: 42).value)
|
17
|
+
.to eq(includes: %w[foo], excludes: %w[42], enabled: true)
|
18
|
+
end
|
19
|
+
specify do
|
20
|
+
expect(described_class.new(includes: :foo, excludes: 42, enabled: false).value)
|
21
|
+
.to eq(includes: %w[foo], excludes: %w[42], enabled: true)
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
describe '#replace!' do
|
@@ -13,7 +13,7 @@ describe Chewy::Search::Parameters do
|
|
13
13
|
|
14
14
|
specify { expect(subject.storages[:limit]).to equal(limit) }
|
15
15
|
specify { expect(subject.storages[:limit].value).to eq(3) }
|
16
|
-
specify { expect(subject.storages[:order].value).to eq('foo'
|
16
|
+
specify { expect(subject.storages[:order].value).to eq(['foo']) }
|
17
17
|
|
18
18
|
specify { expect { described_class.new(offset: limit) }.to raise_error(TypeError) }
|
19
19
|
end
|
@@ -55,7 +55,10 @@ describe Chewy::Search::Parameters do
|
|
55
55
|
subject { described_class.new(limit: 10, offset: 20, order: :foo) }
|
56
56
|
|
57
57
|
specify { expect { subject.only!([:limit]) }.to change { subject.clone }.to(described_class.new(limit: 10)) }
|
58
|
-
specify
|
58
|
+
specify do
|
59
|
+
expect { subject.only!(%i[offset order]) }
|
60
|
+
.to change { subject.clone }.to(described_class.new(offset: 20, order: :foo))
|
61
|
+
end
|
59
62
|
specify { expect { subject.only!(%i[limit something]) }.to raise_error NameError }
|
60
63
|
specify { expect { subject.only!([]) }.to raise_error ArgumentError }
|
61
64
|
end
|
@@ -63,8 +66,14 @@ describe Chewy::Search::Parameters do
|
|
63
66
|
describe '#except!' do
|
64
67
|
subject { described_class.new(limit: 10, offset: 20, order: :foo) }
|
65
68
|
|
66
|
-
specify
|
67
|
-
|
69
|
+
specify do
|
70
|
+
expect { subject.except!([:limit]) }
|
71
|
+
.to change { subject.clone }.to(described_class.new(offset: 20, order: :foo))
|
72
|
+
end
|
73
|
+
specify do
|
74
|
+
expect { subject.except!(%i[offset order]) }
|
75
|
+
.to change { subject.clone }.to(described_class.new(limit: 10))
|
76
|
+
end
|
68
77
|
specify { expect { subject.except!(%i[limit something]) }.to raise_error NameError }
|
69
78
|
specify { expect { subject.except!([]) }.to raise_error ArgumentError }
|
70
79
|
end
|
@@ -72,18 +81,20 @@ describe Chewy::Search::Parameters do
|
|
72
81
|
describe '#merge!' do
|
73
82
|
let(:first) { described_class.new(offset: 10, order: 'foo') }
|
74
83
|
let(:second) { described_class.new(limit: 20, offset: 20, order: 'bar') }
|
84
|
+
let(:first_clone) { first.clone }
|
85
|
+
let(:second_clone) { second.clone }
|
75
86
|
|
76
87
|
specify do
|
77
88
|
expect { first.merge!(second) }.to change { first.clone }
|
78
89
|
.to(described_class.new(limit: 20, offset: 20, order: %w[foo bar]))
|
79
90
|
end
|
80
|
-
specify { expect { first.merge!(second) }.not_to change {
|
91
|
+
specify { expect { first.merge!(second) }.not_to change { second_clone } }
|
81
92
|
|
82
93
|
specify do
|
83
94
|
expect { second.merge!(first) }.to change { second.clone }
|
84
95
|
.to(described_class.new(limit: 20, offset: 10, order: %w[bar foo]))
|
85
96
|
end
|
86
|
-
specify { expect { second.merge!(first) }.not_to change {
|
97
|
+
specify { expect { second.merge!(first) }.not_to change { first_clone } }
|
87
98
|
|
88
99
|
context 'spawns new storages for the merge' do
|
89
100
|
let(:names) { %i[limit offset order] }
|
@@ -100,7 +111,27 @@ describe Chewy::Search::Parameters do
|
|
100
111
|
subject { described_class.new(offset: 10, order: 'foo') }
|
101
112
|
|
102
113
|
specify { expect(subject.render).to eq(body: {from: 10, sort: ['foo']}) }
|
103
|
-
specify { expect(described_class.new.render).to eq({}) }
|
114
|
+
specify { expect(described_class.new.render).to eq(body: {}) }
|
115
|
+
|
116
|
+
context do
|
117
|
+
subject { described_class.new(request_cache: true) }
|
118
|
+
specify { expect(subject.render).to eq(body: {}, request_cache: true) }
|
119
|
+
end
|
120
|
+
|
121
|
+
context do
|
122
|
+
subject { described_class.new(search_type: 'query_then_fetch') }
|
123
|
+
specify { expect(subject.render).to eq(body: {}, search_type: 'query_then_fetch') }
|
124
|
+
end
|
125
|
+
|
126
|
+
context do
|
127
|
+
subject { described_class.new(allow_partial_search_results: true) }
|
128
|
+
specify { expect(subject.render).to eq(body: {}, allow_partial_search_results: true) }
|
129
|
+
end
|
130
|
+
|
131
|
+
context do
|
132
|
+
subject { described_class.new(ignore_unavailable: true) }
|
133
|
+
specify { expect(subject.render).to eq(body: {}, ignore_unavailable: true) }
|
134
|
+
end
|
104
135
|
|
105
136
|
context do
|
106
137
|
subject { described_class.new(query: {foo: 'bar'}, filter: {moo: 'baz'}) }
|
@@ -124,7 +155,7 @@ describe Chewy::Search::Parameters do
|
|
124
155
|
|
125
156
|
context do
|
126
157
|
subject { described_class.new(filter: {moo: 'baz'}, none: true) }
|
127
|
-
specify { expect(subject.render).to eq(body: {query: {
|
158
|
+
specify { expect(subject.render).to eq(body: {query: {match_none: {}}}) }
|
128
159
|
end
|
129
160
|
end
|
130
161
|
end
|