chewy 0.10.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +240 -0
- data/.rubocop.yml +25 -25
- data/Appraisals +12 -10
- data/CHANGELOG.md +252 -263
- data/Gemfile +5 -1
- data/LICENSE.txt +1 -1
- data/README.md +142 -78
- data/chewy.gemspec +10 -12
- data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.5.2.activerecord.gemfile} +6 -4
- data/gemfiles/{rails.4.2.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +6 -4
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.6.0.activerecord.gemfile} +6 -3
- data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
- data/gemfiles/sequel.4.45.gemfile +2 -2
- data/lib/chewy.rb +2 -1
- data/lib/chewy/backports/duplicable.rb +1 -1
- data/lib/chewy/config.rb +10 -39
- data/lib/chewy/fields/base.rb +40 -28
- data/lib/chewy/fields/root.rb +18 -11
- data/lib/chewy/index.rb +3 -1
- data/lib/chewy/index/actions.rb +27 -15
- data/lib/chewy/index/settings.rb +2 -0
- data/lib/chewy/index/specification.rb +12 -10
- data/lib/chewy/minitest/helpers.rb +6 -6
- data/lib/chewy/minitest/search_index_receiver.rb +17 -17
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +4 -4
- data/lib/chewy/rake_helper.rb +5 -5
- data/lib/chewy/rspec/update_index.rb +3 -5
- data/lib/chewy/search.rb +4 -11
- data/lib/chewy/search/loader.rb +1 -1
- data/lib/chewy/search/pagination/will_paginate.rb +4 -2
- data/lib/chewy/search/parameters.rb +24 -6
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
- data/lib/chewy/search/parameters/indices.rb +123 -0
- data/lib/chewy/search/parameters/none.rb +1 -3
- data/lib/chewy/search/request.rb +100 -74
- data/lib/chewy/search/scrolling.rb +7 -6
- data/lib/chewy/stash.rb +30 -21
- data/lib/chewy/strategy/active_job.rb +1 -1
- data/lib/chewy/strategy/atomic.rb +1 -1
- data/lib/chewy/strategy/sidekiq.rb +1 -1
- data/lib/chewy/type.rb +5 -2
- data/lib/chewy/type/adapter/active_record.rb +1 -1
- data/lib/chewy/type/adapter/base.rb +9 -9
- data/lib/chewy/type/adapter/mongoid.rb +2 -4
- data/lib/chewy/type/adapter/orm.rb +7 -4
- data/lib/chewy/type/adapter/sequel.rb +5 -7
- data/lib/chewy/type/crutch.rb +1 -1
- data/lib/chewy/type/import.rb +13 -11
- data/lib/chewy/type/import/bulk_builder.rb +1 -1
- data/lib/chewy/type/import/bulk_request.rb +4 -2
- data/lib/chewy/type/import/journal_builder.rb +3 -3
- data/lib/chewy/type/import/routine.rb +3 -3
- data/lib/chewy/type/mapping.rb +42 -36
- data/lib/chewy/type/observe.rb +16 -12
- data/lib/chewy/type/syncer.rb +15 -14
- data/lib/chewy/type/witchcraft.rb +11 -7
- data/lib/chewy/type/wrapper.rb +14 -4
- data/lib/chewy/version.rb +1 -1
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/migration_guide.md +18 -0
- data/spec/chewy/config_spec.rb +16 -21
- data/spec/chewy/fields/base_spec.rb +70 -70
- data/spec/chewy/fields/root_spec.rb +56 -9
- data/spec/chewy/index/actions_spec.rb +63 -7
- data/spec/chewy/index/specification_spec.rb +25 -16
- data/spec/chewy/index_spec.rb +75 -45
- data/spec/chewy/journal_spec.rb +33 -29
- data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
- data/spec/chewy/multi_search_spec.rb +85 -0
- data/spec/chewy/rake_helper_spec.rb +123 -95
- data/spec/chewy/rspec/update_index_spec.rb +47 -46
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/pagination/kaminari_spec.rb +7 -3
- data/spec/chewy/search/pagination/will_paginate_spec.rb +9 -3
- data/spec/chewy/search/parameters/indices_spec.rb +190 -0
- data/spec/chewy/search/parameters/none_spec.rb +1 -1
- data/spec/chewy/search/parameters_spec.rb +21 -4
- data/spec/chewy/search/request_spec.rb +101 -70
- data/spec/chewy/search/response_spec.rb +27 -17
- data/spec/chewy/search/scrolling_spec.rb +25 -16
- data/spec/chewy/search_spec.rb +49 -35
- data/spec/chewy/stash_spec.rb +15 -13
- data/spec/chewy/strategy/active_job_spec.rb +15 -2
- data/spec/chewy/strategy/shoryuken_spec.rb +8 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
- data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
- data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
- data/spec/chewy/type/import/journal_builder_spec.rb +17 -15
- data/spec/chewy/type/import_spec.rb +6 -0
- data/spec/chewy/type/mapping_spec.rb +51 -18
- data/spec/chewy/type/observe_spec.rb +4 -4
- data/spec/chewy/type/witchcraft_spec.rb +31 -0
- data/spec/chewy/type/wrapper_spec.rb +3 -1
- data/spec/chewy_spec.rb +0 -7
- data/spec/spec_helper.rb +5 -1
- data/spec/support/active_record.rb +20 -0
- metadata +46 -116
- data/.travis.yml +0 -53
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
- 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/lib/chewy/query.rb +0 -1098
- 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/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/parameters/indices_boost_spec.rb +0 -83
@@ -7,12 +7,13 @@ describe Chewy::Search::Scrolling, :orm do
|
|
7
7
|
stub_model(:city)
|
8
8
|
stub_model(:country)
|
9
9
|
|
10
|
-
stub_index(:
|
10
|
+
stub_index(:cities) do
|
11
11
|
define_type City do
|
12
12
|
field :name
|
13
13
|
field :rating, type: 'integer'
|
14
14
|
end
|
15
|
-
|
15
|
+
end
|
16
|
+
stub_index(:countries) do
|
16
17
|
define_type Country do
|
17
18
|
field :name
|
18
19
|
field :rating, type: 'integer'
|
@@ -20,12 +21,15 @@ describe Chewy::Search::Scrolling, :orm do
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
let(:request) { Chewy::Search::Request.new(
|
24
|
+
let(:request) { Chewy::Search::Request.new(CitiesIndex, CountriesIndex).order(:rating) }
|
24
25
|
|
25
26
|
specify { expect(request.scroll_batches.to_a).to eq([]) }
|
26
27
|
|
27
28
|
context do
|
28
|
-
before
|
29
|
+
before do
|
30
|
+
CitiesIndex.import!(cities)
|
31
|
+
CountriesIndex.import!(countries: countries)
|
32
|
+
end
|
29
33
|
|
30
34
|
let(:cities) { Array.new(2) { |i| City.create!(rating: i, name: "city #{i}") } }
|
31
35
|
let(:countries) { Array.new(3) { |i| Country.create!(rating: i + 2, name: "country #{i}") } }
|
@@ -61,9 +65,9 @@ describe Chewy::Search::Scrolling, :orm do
|
|
61
65
|
context do
|
62
66
|
before { expect(Chewy.client).not_to receive(:scroll) }
|
63
67
|
it 'respects limit and terminate_after' do
|
64
|
-
expect(request.terminate_after(
|
68
|
+
expect(request.terminate_after(1).limit(4).scroll_batches(batch_size: 3).map do |batch|
|
65
69
|
batch.map { |hit| hit['_source']['rating'] }
|
66
|
-
end).to eq([[0,
|
70
|
+
end).to eq([[0, 2]])
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
@@ -103,6 +107,11 @@ describe Chewy::Search::Scrolling, :orm do
|
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
110
|
+
it 'clears the scroll after completion' do
|
111
|
+
expect(Chewy.client).to receive(:clear_scroll).with(scroll_id: anything).once.and_call_original
|
112
|
+
request.scroll_batches(batch_size: 3) {}
|
113
|
+
end
|
114
|
+
|
106
115
|
context 'instrumentation' do
|
107
116
|
specify do
|
108
117
|
outer_payload = []
|
@@ -113,18 +122,18 @@ describe Chewy::Search::Scrolling, :orm do
|
|
113
122
|
|
114
123
|
expect(outer_payload).to match_array([
|
115
124
|
hash_including(
|
116
|
-
index:
|
117
|
-
indexes: [
|
118
|
-
request: {index: [
|
119
|
-
type: [
|
120
|
-
types: [
|
125
|
+
index: [CitiesIndex, CountriesIndex],
|
126
|
+
indexes: [CitiesIndex, CountriesIndex],
|
127
|
+
request: {index: %w[cities countries], type: %w[city country], body: {sort: ['rating']}, size: 3, scroll: '1m'},
|
128
|
+
type: [CitiesIndex::City, CountriesIndex::Country],
|
129
|
+
types: [CitiesIndex::City, CountriesIndex::Country]
|
121
130
|
),
|
122
131
|
hash_including(
|
123
|
-
index:
|
124
|
-
indexes: [
|
132
|
+
index: [CitiesIndex, CountriesIndex],
|
133
|
+
indexes: [CitiesIndex, CountriesIndex],
|
125
134
|
request: {scroll: '1m', scroll_id: an_instance_of(String)},
|
126
|
-
type: [
|
127
|
-
types: [
|
135
|
+
type: [CitiesIndex::City, CountriesIndex::Country],
|
136
|
+
types: [CitiesIndex::City, CountriesIndex::Country]
|
128
137
|
)
|
129
138
|
])
|
130
139
|
end
|
@@ -149,7 +158,7 @@ describe Chewy::Search::Scrolling, :orm do
|
|
149
158
|
end
|
150
159
|
specify do
|
151
160
|
expect(request.scroll_wrappers(batch_size: 2).map(&:class).uniq)
|
152
|
-
.to eq([
|
161
|
+
.to eq([CitiesIndex::City, CountriesIndex::Country])
|
153
162
|
end
|
154
163
|
end
|
155
164
|
|
data/spec/chewy/search_spec.rb
CHANGED
@@ -6,7 +6,6 @@ describe Chewy::Search do
|
|
6
6
|
before do
|
7
7
|
stub_index(:products) do
|
8
8
|
define_type :product
|
9
|
-
define_type :product2
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
@@ -38,12 +37,12 @@ describe Chewy::Search do
|
|
38
37
|
end
|
39
38
|
|
40
39
|
specify do
|
41
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'], type: %w[product
|
40
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'], type: %w[product]))
|
42
41
|
ProductsIndex.search_string('hello')
|
43
42
|
end
|
44
43
|
|
45
44
|
specify do
|
46
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'], type: [
|
45
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'], type: %w[product]))
|
47
46
|
product.search_string('hello')
|
48
47
|
end
|
49
48
|
end
|
@@ -53,7 +52,7 @@ describe Chewy::Search do
|
|
53
52
|
stub_model(:city)
|
54
53
|
stub_model(:country)
|
55
54
|
|
56
|
-
stub_index(:
|
55
|
+
stub_index(:cities) do
|
57
56
|
def self.by_rating(value)
|
58
57
|
filter { match rating: value }
|
59
58
|
end
|
@@ -63,45 +62,60 @@ describe Chewy::Search do
|
|
63
62
|
end
|
64
63
|
|
65
64
|
define_type City do
|
66
|
-
|
67
|
-
filter { match rating: yield }
|
68
|
-
end
|
69
|
-
|
70
|
-
field :name, index: 'not_analyzed'
|
65
|
+
field :name, type: 'keyword'
|
71
66
|
field :rating, type: :integer
|
72
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
stub_index(:countries) do
|
71
|
+
def self.by_rating(value)
|
72
|
+
filter { match rating: value }
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.by_name(index)
|
76
|
+
filter { match name: "Name#{index}" }
|
77
|
+
end
|
73
78
|
|
74
79
|
define_type Country do
|
75
|
-
field :name,
|
80
|
+
field :name, type: 'keyword'
|
76
81
|
field :rating, type: :integer
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
81
|
-
let!(:cities) { Array.new(3) { |i| City.create! rating: i + 1, name: "Name#{i +
|
82
|
-
let!(:countries) { Array.new(3) { |i| Country.create! rating: i + 1, name: "Name#{i +
|
83
|
-
|
84
|
-
before
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
specify { expect(
|
90
|
-
specify { expect(
|
91
|
-
specify { expect(
|
92
|
-
|
93
|
-
specify { expect(
|
94
|
-
specify { expect(
|
95
|
-
specify { expect(
|
96
|
-
specify { expect(
|
97
|
-
|
98
|
-
specify { expect(
|
99
|
-
|
100
|
-
specify { expect(
|
101
|
-
specify { expect(
|
102
|
-
specify { expect(
|
103
|
-
specify { expect(
|
104
|
-
specify { expect(
|
105
|
-
specify { expect(
|
86
|
+
let!(:cities) { Array.new(3) { |i| City.create! rating: i + 1, name: "Name#{i + 2}" } }
|
87
|
+
let!(:countries) { Array.new(3) { |i| Country.create! rating: i + 1, name: "Name#{i + 3}" } }
|
88
|
+
|
89
|
+
before do
|
90
|
+
CitiesIndex.import!(cities)
|
91
|
+
CountriesIndex.import!(country: countries)
|
92
|
+
end
|
93
|
+
|
94
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:rating)).to eq([1, 1]) }
|
95
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:class)).to match_array([CitiesIndex::City, CountriesIndex::Country]) }
|
96
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:rating)).to eq([1]) }
|
97
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:class)).to eq([CitiesIndex::City]) }
|
98
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:rating)).to eq([2, 1]) }
|
99
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:class)).to eq([CitiesIndex::City, CountriesIndex::Country]) }
|
100
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:rating)).to eq([1, 1]) }
|
101
|
+
specify { expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:class)).to match_array([CitiesIndex::City, CountriesIndex::Country]) }
|
102
|
+
|
103
|
+
specify { expect(CitiesIndex.by_rating(2).map(&:rating)).to eq([2]) }
|
104
|
+
specify { expect(CitiesIndex.by_rating(2).map(&:class)).to eq([CitiesIndex::City]) }
|
105
|
+
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::City]) }
|
107
|
+
specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
|
108
|
+
specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
|
109
|
+
specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
|
110
|
+
specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
|
111
|
+
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::City]) }
|
113
|
+
|
114
|
+
specify { expect(CountriesIndex.by_rating(3).map(&:rating)).to eq([3]) }
|
115
|
+
specify { expect(CountriesIndex.by_rating(3).map(&:class)).to eq([CountriesIndex::Country]) }
|
116
|
+
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::Country]) }
|
118
|
+
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::Country]) }
|
106
120
|
end
|
107
121
|
end
|
data/spec/chewy/stash_spec.rb
CHANGED
@@ -9,8 +9,10 @@ describe Chewy::Stash::Journal, :orm do
|
|
9
9
|
|
10
10
|
before do
|
11
11
|
stub_model(:city)
|
12
|
-
stub_index(:
|
12
|
+
stub_index(:cities) do
|
13
13
|
define_type City
|
14
|
+
end
|
15
|
+
stub_index(:countries) do
|
14
16
|
define_type :country
|
15
17
|
end
|
16
18
|
stub_index(:users) { define_type :user }
|
@@ -21,9 +23,9 @@ describe Chewy::Stash::Journal, :orm do
|
|
21
23
|
after { Timecop.return }
|
22
24
|
|
23
25
|
before do
|
24
|
-
|
26
|
+
CitiesIndex.import!(City.new(id: 1, name: 'City'), journal: true)
|
25
27
|
Timecop.travel(Time.now + 1.minute) do
|
26
|
-
|
28
|
+
CountriesIndex.import!([id: 2, name: 'Country'], journal: true)
|
27
29
|
end
|
28
30
|
Timecop.travel(Time.now + 2.minutes) do
|
29
31
|
UsersIndex::User.import!([id: 3, name: 'User'], journal: true)
|
@@ -49,11 +51,11 @@ describe Chewy::Stash::Journal, :orm do
|
|
49
51
|
.to contain_exactly([{'id' => 3, 'name' => 'User'}])
|
50
52
|
end
|
51
53
|
specify do
|
52
|
-
expect(described_class.entries(Time.now - 30.seconds, only: [
|
54
|
+
expect(described_class.entries(Time.now - 30.seconds, only: [CitiesIndex, UsersIndex]).map(&:references))
|
53
55
|
.to contain_exactly([1], [{'id' => 3, 'name' => 'User'}])
|
54
56
|
end
|
55
57
|
specify do
|
56
|
-
expect(described_class.entries(Time.now + 30.seconds, only: [
|
58
|
+
expect(described_class.entries(Time.now + 30.seconds, only: [CitiesIndex, UsersIndex]).map(&:references))
|
57
59
|
.to contain_exactly([{'id' => 3, 'name' => 'User'}])
|
58
60
|
end
|
59
61
|
specify do
|
@@ -68,28 +70,28 @@ describe Chewy::Stash::Journal, :orm do
|
|
68
70
|
specify { expect(fetch_deleted_number(described_class.clean(Time.now + 90.seconds))).to eq(2) }
|
69
71
|
specify { expect(fetch_deleted_number(described_class.clean(only: BorogovesIndex))).to eq(0) }
|
70
72
|
specify { expect(fetch_deleted_number(described_class.clean(only: UsersIndex))).to eq(1) }
|
71
|
-
specify { expect(fetch_deleted_number(described_class.clean(only: [
|
73
|
+
specify { expect(fetch_deleted_number(described_class.clean(only: [CitiesIndex, UsersIndex]))).to eq(2) }
|
72
74
|
|
73
|
-
specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only:
|
74
|
-
specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only:
|
75
|
+
specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CountriesIndex))).to eq(0) }
|
76
|
+
specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CitiesIndex))).to eq(1) }
|
75
77
|
end
|
76
78
|
|
77
79
|
describe '.for' do
|
78
80
|
specify { expect(described_class.for(UsersIndex).map(&:index_name)).to eq(['users']) }
|
79
|
-
specify { expect(described_class.for(
|
80
|
-
specify { expect(described_class.for(
|
81
|
+
specify { expect(described_class.for(CitiesIndex, CountriesIndex).map(&:type_name)).to contain_exactly('city', 'country') }
|
82
|
+
specify { expect(described_class.for(CitiesIndex, UsersIndex).map(&:index_name)).to contain_exactly('cities', 'users') }
|
81
83
|
end
|
82
84
|
|
83
85
|
describe '#type' do
|
84
86
|
let(:index_name) { 'users' }
|
85
87
|
let(:type_name) { 'city' }
|
86
|
-
subject { described_class.new('index_name' => index_name, 'type_name' => type_name).type }
|
88
|
+
subject { described_class::Journal.new('index_name' => index_name, 'type_name' => type_name).type }
|
87
89
|
|
88
90
|
specify { expect { subject }.to raise_error(Chewy::UnderivableType) }
|
89
91
|
|
90
92
|
context do
|
91
|
-
let(:index_name) { '
|
92
|
-
it { is_expected.to eq(
|
93
|
+
let(:index_name) { 'cities' }
|
94
|
+
it { is_expected.to eq(CitiesIndex::City) }
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
@@ -2,7 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
if defined?(::ActiveJob)
|
4
4
|
describe Chewy::Strategy::ActiveJob do
|
5
|
-
around
|
5
|
+
around do |example|
|
6
|
+
active_job_settings = Chewy.settings[:active_job]
|
7
|
+
Chewy.settings[:active_job] = {queue: 'low'}
|
8
|
+
Chewy.strategy(:bypass) { example.run }
|
9
|
+
Chewy.settings[:active_job] = active_job_settings
|
10
|
+
end
|
6
11
|
before(:all) do
|
7
12
|
::ActiveJob::Base.logger = Chewy.logger
|
8
13
|
end
|
@@ -36,7 +41,15 @@ if defined?(::ActiveJob)
|
|
36
41
|
end
|
37
42
|
enqueued_job = ::ActiveJob::Base.queue_adapter.enqueued_jobs.first
|
38
43
|
expect(enqueued_job[:job]).to eq(Chewy::Strategy::ActiveJob::Worker)
|
39
|
-
expect(enqueued_job[:queue]).to eq('
|
44
|
+
expect(enqueued_job[:queue]).to eq('low')
|
45
|
+
end
|
46
|
+
|
47
|
+
specify do
|
48
|
+
Chewy.strategy(:active_job) do
|
49
|
+
[city, other_city].map(&:save!)
|
50
|
+
end
|
51
|
+
enqueued_job = ::ActiveJob::Base.queue_adapter.enqueued_jobs.first
|
52
|
+
expect(enqueued_job[:queue]).to eq('low')
|
40
53
|
end
|
41
54
|
|
42
55
|
specify do
|
@@ -1,8 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
if defined?(::Shoryuken)
|
4
|
+
require 'aws-sdk-sqs'
|
5
|
+
|
4
6
|
describe Chewy::Strategy::Shoryuken do
|
5
|
-
around
|
7
|
+
around do |example|
|
8
|
+
shoryuken_settings = Chewy.settings[:shoryuken]
|
9
|
+
Chewy.settings[:shoryuken] = {queue: 'low'}
|
10
|
+
Chewy.strategy(:bypass) { example.run }
|
11
|
+
Chewy.settings[:shoryuken] = shoryuken_settings
|
12
|
+
end
|
6
13
|
before { ::Shoryuken.groups.clear }
|
7
14
|
before do
|
8
15
|
stub_model(:city) do
|
@@ -29,7 +36,6 @@ if defined?(::Shoryuken)
|
|
29
36
|
end
|
30
37
|
|
31
38
|
specify do
|
32
|
-
Chewy.settings[:shoryuken] = {queue: 'low'}
|
33
39
|
expect(Chewy::Strategy::Shoryuken::Worker).to receive(:perform_async)
|
34
40
|
.with(hash_including(type: 'CitiesIndex::City', ids: [city.id, other_city.id]), hash_including(queue: 'low'))
|
35
41
|
Chewy.strategy(:shoryuken) do
|
@@ -4,7 +4,12 @@ if defined?(::Sidekiq)
|
|
4
4
|
require 'sidekiq/testing'
|
5
5
|
|
6
6
|
describe Chewy::Strategy::Sidekiq do
|
7
|
-
around
|
7
|
+
around do |example|
|
8
|
+
sidekiq_settings = Chewy.settings[:sidekiq]
|
9
|
+
Chewy.settings[:sidekiq] = {queue: 'low'}
|
10
|
+
Chewy.strategy(:bypass) { example.run }
|
11
|
+
Chewy.settings[:sidekiq] = sidekiq_settings
|
12
|
+
end
|
8
13
|
before { ::Sidekiq::Worker.clear_all }
|
9
14
|
before do
|
10
15
|
stub_model(:city) do
|
@@ -25,7 +30,6 @@ if defined?(::Sidekiq)
|
|
25
30
|
end
|
26
31
|
|
27
32
|
specify do
|
28
|
-
Chewy.settings[:sidekiq] = {queue: 'low'}
|
29
33
|
expect(::Sidekiq::Client).to receive(:push).with(hash_including('queue' => 'low')).and_call_original
|
30
34
|
::Sidekiq::Testing.inline! do
|
31
35
|
expect { [city, other_city].map(&:save!) }
|
@@ -86,7 +86,19 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
|
|
86
86
|
.to eq([{index: cities.first(2)}, {index: cities.last(1)}])
|
87
87
|
end
|
88
88
|
|
89
|
-
specify
|
89
|
+
specify do
|
90
|
+
cities
|
91
|
+
expects_db_queries do
|
92
|
+
expect(import(cities, direct_import: false)).to eq([{index: cities}])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
specify do
|
96
|
+
cities
|
97
|
+
expects_no_query do
|
98
|
+
expect(import(cities, direct_import: true)).to eq([{index: cities}])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
90
102
|
specify do
|
91
103
|
expect(import(cities, batch_size: 2))
|
92
104
|
.to eq([{index: cities.first(2)}, {index: cities.last(1)}])
|
@@ -454,9 +466,9 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
|
|
454
466
|
specify do
|
455
467
|
expect(subject.import_fields(fields: [:updated_at], typecast: false))
|
456
468
|
.to match([contain_exactly(
|
457
|
-
[1, match(/#{Time.now.strftime('%Y-%m-%d')}/)],
|
458
|
-
[2, match(/#{Time.now.strftime('%Y-%m-%d')}/)],
|
459
|
-
[3, match(/#{Time.now.strftime('%Y-%m-%d')}/)]
|
469
|
+
[1, match(/#{Time.now.utc.strftime('%Y-%m-%d')}/)],
|
470
|
+
[2, match(/#{Time.now.utc.strftime('%Y-%m-%d')}/)],
|
471
|
+
[3, match(/#{Time.now.utc.strftime('%Y-%m-%d')}/)]
|
460
472
|
)])
|
461
473
|
end
|
462
474
|
end
|
@@ -4,7 +4,7 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
4
4
|
before { Chewy.massacre }
|
5
5
|
|
6
6
|
subject { described_class.new(type, index: index, delete: delete, fields: fields) }
|
7
|
-
let(:type) {
|
7
|
+
let(:type) { CitiesIndex::City }
|
8
8
|
let(:index) { [] }
|
9
9
|
let(:delete) { [] }
|
10
10
|
let(:fields) { [] }
|
@@ -13,7 +13,7 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
13
13
|
context 'simple bulk', :orm do
|
14
14
|
before do
|
15
15
|
stub_model(:city)
|
16
|
-
stub_index(:
|
16
|
+
stub_index(:cities) do
|
17
17
|
define_type City do
|
18
18
|
field :name, :rating
|
19
19
|
end
|
@@ -67,98 +67,13 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
context 'parent-child relationship', :orm do
|
71
|
-
before do
|
72
|
-
stub_model(:country)
|
73
|
-
stub_model(:city)
|
74
|
-
adapter == :sequel ? City.many_to_one(:country) : City.belongs_to(:country)
|
75
|
-
end
|
76
|
-
|
77
|
-
before do
|
78
|
-
stub_index(:places) do
|
79
|
-
define_type Country do
|
80
|
-
field :name
|
81
|
-
end
|
82
|
-
|
83
|
-
define_type City do
|
84
|
-
root parent: 'country', parent_id: -> { country_id } do
|
85
|
-
field :name
|
86
|
-
field :rating
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
before { PlacesIndex::Country.import(country) }
|
93
|
-
let(:country) { Country.create!(id: 1, name: 'country') }
|
94
|
-
let(:another_country) { Country.create!(id: 2, name: 'another country') }
|
95
|
-
let(:city) { City.create!(id: 4, country_id: country.id, name: 'city', rating: 42) }
|
96
|
-
|
97
|
-
context 'indexing' do
|
98
|
-
let(:index) { [city] }
|
99
|
-
|
100
|
-
specify do
|
101
|
-
expect(subject.bulk_body).to eq([
|
102
|
-
{index: {_id: city.id, parent: country.id, data: {'name' => 'city', 'rating' => 42}}}
|
103
|
-
])
|
104
|
-
end
|
105
|
-
|
106
|
-
context do
|
107
|
-
let(:fields) { %w[name] }
|
108
|
-
|
109
|
-
specify do
|
110
|
-
expect(subject.bulk_body).to eq([
|
111
|
-
{update: {_id: city.id, parent: country.id, data: {doc: {'name' => 'city'}}}}
|
112
|
-
])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'updating parent' do
|
118
|
-
before do
|
119
|
-
PlacesIndex::City.import(city)
|
120
|
-
city.update_attributes(country_id: another_country.id)
|
121
|
-
end
|
122
|
-
let(:index) { [city] }
|
123
|
-
|
124
|
-
specify do
|
125
|
-
expect(subject.bulk_body).to eq([
|
126
|
-
{delete: {_id: city.id, parent: country.id.to_s}},
|
127
|
-
{index: {_id: city.id, parent: another_country.id, data: {'name' => 'city', 'rating' => 42}}}
|
128
|
-
])
|
129
|
-
end
|
130
|
-
|
131
|
-
context do
|
132
|
-
let(:fields) { %w[name] }
|
133
|
-
|
134
|
-
specify do
|
135
|
-
expect(subject.bulk_body).to eq([
|
136
|
-
{delete: {_id: city.id, parent: country.id.to_s}},
|
137
|
-
{index: {_id: city.id, parent: another_country.id, data: {'name' => 'city', 'rating' => 42}}}
|
138
|
-
])
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'destroying' do
|
144
|
-
before { PlacesIndex::City.import(city) }
|
145
|
-
let(:delete) { [city] }
|
146
|
-
|
147
|
-
specify do
|
148
|
-
expect(subject.bulk_body).to eq([
|
149
|
-
{delete: {_id: city.id, parent: country.id.to_s}}
|
150
|
-
])
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
70
|
context 'custom id', :orm do
|
156
71
|
before do
|
157
72
|
stub_model(:city)
|
158
73
|
end
|
159
74
|
|
160
75
|
before do
|
161
|
-
stub_index(:
|
76
|
+
stub_index(:cities) do
|
162
77
|
define_type City do
|
163
78
|
root id: -> { name } do
|
164
79
|
field :rating
|
@@ -170,8 +85,8 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
170
85
|
let(:london) { City.create(id: 1, name: 'London', rating: 4) }
|
171
86
|
|
172
87
|
specify do
|
173
|
-
expect {
|
174
|
-
.to update_index(
|
88
|
+
expect { CitiesIndex.import(london) }
|
89
|
+
.to update_index(CitiesIndex).and_reindex(london.name)
|
175
90
|
end
|
176
91
|
|
177
92
|
context 'indexing' do
|
@@ -197,7 +112,7 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
197
112
|
|
198
113
|
context 'crutches' do
|
199
114
|
before do
|
200
|
-
stub_index(:
|
115
|
+
stub_index(:cities) do
|
201
116
|
define_type :city do
|
202
117
|
crutch :names do |collection|
|
203
118
|
collection.map { |item| [item.id, "Name#{item.id}"] }.to_h
|
@@ -217,7 +132,7 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
217
132
|
end
|
218
133
|
|
219
134
|
context 'witchcraft' do
|
220
|
-
before {
|
135
|
+
before { CitiesIndex::City.witchcraft! }
|
221
136
|
specify do
|
222
137
|
expect(subject.bulk_body).to eq([
|
223
138
|
{index: {_id: 42, data: {'name' => 'Name42'}}}
|
@@ -228,7 +143,7 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
228
143
|
|
229
144
|
context 'empty ids' do
|
230
145
|
before do
|
231
|
-
stub_index(:
|
146
|
+
stub_index(:cities) do
|
232
147
|
define_type :city do
|
233
148
|
field :name
|
234
149
|
end
|
@@ -264,7 +179,7 @@ describe Chewy::Type::Import::BulkBuilder do
|
|
264
179
|
|
265
180
|
describe '#index_objects_by_id' do
|
266
181
|
before do
|
267
|
-
stub_index(:
|
182
|
+
stub_index(:cities) do
|
268
183
|
define_type :city do
|
269
184
|
field :name
|
270
185
|
end
|