chewy 7.1.0 → 7.2.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/ruby.yml +58 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -7
- data/Guardfile +3 -1
- data/README.md +282 -245
- data/chewy.gemspec +3 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
- data/lib/chewy.rb +21 -75
- data/lib/chewy/config.rb +40 -40
- data/lib/chewy/errors.rb +0 -12
- data/lib/chewy/fields/base.rb +11 -1
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +46 -87
- data/lib/chewy/index/actions.rb +51 -32
- data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
- data/lib/chewy/{type → index}/crutch.rb +5 -5
- data/lib/chewy/{type → index}/import.rb +36 -27
- data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
- data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
- data/lib/chewy/{type → index}/import/routine.rb +15 -14
- data/lib/chewy/{type → index}/mapping.rb +26 -31
- data/lib/chewy/{type → index}/observe.rb +9 -19
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +60 -57
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/journal.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +9 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/railtie.rb +4 -2
- data/lib/chewy/rake_helper.rb +82 -107
- data/lib/chewy/rspec/update_index.rb +47 -43
- data/lib/chewy/search.rb +4 -17
- data/lib/chewy/search/loader.rb +18 -30
- data/lib/chewy/search/parameters.rb +4 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +82 -86
- data/lib/chewy/search/response.rb +4 -4
- data/lib/chewy/search/scoping.rb +6 -7
- data/lib/chewy/search/scrolling.rb +11 -11
- data/lib/chewy/stash.rb +14 -22
- data/lib/chewy/strategy.rb +3 -19
- data/lib/chewy/strategy/sidekiq.rb +1 -0
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +10 -22
- data/migration_guide.md +14 -0
- data/spec/chewy/config_spec.rb +14 -39
- data/spec/chewy/fields/base_spec.rb +412 -148
- data/spec/chewy/fields/root_spec.rb +16 -24
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +270 -24
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
- data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
- data/spec/chewy/{type → index}/import_spec.rb +102 -98
- data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
- data/spec/chewy/index/observe_spec.rb +116 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +7 -17
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +59 -102
- data/spec/chewy/journal_spec.rb +9 -22
- data/spec/chewy/minitest/helpers_spec.rb +13 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +145 -55
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/search/loader_spec.rb +19 -37
- 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/indices_spec.rb +2 -8
- data/spec/chewy/search/parameters/order_spec.rb +1 -1
- 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_spec.rb +12 -3
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +222 -74
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +7 -9
- data/spec/chewy/search_spec.rb +32 -35
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +14 -100
- data/spec/spec_helper.rb +2 -21
- data/spec/support/active_record.rb +15 -5
- metadata +44 -103
- data/.circleci/config.yml +0 -214
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type.rb +0 -120
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- 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/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- 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/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
@@ -8,16 +8,14 @@ describe Chewy::Search::Response, :orm do
|
|
8
8
|
stub_model(:country)
|
9
9
|
|
10
10
|
stub_index(:cities) do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
11
|
+
index_scope City
|
12
|
+
field :name
|
13
|
+
field :rating, type: 'integer'
|
15
14
|
end
|
16
15
|
stub_index(:countries) do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
index_scope Country
|
17
|
+
field :name
|
18
|
+
field :rating, type: 'integer'
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -127,7 +125,9 @@ describe Chewy::Search::Response, :orm do
|
|
127
125
|
specify { expect(subject.aggs).to eq({}) }
|
128
126
|
|
129
127
|
context do
|
130
|
-
let(:request)
|
128
|
+
let(:request) do
|
129
|
+
Chewy::Search::Request.new(CitiesIndex, CountriesIndex).aggs(avg_rating: {avg: {field: :rating}})
|
130
|
+
end
|
131
131
|
specify { expect(subject.aggs).to eq('avg_rating' => {'value' => 1.5}) }
|
132
132
|
end
|
133
133
|
end
|
@@ -137,7 +137,7 @@ describe Chewy::Search::Response, :orm do
|
|
137
137
|
specify { expect(subject.wrappers).to have(4).items }
|
138
138
|
specify do
|
139
139
|
expect(subject.wrappers.map(&:class).uniq)
|
140
|
-
.to contain_exactly(CitiesIndex
|
140
|
+
.to contain_exactly(CitiesIndex, CountriesIndex)
|
141
141
|
end
|
142
142
|
specify { expect(subject.wrappers.map(&:_data)).to eq(subject.hits) }
|
143
143
|
|
@@ -166,7 +166,7 @@ describe Chewy::Search::Response, :orm do
|
|
166
166
|
'_source' => {'id' => 2, 'rating' => 0}}
|
167
167
|
]}}
|
168
168
|
end
|
169
|
-
specify { expect(subject.wrappers.first).to be_a(CitiesIndex
|
169
|
+
specify { expect(subject.wrappers.first).to be_a(CitiesIndex) }
|
170
170
|
specify { expect(subject.wrappers.first.id).to eq(2) }
|
171
171
|
specify { expect(subject.wrappers.first.rating).to eq(0) }
|
172
172
|
specify { expect(subject.wrappers.first._score).to eq(1.3) }
|
@@ -183,7 +183,7 @@ describe Chewy::Search::Response, :orm do
|
|
183
183
|
'_explanation' => {foo: 'bar'}}
|
184
184
|
]}}
|
185
185
|
end
|
186
|
-
specify { expect(subject.wrappers.first).to be_a(CountriesIndex
|
186
|
+
specify { expect(subject.wrappers.first).to be_a(CountriesIndex) }
|
187
187
|
specify { expect(subject.wrappers.first.id).to eq('2') }
|
188
188
|
specify { expect(subject.wrappers.first.rating).to be_nil }
|
189
189
|
specify { expect(subject.wrappers.first._score).to eq(1.2) }
|
@@ -8,16 +8,14 @@ describe Chewy::Search::Scrolling, :orm do
|
|
8
8
|
stub_model(:country)
|
9
9
|
|
10
10
|
stub_index(:cities) do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
11
|
+
index_scope City
|
12
|
+
field :name
|
13
|
+
field :rating, type: 'integer'
|
15
14
|
end
|
16
15
|
stub_index(:countries) do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
index_scope Country
|
17
|
+
field :name
|
18
|
+
field :rating, type: 'integer'
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -153,7 +151,7 @@ describe Chewy::Search::Scrolling, :orm do
|
|
153
151
|
end
|
154
152
|
specify do
|
155
153
|
expect(request.scroll_wrappers(batch_size: 2).map(&:class).uniq)
|
156
|
-
.to eq([CitiesIndex
|
154
|
+
.to eq([CitiesIndex, CountriesIndex])
|
157
155
|
end
|
158
156
|
end
|
159
157
|
|
data/spec/chewy/search_spec.rb
CHANGED
@@ -4,47 +4,34 @@ describe Chewy::Search do
|
|
4
4
|
before { Chewy.massacre }
|
5
5
|
|
6
6
|
before do
|
7
|
-
stub_index(:products)
|
8
|
-
define_type :product
|
9
|
-
end
|
7
|
+
stub_index(:products)
|
10
8
|
end
|
11
9
|
|
12
|
-
let(:product) { ProductsIndex::Product }
|
13
|
-
|
14
10
|
describe '.all' do
|
15
11
|
specify { expect(ProductsIndex.all).to be_a(Chewy::Search::Request) }
|
16
|
-
specify { expect(product.all).to be_a(Chewy::Search::Request) }
|
17
12
|
|
18
13
|
context do
|
19
14
|
before { allow(Chewy).to receive_messages(search_class: Chewy::Search::Request) }
|
20
15
|
|
21
16
|
specify { expect(ProductsIndex.all).to be_a(Chewy::Search::Request) }
|
22
|
-
specify { expect(product.all).to be_a(Chewy::Search::Request) }
|
23
17
|
end
|
24
18
|
end
|
25
19
|
|
26
20
|
describe '.search_string' do
|
27
21
|
specify do
|
28
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(q: 'hello')).
|
22
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(q: 'hello')).once
|
29
23
|
ProductsIndex.search_string('hello')
|
30
|
-
product.search_string('hello')
|
31
24
|
end
|
32
25
|
|
33
26
|
specify do
|
34
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(explain: true)).
|
27
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(explain: true)).once
|
35
28
|
ProductsIndex.search_string('hello', explain: true)
|
36
|
-
product.search_string('hello', explain: true)
|
37
29
|
end
|
38
30
|
|
39
31
|
specify do
|
40
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products']))
|
32
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'])).once
|
41
33
|
ProductsIndex.search_string('hello')
|
42
34
|
end
|
43
|
-
|
44
|
-
specify do
|
45
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products']))
|
46
|
-
product.search_string('hello')
|
47
|
-
end
|
48
35
|
end
|
49
36
|
|
50
37
|
context 'named scopes' do
|
@@ -61,10 +48,9 @@ describe Chewy::Search do
|
|
61
48
|
filter { match name: "Name#{index}" }
|
62
49
|
end
|
63
50
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
51
|
+
index_scope City
|
52
|
+
field :name, type: 'keyword'
|
53
|
+
field :rating, type: :integer
|
68
54
|
end
|
69
55
|
|
70
56
|
stub_index(:countries) do
|
@@ -76,10 +62,9 @@ describe Chewy::Search do
|
|
76
62
|
filter { match name: "Name#{index}" }
|
77
63
|
end
|
78
64
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
65
|
+
index_scope Country
|
66
|
+
field :name, type: 'keyword'
|
67
|
+
field :rating, type: :integer
|
83
68
|
end
|
84
69
|
end
|
85
70
|
|
@@ -92,30 +77,42 @@ describe Chewy::Search do
|
|
92
77
|
end
|
93
78
|
|
94
79
|
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:rating)).to eq([1, 1]) }
|
95
|
-
specify
|
80
|
+
specify do
|
81
|
+
expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:class))
|
82
|
+
.to match_array([CitiesIndex, CountriesIndex])
|
83
|
+
end
|
96
84
|
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:rating)).to eq([1]) }
|
97
|
-
specify
|
85
|
+
specify do
|
86
|
+
expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:class))
|
87
|
+
.to eq([CitiesIndex])
|
88
|
+
end
|
98
89
|
specify { expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:rating)).to eq([2, 1]) }
|
99
|
-
specify
|
90
|
+
specify do
|
91
|
+
expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:class))
|
92
|
+
.to eq([CitiesIndex, CountriesIndex])
|
93
|
+
end
|
100
94
|
specify { expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:rating)).to eq([1, 1]) }
|
101
|
-
specify
|
95
|
+
specify do
|
96
|
+
expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:class))
|
97
|
+
.to match_array([CitiesIndex, CountriesIndex])
|
98
|
+
end
|
102
99
|
|
103
100
|
specify { expect(CitiesIndex.by_rating(2).map(&:rating)).to eq([2]) }
|
104
|
-
specify { expect(CitiesIndex.by_rating(2).map(&:class)).to eq([CitiesIndex
|
101
|
+
specify { expect(CitiesIndex.by_rating(2).map(&:class)).to eq([CitiesIndex]) }
|
105
102
|
specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:rating)).to eq([2]) }
|
106
|
-
specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:class)).to eq([CitiesIndex
|
103
|
+
specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:class)).to eq([CitiesIndex]) }
|
107
104
|
specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
|
108
105
|
specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
|
109
106
|
specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
|
110
107
|
specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
|
111
108
|
specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:rating)).to eq([2]) }
|
112
|
-
specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:class)).to eq([CitiesIndex
|
109
|
+
specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:class)).to eq([CitiesIndex]) }
|
113
110
|
|
114
111
|
specify { expect(CountriesIndex.by_rating(3).map(&:rating)).to eq([3]) }
|
115
|
-
specify { expect(CountriesIndex.by_rating(3).map(&:class)).to eq([CountriesIndex
|
112
|
+
specify { expect(CountriesIndex.by_rating(3).map(&:class)).to eq([CountriesIndex]) }
|
116
113
|
specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:rating)).to eq([3]) }
|
117
|
-
specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:class)).to eq([CountriesIndex
|
114
|
+
specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:class)).to eq([CountriesIndex]) }
|
118
115
|
specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:rating)).to eq([3]) }
|
119
|
-
specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:class)).to eq([CountriesIndex
|
116
|
+
specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:class)).to eq([CountriesIndex]) }
|
120
117
|
end
|
121
118
|
end
|
data/spec/chewy/stash_spec.rb
CHANGED
@@ -10,12 +10,10 @@ describe Chewy::Stash::Journal, :orm do
|
|
10
10
|
before do
|
11
11
|
stub_model(:city)
|
12
12
|
stub_index(:cities) do
|
13
|
-
|
13
|
+
index_scope City
|
14
14
|
end
|
15
|
-
stub_index(:countries)
|
16
|
-
|
17
|
-
end
|
18
|
-
stub_index(:users) { define_type :user }
|
15
|
+
stub_index(:countries)
|
16
|
+
stub_index(:users)
|
19
17
|
stub_index(:borogoves)
|
20
18
|
end
|
21
19
|
|
@@ -28,7 +26,7 @@ describe Chewy::Stash::Journal, :orm do
|
|
28
26
|
CountriesIndex.import!([id: 2, name: 'Country'], journal: true)
|
29
27
|
end
|
30
28
|
Timecop.travel(Time.now + 2.minutes) do
|
31
|
-
UsersIndex
|
29
|
+
UsersIndex.import!([id: 3, name: 'User'], journal: true)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -72,26 +70,16 @@ describe Chewy::Stash::Journal, :orm do
|
|
72
70
|
specify { expect(fetch_deleted_number(described_class.clean(only: UsersIndex))).to eq(1) }
|
73
71
|
specify { expect(fetch_deleted_number(described_class.clean(only: [CitiesIndex, UsersIndex]))).to eq(2) }
|
74
72
|
|
75
|
-
specify
|
73
|
+
specify do
|
74
|
+
expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CountriesIndex))).to eq(0)
|
75
|
+
end
|
76
76
|
specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CitiesIndex))).to eq(1) }
|
77
77
|
end
|
78
78
|
|
79
79
|
describe '.for' do
|
80
80
|
specify { expect(described_class.for(UsersIndex).map(&:index_name)).to eq(['users']) }
|
81
|
-
specify
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#type' do
|
86
|
-
let(:index_name) { 'users' }
|
87
|
-
let(:type_name) { 'city' }
|
88
|
-
subject { described_class::Journal.new('index_name' => index_name, 'type_name' => type_name).type }
|
89
|
-
|
90
|
-
specify { expect { subject }.to raise_error(Chewy::UnderivableType) }
|
91
|
-
|
92
|
-
context do
|
93
|
-
let(:index_name) { 'cities' }
|
94
|
-
it { is_expected.to eq(CitiesIndex::City) }
|
81
|
+
specify do
|
82
|
+
expect(described_class.for(CitiesIndex, UsersIndex).map(&:index_name)).to contain_exactly('cities', 'users')
|
95
83
|
end
|
96
84
|
end
|
97
85
|
end
|
@@ -19,11 +19,11 @@ if defined?(::ActiveJob)
|
|
19
19
|
|
20
20
|
before do
|
21
21
|
stub_model(:city) do
|
22
|
-
update_index('cities
|
22
|
+
update_index('cities') { self }
|
23
23
|
end
|
24
24
|
|
25
25
|
stub_index(:cities) do
|
26
|
-
|
26
|
+
index_scope City
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -32,7 +32,7 @@ if defined?(::ActiveJob)
|
|
32
32
|
|
33
33
|
specify do
|
34
34
|
expect { [city, other_city].map(&:save!) }
|
35
|
-
.not_to update_index(CitiesIndex
|
35
|
+
.not_to update_index(CitiesIndex, strategy: :active_job)
|
36
36
|
end
|
37
37
|
|
38
38
|
specify do
|
@@ -55,19 +55,19 @@ if defined?(::ActiveJob)
|
|
55
55
|
specify do
|
56
56
|
::ActiveJob::Base.queue_adapter = :inline
|
57
57
|
expect { [city, other_city].map(&:save!) }
|
58
|
-
.to update_index(CitiesIndex
|
58
|
+
.to update_index(CitiesIndex, strategy: :active_job)
|
59
59
|
.and_reindex(city, other_city).only
|
60
60
|
end
|
61
61
|
|
62
62
|
specify do
|
63
|
-
expect(CitiesIndex
|
64
|
-
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex
|
63
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
|
64
|
+
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
65
65
|
end
|
66
66
|
|
67
67
|
specify do
|
68
68
|
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
69
|
-
expect(CitiesIndex
|
70
|
-
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex
|
69
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
|
70
|
+
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -5,11 +5,11 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_model(:country) do
|
8
|
-
update_index('countries
|
8
|
+
update_index('countries') { self }
|
9
9
|
end
|
10
10
|
|
11
11
|
stub_index(:countries) do
|
12
|
-
|
12
|
+
index_scope Country
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -18,35 +18,34 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
18
18
|
|
19
19
|
specify do
|
20
20
|
expect { [country, other_country].map(&:save!) }
|
21
|
-
.to update_index(CountriesIndex
|
21
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
22
22
|
.and_reindex(country, other_country).only
|
23
23
|
end
|
24
24
|
|
25
25
|
specify do
|
26
26
|
expect { [country, other_country].map(&:destroy) }
|
27
|
-
.to update_index(CountriesIndex
|
27
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
28
28
|
.and_delete(country, other_country).only
|
29
29
|
end
|
30
30
|
|
31
31
|
context do
|
32
32
|
before do
|
33
33
|
stub_index(:countries) do
|
34
|
-
|
35
|
-
|
36
|
-
end
|
34
|
+
index_scope Country
|
35
|
+
root id: -> { country_code } do
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
40
|
specify do
|
42
41
|
expect { [country, other_country].map(&:save!) }
|
43
|
-
.to update_index(CountriesIndex
|
42
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
44
43
|
.and_reindex('HL', 'WD').only
|
45
44
|
end
|
46
45
|
|
47
46
|
specify do
|
48
47
|
expect { [country, other_country].map(&:destroy) }
|
49
|
-
.to update_index(CountriesIndex
|
48
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
50
49
|
.and_delete('HL', 'WD').only
|
51
50
|
end
|
52
51
|
|
@@ -55,7 +54,7 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
55
54
|
country.save!
|
56
55
|
other_country.destroy
|
57
56
|
end
|
58
|
-
.to update_index(CountriesIndex
|
57
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
59
58
|
.and_reindex('HL').and_delete('WD').only
|
60
59
|
end
|
61
60
|
end
|
@@ -13,11 +13,11 @@ if defined?(::Sidekiq)
|
|
13
13
|
before { ::Sidekiq::Worker.clear_all }
|
14
14
|
before do
|
15
15
|
stub_model(:city) do
|
16
|
-
update_index('cities
|
16
|
+
update_index('cities') { self }
|
17
17
|
end
|
18
18
|
|
19
19
|
stub_index(:cities) do
|
20
|
-
|
20
|
+
index_scope City
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -26,27 +26,27 @@ if defined?(::Sidekiq)
|
|
26
26
|
|
27
27
|
specify do
|
28
28
|
expect { [city, other_city].map(&:save!) }
|
29
|
-
.not_to update_index(CitiesIndex
|
29
|
+
.not_to update_index(CitiesIndex, strategy: :sidekiq)
|
30
30
|
end
|
31
31
|
|
32
32
|
specify do
|
33
33
|
expect(::Sidekiq::Client).to receive(:push).with(hash_including('queue' => 'low')).and_call_original
|
34
34
|
::Sidekiq::Testing.inline! do
|
35
35
|
expect { [city, other_city].map(&:save!) }
|
36
|
-
.to update_index(CitiesIndex
|
36
|
+
.to update_index(CitiesIndex, strategy: :sidekiq)
|
37
37
|
.and_reindex(city, other_city).only
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
specify do
|
42
|
-
expect(CitiesIndex
|
43
|
-
Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex
|
42
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
|
43
|
+
Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
44
44
|
end
|
45
45
|
|
46
46
|
specify do
|
47
47
|
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
48
|
-
expect(CitiesIndex
|
49
|
-
Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex
|
48
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
|
49
|
+
Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
data/spec/chewy/strategy_spec.rb
CHANGED
@@ -14,7 +14,10 @@ describe Chewy::Strategy do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#push' do
|
17
|
-
specify
|
17
|
+
specify do
|
18
|
+
expect { strategy.push(:unexistant) }
|
19
|
+
.to raise_error(RuntimeError).with_message("Can't find update strategy `unexistant`")
|
20
|
+
end
|
18
21
|
|
19
22
|
specify do
|
20
23
|
expect { strategy.push(:atomic) }
|
@@ -35,7 +38,10 @@ describe Chewy::Strategy do
|
|
35
38
|
end
|
36
39
|
|
37
40
|
describe '#wrap' do
|
38
|
-
specify
|
41
|
+
specify do
|
42
|
+
expect { strategy.wrap(:unexistant) {} }
|
43
|
+
.to raise_error(RuntimeError).with_message("Can't find update strategy `unexistant`")
|
44
|
+
end
|
39
45
|
|
40
46
|
specify do
|
41
47
|
expect do
|
@@ -49,11 +55,11 @@ describe Chewy::Strategy do
|
|
49
55
|
context 'nesting', :orm do
|
50
56
|
before do
|
51
57
|
stub_model(:city) do
|
52
|
-
update_index('cities
|
58
|
+
update_index('cities') { self }
|
53
59
|
end
|
54
60
|
|
55
61
|
stub_index(:cities) do
|
56
|
-
|
62
|
+
index_scope City
|
57
63
|
end
|
58
64
|
end
|
59
65
|
|
@@ -64,12 +70,12 @@ describe Chewy::Strategy do
|
|
64
70
|
around { |example| Chewy.strategy(:bypass) { example.run } }
|
65
71
|
|
66
72
|
specify do
|
67
|
-
expect(CitiesIndex
|
73
|
+
expect(CitiesIndex).not_to receive(:import!)
|
68
74
|
[city, other_city].map(&:save!)
|
69
75
|
end
|
70
76
|
|
71
77
|
specify do
|
72
|
-
expect(CitiesIndex
|
78
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id]).once
|
73
79
|
Chewy.strategy(:atomic) { [city, other_city].map(&:save!) }
|
74
80
|
end
|
75
81
|
end
|
@@ -78,41 +84,39 @@ describe Chewy::Strategy do
|
|
78
84
|
around { |example| Chewy.strategy(:urgent) { example.run } }
|
79
85
|
|
80
86
|
specify do
|
81
|
-
expect(CitiesIndex
|
87
|
+
expect(CitiesIndex).to receive(:import!).at_least(2).times
|
82
88
|
[city, other_city].map(&:save!)
|
83
89
|
end
|
84
90
|
|
85
91
|
specify do
|
86
|
-
expect(CitiesIndex
|
92
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id]).once
|
87
93
|
Chewy.strategy(:atomic) { [city, other_city].map(&:save!) }
|
88
94
|
end
|
89
95
|
|
90
96
|
context 'hash passed to urgent' do
|
91
97
|
before do
|
92
|
-
stub_index(:cities)
|
93
|
-
define_type :city
|
94
|
-
end
|
98
|
+
stub_index(:cities)
|
95
99
|
|
96
100
|
stub_model(:city) do
|
97
|
-
update_index('cities
|
101
|
+
update_index('cities') { {name: name} }
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
101
105
|
specify do
|
102
106
|
[city, other_city].map(&:save!)
|
103
|
-
expect(CitiesIndex
|
107
|
+
expect(CitiesIndex.total_count).to eq(4)
|
104
108
|
end
|
105
109
|
|
106
110
|
context do
|
107
111
|
before do
|
108
112
|
stub_model(:city) do
|
109
|
-
update_index('cities
|
113
|
+
update_index('cities') { {id: id.to_s, name: name} }
|
110
114
|
end
|
111
115
|
end
|
112
116
|
|
113
117
|
specify do
|
114
118
|
[city, other_city].map(&:save!)
|
115
|
-
expect(CitiesIndex
|
119
|
+
expect(CitiesIndex.total_count).to eq(2)
|
116
120
|
end
|
117
121
|
end
|
118
122
|
end
|