chewy 5.1.0 → 7.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +73 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +449 -347
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +3 -7
- data/Guardfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +423 -311
- data/chewy.gemspec +8 -10
- data/gemfiles/rails.5.2.activerecord.gemfile +9 -14
- 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 +42 -60
- data/lib/chewy/errors.rb +4 -10
- data/lib/chewy/fields/base.rb +80 -20
- data/lib/chewy/fields/root.rb +7 -17
- data/lib/chewy/index/actions.rb +62 -35
- data/lib/chewy/{type → index}/adapter/active_record.rb +18 -4
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- 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/{type → index}/crutch.rb +5 -5
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -7
- data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
- data/lib/chewy/{type → index}/import/routine.rb +17 -16
- data/lib/chewy/{type → index}/import.rb +51 -33
- data/lib/chewy/{type → index}/mapping.rb +32 -37
- 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/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +61 -62
- data/lib/chewy/{type → index}/witchcraft.rb +15 -9
- data/lib/chewy/{type → index}/wrapper.rb +13 -3
- data/lib/chewy/index.rb +46 -96
- data/lib/chewy/journal.rb +25 -14
- data/lib/chewy/minitest/helpers.rb +86 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +6 -20
- data/lib/chewy/rake_helper.rb +136 -108
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +55 -44
- 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/collapse.rb +16 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/indices.rb +12 -57
- 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 +7 -4
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +180 -154
- data/lib/chewy/search/response.rb +5 -5
- data/lib/chewy/search/scoping.rb +7 -8
- data/lib/chewy/search/scrolling.rb +16 -13
- data/lib/chewy/search.rb +7 -22
- data/lib/chewy/stash.rb +19 -30
- data/lib/chewy/strategy/active_job.rb +2 -2
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +10 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +3 -2
- data/lib/chewy/strategy.rb +5 -19
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +36 -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 +15 -61
- data/spec/chewy/fields/base_spec.rb +432 -145
- data/spec/chewy/fields/root_spec.rb +20 -28
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +388 -55
- 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 +14 -22
- data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
- data/spec/chewy/{type → index}/import_spec.rb +149 -96
- 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 +20 -30
- 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 +69 -137
- data/spec/chewy/journal_spec.rb +46 -91
- 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 +293 -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 +26 -118
- 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 +23 -7
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +344 -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 +69 -59
- 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/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 +6 -29
- data/spec/support/active_record.rb +43 -5
- metadata +102 -198
- data/.travis.yml +0 -45
- data/Appraisals +0 -81
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.mongoid.6.1.gemfile +0 -16
- data/gemfiles/rails.5.1.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
- 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 -244
- data/lib/chewy/query/loading.rb +0 -110
- 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 -1142
- 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 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/chewy/type/import/bulk_builder.rb +0 -122
- data/lib/chewy/type/observe.rb +0 -82
- data/lib/chewy/type.rb +0 -117
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- 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 -14
- 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 -637
- 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/types_spec.rb +0 -5
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -66
- 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 -173
- 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
@@ -4,27 +4,31 @@ describe Chewy::RakeHelper, :orm do
|
|
4
4
|
before { Chewy.massacre }
|
5
5
|
|
6
6
|
before do
|
7
|
+
described_class.instance_variable_set(:@journal_exists, journal_exists)
|
8
|
+
|
7
9
|
stub_model(:city)
|
8
10
|
stub_model(:country)
|
9
11
|
|
10
|
-
stub_index(:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
stub_index(:cities) do
|
13
|
+
index_scope City
|
14
|
+
field :name
|
15
|
+
field :updated_at, type: 'date'
|
16
|
+
end
|
17
|
+
stub_index(:countries) do
|
18
|
+
index_scope Country
|
16
19
|
end
|
17
20
|
stub_index(:users)
|
18
21
|
|
19
|
-
allow(described_class).to receive(:all_indexes) { [
|
22
|
+
allow(described_class).to receive(:all_indexes) { [CitiesIndex, CountriesIndex, UsersIndex] }
|
20
23
|
end
|
21
24
|
|
25
|
+
let(:journal_exists) { true }
|
22
26
|
let!(:cities) { Array.new(3) { |i| City.create!(name: "Name#{i + 1}") } }
|
23
27
|
let!(:countries) { Array.new(2) { |i| Country.create!(name: "Name#{i + 1}") } }
|
24
28
|
let(:journal) do
|
25
29
|
Chewy::Stash::Journal.import([
|
26
30
|
{
|
27
|
-
index_name: '
|
31
|
+
index_name: 'cities',
|
28
32
|
type_name: 'city',
|
29
33
|
action: 'index',
|
30
34
|
references: cities.first(2).map(&:id).map(&:to_s)
|
@@ -32,7 +36,7 @@ describe Chewy::RakeHelper, :orm do
|
|
32
36
|
created_at: 2.minutes.since
|
33
37
|
},
|
34
38
|
{
|
35
|
-
index_name: '
|
39
|
+
index_name: 'countries',
|
36
40
|
type_name: 'country',
|
37
41
|
action: 'index',
|
38
42
|
references: [Base64.encode64(countries.first.id.to_s.to_json)],
|
@@ -47,87 +51,115 @@ describe Chewy::RakeHelper, :orm do
|
|
47
51
|
specify do
|
48
52
|
output = StringIO.new
|
49
53
|
expect { described_class.reset(output: output) }
|
50
|
-
.to update_index(
|
54
|
+
.to update_index(CitiesIndex)
|
51
55
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
52
|
-
\\AResetting
|
53
|
-
Imported
|
54
|
-
|
55
|
-
|
56
|
-
Imported
|
57
|
-
|
58
|
-
Imported
|
56
|
+
\\AResetting CitiesIndex
|
57
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
58
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
59
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
60
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
61
|
+
Resetting CountriesIndex
|
62
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
63
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
64
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
65
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
59
66
|
Resetting UsersIndex
|
60
|
-
Imported
|
67
|
+
Imported UsersIndex in 1s, stats:\s
|
68
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
61
69
|
Total: \\d+s\\Z
|
62
70
|
OUTPUT
|
63
71
|
end
|
64
72
|
|
65
73
|
specify do
|
66
74
|
output = StringIO.new
|
67
|
-
expect { described_class.reset(only: '
|
68
|
-
.to update_index(
|
75
|
+
expect { described_class.reset(only: 'cities', output: output) }
|
76
|
+
.to update_index(CitiesIndex)
|
69
77
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
70
|
-
\\AResetting
|
71
|
-
Imported
|
72
|
-
|
73
|
-
|
74
|
-
Imported
|
75
|
-
Imported PlacesIndex::Country in \\d+s, stats: index 1
|
76
|
-
Imported Chewy::Stash::Specification::Specification in \\d+s, stats: index 1
|
78
|
+
\\AResetting CitiesIndex
|
79
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
80
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
81
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
82
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
77
83
|
Total: \\d+s\\Z
|
78
84
|
OUTPUT
|
79
85
|
end
|
80
86
|
|
81
87
|
specify do
|
82
88
|
output = StringIO.new
|
83
|
-
expect { described_class.reset(except:
|
84
|
-
.not_to update_index(
|
89
|
+
expect { described_class.reset(except: [CitiesIndex, CountriesIndex], output: output) }
|
90
|
+
.not_to update_index(CitiesIndex)
|
85
91
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
86
92
|
\\AResetting UsersIndex
|
87
|
-
Imported
|
93
|
+
Imported UsersIndex in 1s, stats:\s
|
94
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
88
95
|
Total: \\d+s\\Z
|
89
96
|
OUTPUT
|
90
97
|
end
|
98
|
+
|
99
|
+
context 'when journal is missing' do
|
100
|
+
let(:journal_exists) { false }
|
101
|
+
|
102
|
+
specify do
|
103
|
+
output = StringIO.new
|
104
|
+
expect { described_class.reset(only: [CitiesIndex], output: output) }
|
105
|
+
.to update_index(CitiesIndex)
|
106
|
+
expect(output.string).to include(
|
107
|
+
"############################################################\n"\
|
108
|
+
"WARN: You are risking to lose some changes during the reset.\n" \
|
109
|
+
" Please consider enabling journaling.\n" \
|
110
|
+
' See https://github.com/toptal/chewy#journaling'
|
111
|
+
)
|
112
|
+
end
|
113
|
+
end
|
91
114
|
end
|
92
115
|
|
93
116
|
describe '.upgrade' do
|
94
117
|
specify do
|
95
118
|
output = StringIO.new
|
96
119
|
expect { described_class.upgrade(output: output) }
|
97
|
-
.to update_index(
|
120
|
+
.to update_index(CitiesIndex)
|
98
121
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
99
|
-
\\AResetting
|
100
|
-
Imported
|
101
|
-
Imported
|
102
|
-
|
122
|
+
\\AResetting CitiesIndex
|
123
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
124
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
125
|
+
Resetting CountriesIndex
|
126
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
127
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
103
128
|
Resetting UsersIndex
|
104
|
-
Imported
|
129
|
+
Imported UsersIndex in 1s, stats:\s
|
130
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
105
131
|
Total: \\d+s\\Z
|
106
132
|
OUTPUT
|
107
133
|
end
|
108
134
|
|
109
135
|
context do
|
110
|
-
before
|
136
|
+
before do
|
137
|
+
CitiesIndex.reset!
|
138
|
+
CountriesIndex.reset!
|
139
|
+
end
|
111
140
|
|
112
141
|
specify do
|
113
142
|
output = StringIO.new
|
114
143
|
expect { described_class.upgrade(output: output) }
|
115
|
-
.not_to update_index(
|
144
|
+
.not_to update_index(CitiesIndex)
|
116
145
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
117
|
-
\\ASkipping
|
146
|
+
\\ASkipping CitiesIndex, the specification didn't change
|
147
|
+
Skipping CountriesIndex, the specification didn't change
|
118
148
|
Resetting UsersIndex
|
119
|
-
Imported
|
149
|
+
Imported UsersIndex in 1s, stats:\s
|
150
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
120
151
|
Total: \\d+s\\Z
|
121
152
|
OUTPUT
|
122
153
|
end
|
123
154
|
|
124
155
|
specify do
|
125
156
|
output = StringIO.new
|
126
|
-
expect { described_class.upgrade(except:
|
127
|
-
.not_to update_index(
|
157
|
+
expect { described_class.upgrade(except: [CitiesIndex, CountriesIndex], output: output) }
|
158
|
+
.not_to update_index(CitiesIndex)
|
128
159
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
129
160
|
\\AResetting UsersIndex
|
130
|
-
Imported
|
161
|
+
Imported UsersIndex in 1s, stats:\s
|
162
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
131
163
|
Total: \\d+s\\Z
|
132
164
|
OUTPUT
|
133
165
|
end
|
@@ -137,8 +169,8 @@ Total: \\d+s\\Z
|
|
137
169
|
|
138
170
|
specify do
|
139
171
|
output = StringIO.new
|
140
|
-
expect { described_class.upgrade(except: [
|
141
|
-
.not_to update_index(
|
172
|
+
expect { described_class.upgrade(except: %w[cities countries], output: output) }
|
173
|
+
.not_to update_index(CitiesIndex)
|
142
174
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
143
175
|
\\ANo index specification was changed
|
144
176
|
Total: \\d+s\\Z
|
@@ -152,45 +184,54 @@ Total: \\d+s\\Z
|
|
152
184
|
specify do
|
153
185
|
output = StringIO.new
|
154
186
|
expect { described_class.update(output: output) }
|
155
|
-
.not_to update_index(
|
187
|
+
.not_to update_index(CitiesIndex)
|
156
188
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
157
|
-
\\ASkipping
|
189
|
+
\\ASkipping CitiesIndex, it does not exists \\(use rake chewy:reset\\[cities\\] to create and update it\\)
|
190
|
+
Skipping CountriesIndex, it does not exists \\(use rake chewy:reset\\[countries\\] to create and update it\\)
|
191
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
192
|
+
Total: \\d+s\\Z
|
158
193
|
OUTPUT
|
159
194
|
end
|
160
195
|
|
161
196
|
context do
|
162
|
-
before
|
197
|
+
before do
|
198
|
+
CitiesIndex.reset!
|
199
|
+
CountriesIndex.reset!
|
200
|
+
end
|
163
201
|
|
164
202
|
specify do
|
165
203
|
output = StringIO.new
|
166
204
|
expect { described_class.update(output: output) }
|
167
|
-
.to update_index(
|
205
|
+
.to update_index(CitiesIndex)
|
168
206
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
169
|
-
\\AUpdating
|
170
|
-
Imported
|
171
|
-
|
207
|
+
\\AUpdating CitiesIndex
|
208
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
209
|
+
Updating CountriesIndex
|
210
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
211
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
172
212
|
Total: \\d+s\\Z
|
173
213
|
OUTPUT
|
174
214
|
end
|
175
215
|
|
176
216
|
specify do
|
177
217
|
output = StringIO.new
|
178
|
-
expect { described_class.update(only: '
|
179
|
-
.not_to update_index(
|
218
|
+
expect { described_class.update(only: 'countries', output: output) }
|
219
|
+
.not_to update_index(CitiesIndex)
|
180
220
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
181
|
-
\\AUpdating
|
182
|
-
Imported
|
221
|
+
\\AUpdating CountriesIndex
|
222
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
183
223
|
Total: \\d+s\\Z
|
184
224
|
OUTPUT
|
185
225
|
end
|
186
226
|
|
187
227
|
specify do
|
188
228
|
output = StringIO.new
|
189
|
-
expect { described_class.update(except:
|
190
|
-
.to update_index(
|
229
|
+
expect { described_class.update(except: CountriesIndex, output: output) }
|
230
|
+
.to update_index(CitiesIndex)
|
191
231
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
192
|
-
\\AUpdating
|
193
|
-
Imported
|
232
|
+
\\AUpdating CitiesIndex
|
233
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
234
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
194
235
|
Total: \\d+s\\Z
|
195
236
|
OUTPUT
|
196
237
|
end
|
@@ -201,43 +242,50 @@ Total: \\d+s\\Z
|
|
201
242
|
specify do
|
202
243
|
output = StringIO.new
|
203
244
|
expect { described_class.sync(output: output) }
|
204
|
-
.to update_index(
|
245
|
+
.to update_index(CitiesIndex)
|
205
246
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
206
|
-
\\ASynchronizing
|
207
|
-
Imported
|
247
|
+
\\ASynchronizing CitiesIndex
|
248
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
208
249
|
Missing documents: \\[[^\\]]+\\]
|
209
250
|
Took \\d+s
|
210
|
-
Synchronizing
|
211
|
-
|
212
|
-
Imported
|
251
|
+
Synchronizing CountriesIndex
|
252
|
+
CountriesIndex doesn't support outdated synchronization
|
253
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
213
254
|
Missing documents: \\[[^\\]]+\\]
|
214
255
|
Took \\d+s
|
256
|
+
Synchronizing UsersIndex
|
257
|
+
UsersIndex doesn't support outdated synchronization
|
258
|
+
Skipping UsersIndex, up to date
|
259
|
+
Took \\d+s
|
215
260
|
Total: \\d+s\\Z
|
216
261
|
OUTPUT
|
217
262
|
end
|
218
263
|
|
219
264
|
context do
|
220
265
|
before do
|
221
|
-
|
222
|
-
|
266
|
+
CitiesIndex.import(cities.first(2))
|
267
|
+
CountriesIndex.import
|
223
268
|
|
224
|
-
sleep(1) if ActiveSupport::VERSION::STRING < '4.1.0'
|
225
269
|
cities.first.update(name: 'Name5')
|
226
270
|
end
|
227
271
|
|
228
272
|
specify do
|
229
273
|
output = StringIO.new
|
230
274
|
expect { described_class.sync(output: output) }
|
231
|
-
.to update_index(
|
275
|
+
.to update_index(CitiesIndex)
|
232
276
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
233
|
-
\\ASynchronizing
|
234
|
-
Imported
|
277
|
+
\\ASynchronizing CitiesIndex
|
278
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
235
279
|
Missing documents: \\["#{cities.last.id}"\\]
|
236
280
|
Outdated documents: \\["#{cities.first.id}"\\]
|
237
281
|
Took \\d+s
|
238
|
-
Synchronizing
|
239
|
-
|
240
|
-
Skipping
|
282
|
+
Synchronizing CountriesIndex
|
283
|
+
CountriesIndex doesn't support outdated synchronization
|
284
|
+
Skipping CountriesIndex, up to date
|
285
|
+
Took \\d+s
|
286
|
+
Synchronizing UsersIndex
|
287
|
+
UsersIndex doesn't support outdated synchronization
|
288
|
+
Skipping UsersIndex, up to date
|
241
289
|
Took \\d+s
|
242
290
|
Total: \\d+s\\Z
|
243
291
|
OUTPUT
|
@@ -245,11 +293,11 @@ Total: \\d+s\\Z
|
|
245
293
|
|
246
294
|
specify do
|
247
295
|
output = StringIO.new
|
248
|
-
expect { described_class.sync(only:
|
249
|
-
.to update_index(
|
296
|
+
expect { described_class.sync(only: CitiesIndex, output: output) }
|
297
|
+
.to update_index(CitiesIndex)
|
250
298
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
251
|
-
\\ASynchronizing
|
252
|
-
Imported
|
299
|
+
\\ASynchronizing CitiesIndex
|
300
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
253
301
|
Missing documents: \\["#{cities.last.id}"\\]
|
254
302
|
Outdated documents: \\["#{cities.first.id}"\\]
|
255
303
|
Took \\d+s
|
@@ -259,12 +307,16 @@ Total: \\d+s\\Z
|
|
259
307
|
|
260
308
|
specify do
|
261
309
|
output = StringIO.new
|
262
|
-
expect { described_class.sync(except: ['
|
263
|
-
.not_to update_index(
|
310
|
+
expect { described_class.sync(except: ['cities'], output: output) }
|
311
|
+
.not_to update_index(CitiesIndex)
|
264
312
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
265
|
-
\\ASynchronizing
|
266
|
-
|
267
|
-
Skipping
|
313
|
+
\\ASynchronizing CountriesIndex
|
314
|
+
CountriesIndex doesn't support outdated synchronization
|
315
|
+
Skipping CountriesIndex, up to date
|
316
|
+
Took \\d+s
|
317
|
+
Synchronizing UsersIndex
|
318
|
+
UsersIndex doesn't support outdated synchronization
|
319
|
+
Skipping UsersIndex, up to date
|
268
320
|
Took \\d+s
|
269
321
|
Total: \\d+s\\Z
|
270
322
|
OUTPUT
|
@@ -290,12 +342,12 @@ Total: \\d+s\\Z
|
|
290
342
|
specify do
|
291
343
|
output = StringIO.new
|
292
344
|
expect { described_class.journal_apply(time: Time.now, output: output) }
|
293
|
-
.to update_index(
|
345
|
+
.to update_index(CitiesIndex)
|
294
346
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
295
347
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
296
|
-
Applying journal to \\[
|
297
|
-
Imported
|
298
|
-
Imported
|
348
|
+
Applying journal to \\[CitiesIndex, CountriesIndex\\], 3 entries, stage 1
|
349
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
350
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
299
351
|
Total: \\d+s\\Z
|
300
352
|
OUTPUT
|
301
353
|
end
|
@@ -303,35 +355,35 @@ Total: \\d+s\\Z
|
|
303
355
|
specify do
|
304
356
|
output = StringIO.new
|
305
357
|
expect { described_class.journal_apply(time: 3.minutes.since, output: output) }
|
306
|
-
.not_to update_index(
|
358
|
+
.not_to update_index(CitiesIndex)
|
307
359
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
308
360
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
309
|
-
Applying journal to \\[
|
310
|
-
Imported
|
361
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
362
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
311
363
|
Total: \\d+s\\Z
|
312
364
|
OUTPUT
|
313
365
|
end
|
314
366
|
|
315
367
|
specify do
|
316
368
|
output = StringIO.new
|
317
|
-
expect { described_class.journal_apply(time: Time.now, only:
|
318
|
-
.to update_index(
|
369
|
+
expect { described_class.journal_apply(time: Time.now, only: CitiesIndex, output: output) }
|
370
|
+
.to update_index(CitiesIndex)
|
319
371
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
320
372
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
321
|
-
Applying journal to \\[
|
322
|
-
Imported
|
373
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
374
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
323
375
|
Total: \\d+s\\Z
|
324
376
|
OUTPUT
|
325
377
|
end
|
326
378
|
|
327
379
|
specify do
|
328
380
|
output = StringIO.new
|
329
|
-
expect { described_class.journal_apply(time: Time.now, except:
|
330
|
-
.not_to update_index(
|
381
|
+
expect { described_class.journal_apply(time: Time.now, except: CitiesIndex, output: output) }
|
382
|
+
.not_to update_index(CitiesIndex)
|
331
383
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
332
384
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
333
|
-
Applying journal to \\[
|
334
|
-
Imported
|
385
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
386
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
335
387
|
Total: \\d+s\\Z
|
336
388
|
OUTPUT
|
337
389
|
end
|
@@ -362,7 +414,7 @@ Total: \\d+s\\Z
|
|
362
414
|
|
363
415
|
specify do
|
364
416
|
output = StringIO.new
|
365
|
-
described_class.journal_clean(only:
|
417
|
+
described_class.journal_clean(only: CitiesIndex, output: output)
|
366
418
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
367
419
|
\\ACleaned up 1 journal entries
|
368
420
|
Total: \\d+s\\Z
|
@@ -371,11 +423,151 @@ Total: \\d+s\\Z
|
|
371
423
|
|
372
424
|
specify do
|
373
425
|
output = StringIO.new
|
374
|
-
described_class.journal_clean(except:
|
426
|
+
described_class.journal_clean(except: CitiesIndex, output: output)
|
375
427
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
376
428
|
\\ACleaned up 1 journal entries
|
377
429
|
Total: \\d+s\\Z
|
378
430
|
OUTPUT
|
379
431
|
end
|
432
|
+
|
433
|
+
it 'executes asynchronously' do
|
434
|
+
output = StringIO.new
|
435
|
+
expect(Chewy.client).to receive(:delete_by_query).with(
|
436
|
+
{
|
437
|
+
body: {query: {match_all: {}}},
|
438
|
+
index: ['chewy_journal'],
|
439
|
+
refresh: false,
|
440
|
+
requests_per_second: 10.0,
|
441
|
+
scroll_size: 200,
|
442
|
+
wait_for_completion: false
|
443
|
+
}
|
444
|
+
).and_call_original
|
445
|
+
described_class.journal_clean(
|
446
|
+
output: output,
|
447
|
+
delete_by_query_options: {
|
448
|
+
wait_for_completion: false,
|
449
|
+
requests_per_second: 10.0,
|
450
|
+
scroll_size: 200
|
451
|
+
}
|
452
|
+
)
|
453
|
+
|
454
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
455
|
+
\\ATask to cleanup the journal has been created, [^\\n]*
|
456
|
+
Total: \\d+s\\Z
|
457
|
+
OUTPUT
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
describe '.reindex' do
|
462
|
+
before do
|
463
|
+
journal
|
464
|
+
CitiesIndex.create!
|
465
|
+
CountriesIndex.create!
|
466
|
+
end
|
467
|
+
|
468
|
+
let(:source_index) { 'cities' }
|
469
|
+
let(:dest_index) { 'countries' }
|
470
|
+
|
471
|
+
context 'with correct arguments' do
|
472
|
+
specify do
|
473
|
+
output = StringIO.new
|
474
|
+
described_class.reindex(source: source_index, dest: dest_index, output: output)
|
475
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
476
|
+
\\Source index is cities
|
477
|
+
\\Destination index is countries
|
478
|
+
cities index successfully reindexed with countries index data
|
479
|
+
Total: \\d+s\\Z
|
480
|
+
OUTPUT
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
context 'with missing indexes' do
|
485
|
+
context 'without dest index' do
|
486
|
+
specify do
|
487
|
+
output = StringIO.new
|
488
|
+
expect { described_class.reindex(source: source_index, output: output) }
|
489
|
+
.to raise_error ArgumentError
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
context 'without source index' do
|
494
|
+
specify do
|
495
|
+
output = StringIO.new
|
496
|
+
expect { described_class.reindex(dest: dest_index, output: output) }
|
497
|
+
.to raise_error ArgumentError
|
498
|
+
end
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
describe '.update_mapping' do
|
504
|
+
before do
|
505
|
+
journal
|
506
|
+
CitiesIndex.create!
|
507
|
+
end
|
508
|
+
|
509
|
+
let(:index_name) { CitiesIndex.index_name }
|
510
|
+
let(:nonexistent_index) { 'wrong_index' }
|
511
|
+
|
512
|
+
context 'with existing index' do
|
513
|
+
specify do
|
514
|
+
output = StringIO.new
|
515
|
+
described_class.update_mapping(name: index_name, output: output)
|
516
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
517
|
+
\\Index name is cities
|
518
|
+
cities index successfully updated
|
519
|
+
Total: \\d+s\\Z
|
520
|
+
OUTPUT
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
context 'with non-existent index name' do
|
525
|
+
specify do
|
526
|
+
output = StringIO.new
|
527
|
+
expect { described_class.update_mapping(name: nonexistent_index, output: output) }
|
528
|
+
.to raise_error NameError
|
529
|
+
end
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
describe '.delete_by_query_options_from_env' do
|
534
|
+
subject(:options) { described_class.delete_by_query_options_from_env(env) }
|
535
|
+
let(:env) do
|
536
|
+
{
|
537
|
+
'WAIT_FOR_COMPLETION' => 'false',
|
538
|
+
'REQUESTS_PER_SECOND' => '10',
|
539
|
+
'SCROLL_SIZE' => '5000'
|
540
|
+
}
|
541
|
+
end
|
542
|
+
|
543
|
+
it 'parses the options' do
|
544
|
+
expect(options).to eq(
|
545
|
+
wait_for_completion: false,
|
546
|
+
requests_per_second: 10.0,
|
547
|
+
scroll_size: 5000
|
548
|
+
)
|
549
|
+
end
|
550
|
+
|
551
|
+
context 'with different boolean values' do
|
552
|
+
it 'parses the option correctly' do
|
553
|
+
%w[1 t true TRUE on ON].each do |v|
|
554
|
+
expect(described_class.delete_by_query_options_from_env({'WAIT_FOR_COMPLETION' => v}))
|
555
|
+
.to eq(wait_for_completion: true)
|
556
|
+
end
|
557
|
+
|
558
|
+
%w[0 f false FALSE off OFF].each do |v|
|
559
|
+
expect(described_class.delete_by_query_options_from_env({'WAIT_FOR_COMPLETION' => v}))
|
560
|
+
.to eq(wait_for_completion: false)
|
561
|
+
end
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
context 'with other env' do
|
566
|
+
let(:env) { {'SOME_ENV' => '123', 'REQUESTS_PER_SECOND' => '15'} }
|
567
|
+
|
568
|
+
it 'parses only the options' do
|
569
|
+
expect(options).to eq(requests_per_second: 15.0)
|
570
|
+
end
|
571
|
+
end
|
380
572
|
end
|
381
573
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe :build_query do
|
4
|
+
before do
|
5
|
+
stub_model(:city)
|
6
|
+
stub_index(:cities) { index_scope City }
|
7
|
+
CitiesIndex.create
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:expected_query) do
|
11
|
+
{
|
12
|
+
index: ['cities'],
|
13
|
+
body: {
|
14
|
+
query: {
|
15
|
+
match: {name: 'name'}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
let(:dummy_query) { {match: {name: 'name'}} }
|
21
|
+
let(:unexpected_query) { {match: {name: 'name'}} }
|
22
|
+
|
23
|
+
context 'build expected query' do
|
24
|
+
specify do
|
25
|
+
expect(CitiesIndex.query(dummy_query)).to build_query(expected_query)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'not to build unexpected query' do
|
30
|
+
specify do
|
31
|
+
expect(CitiesIndex.query(dummy_query)).not_to build_query(unexpected_query)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|