chewy 0.8.4 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +56 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +36 -67
- data/.yardopts +5 -0
- data/Appraisals +63 -58
- data/CHANGELOG.md +168 -11
- data/Gemfile +16 -9
- data/Guardfile +5 -5
- data/LEGACY_DSL.md +497 -0
- data/README.md +403 -470
- data/Rakefile +11 -1
- data/chewy.gemspec +12 -15
- data/gemfiles/rails.4.0.activerecord.gemfile +9 -9
- data/gemfiles/rails.4.1.activerecord.gemfile +9 -9
- data/gemfiles/rails.4.2.activerecord.gemfile +8 -8
- data/gemfiles/rails.4.2.mongoid.5.2.gemfile +16 -0
- data/gemfiles/rails.5.0.activerecord.gemfile +16 -0
- data/gemfiles/rails.5.0.mongoid.6.1.gemfile +16 -0
- data/gemfiles/rails.5.1.activerecord.gemfile +16 -0
- data/gemfiles/rails.5.1.mongoid.6.3.gemfile +16 -0
- data/gemfiles/rails.5.2.activerecord.gemfile +16 -0
- data/gemfiles/sequel.4.45.gemfile +11 -0
- data/lib/chewy/backports/deep_dup.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -0
- data/lib/chewy/config.rb +53 -21
- data/lib/chewy/errors.rb +6 -6
- data/lib/chewy/fields/base.rb +59 -29
- data/lib/chewy/fields/root.rb +49 -14
- data/lib/chewy/index/actions.rb +95 -36
- data/lib/chewy/index/aliases.rb +2 -1
- data/lib/chewy/index/settings.rb +10 -5
- data/lib/chewy/index/specification.rb +60 -0
- data/lib/chewy/index.rb +239 -138
- data/lib/chewy/journal.rb +55 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +77 -0
- data/lib/chewy/minitest/search_index_receiver.rb +80 -0
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/query/compose.rb +18 -19
- data/lib/chewy/query/criteria.rb +34 -24
- data/lib/chewy/query/filters.rb +28 -11
- data/lib/chewy/query/loading.rb +3 -4
- data/lib/chewy/query/nodes/and.rb +1 -1
- data/lib/chewy/query/nodes/base.rb +1 -1
- data/lib/chewy/query/nodes/bool.rb +6 -4
- data/lib/chewy/query/nodes/equal.rb +4 -4
- data/lib/chewy/query/nodes/exists.rb +1 -1
- data/lib/chewy/query/nodes/expr.rb +2 -2
- data/lib/chewy/query/nodes/field.rb +35 -31
- data/lib/chewy/query/nodes/has_child.rb +1 -0
- data/lib/chewy/query/nodes/has_parent.rb +1 -0
- data/lib/chewy/query/nodes/has_relation.rb +10 -12
- data/lib/chewy/query/nodes/missing.rb +1 -1
- data/lib/chewy/query/nodes/not.rb +1 -1
- data/lib/chewy/query/nodes/or.rb +1 -1
- data/lib/chewy/query/nodes/prefix.rb +3 -2
- data/lib/chewy/query/nodes/query.rb +1 -1
- data/lib/chewy/query/nodes/range.rb +9 -9
- data/lib/chewy/query/nodes/raw.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +13 -9
- data/lib/chewy/query/nodes/script.rb +4 -4
- data/lib/chewy/query/pagination.rb +10 -1
- data/lib/chewy/query.rb +286 -170
- data/lib/chewy/railtie.rb +7 -6
- data/lib/chewy/rake_helper.rb +275 -37
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec/update_index.rb +70 -65
- data/lib/chewy/rspec.rb +1 -1
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/search/loader.rb +83 -0
- data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
- data/lib/chewy/search/pagination/will_paginate.rb +43 -0
- data/lib/chewy/search/parameters/aggs.rb +16 -0
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/concerns/bool_storage.rb +24 -0
- data/lib/chewy/search/parameters/concerns/hash_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/integer_storage.rb +14 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +238 -0
- data/lib/chewy/search/parameters/concerns/string_array_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/string_storage.rb +14 -0
- data/lib/chewy/search/parameters/docvalue_fields.rb +12 -0
- data/lib/chewy/search/parameters/explain.rb +16 -0
- data/lib/chewy/search/parameters/filter.rb +47 -0
- data/lib/chewy/search/parameters/highlight.rb +16 -0
- data/lib/chewy/search/parameters/indices.rb +123 -0
- data/lib/chewy/search/parameters/indices_boost.rb +52 -0
- data/lib/chewy/search/parameters/limit.rb +17 -0
- data/lib/chewy/search/parameters/load.rb +32 -0
- data/lib/chewy/search/parameters/min_score.rb +16 -0
- data/lib/chewy/search/parameters/none.rb +27 -0
- data/lib/chewy/search/parameters/offset.rb +17 -0
- data/lib/chewy/search/parameters/order.rb +64 -0
- data/lib/chewy/search/parameters/post_filter.rb +19 -0
- data/lib/chewy/search/parameters/preference.rb +16 -0
- data/lib/chewy/search/parameters/profile.rb +16 -0
- data/lib/chewy/search/parameters/query.rb +19 -0
- data/lib/chewy/search/parameters/request_cache.rb +27 -0
- data/lib/chewy/search/parameters/rescore.rb +29 -0
- data/lib/chewy/search/parameters/script_fields.rb +16 -0
- data/lib/chewy/search/parameters/search_after.rb +20 -0
- data/lib/chewy/search/parameters/search_type.rb +16 -0
- data/lib/chewy/search/parameters/source.rb +73 -0
- data/lib/chewy/search/parameters/storage.rb +95 -0
- data/lib/chewy/search/parameters/stored_fields.rb +63 -0
- data/lib/chewy/search/parameters/suggest.rb +16 -0
- data/lib/chewy/search/parameters/terminate_after.rb +16 -0
- data/lib/chewy/search/parameters/timeout.rb +16 -0
- data/lib/chewy/search/parameters/track_scores.rb +16 -0
- data/lib/chewy/search/parameters/types.rb +20 -0
- data/lib/chewy/search/parameters/version.rb +16 -0
- data/lib/chewy/search/parameters.rb +167 -0
- data/lib/chewy/search/query_proxy.rb +257 -0
- data/lib/chewy/search/request.rb +1045 -0
- data/lib/chewy/search/response.rb +119 -0
- data/lib/chewy/search/scoping.rb +50 -0
- data/lib/chewy/search/scrolling.rb +134 -0
- data/lib/chewy/search.rb +81 -26
- data/lib/chewy/stash.rb +79 -0
- data/lib/chewy/strategy/active_job.rb +1 -0
- data/lib/chewy/strategy/atomic.rb +2 -4
- data/lib/chewy/strategy/base.rb +4 -4
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/resque.rb +1 -0
- data/lib/chewy/strategy/shoryuken.rb +40 -0
- data/lib/chewy/strategy/sidekiq.rb +13 -1
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/strategy.rb +19 -10
- data/lib/chewy/type/actions.rb +26 -2
- data/lib/chewy/type/adapter/active_record.rb +50 -24
- data/lib/chewy/type/adapter/base.rb +29 -9
- data/lib/chewy/type/adapter/mongoid.rb +19 -10
- data/lib/chewy/type/adapter/object.rb +195 -31
- data/lib/chewy/type/adapter/orm.rb +69 -33
- data/lib/chewy/type/adapter/sequel.rb +37 -19
- data/lib/chewy/type/crutch.rb +5 -4
- data/lib/chewy/type/import/bulk_builder.rb +122 -0
- data/lib/chewy/type/import/bulk_request.rb +78 -0
- data/lib/chewy/type/import/journal_builder.rb +45 -0
- data/lib/chewy/type/import/routine.rb +138 -0
- data/lib/chewy/type/import.rb +150 -176
- data/lib/chewy/type/mapping.rb +58 -42
- data/lib/chewy/type/observe.rb +21 -15
- data/lib/chewy/type/syncer.rb +222 -0
- data/lib/chewy/type/witchcraft.rb +89 -34
- data/lib/chewy/type/wrapper.rb +48 -16
- data/lib/chewy/type.rb +77 -49
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +95 -52
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/lib/tasks/chewy.rake +91 -28
- data/spec/chewy/config_spec.rb +130 -12
- data/spec/chewy/fields/base_spec.rb +194 -172
- data/spec/chewy/fields/root_spec.rb +123 -17
- data/spec/chewy/fields/time_fields_spec.rb +10 -9
- data/spec/chewy/index/actions_spec.rb +228 -43
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +100 -49
- data/spec/chewy/index/specification_spec.rb +169 -0
- data/spec/chewy/index_spec.rb +159 -63
- data/spec/chewy/journal_spec.rb +268 -0
- data/spec/chewy/minitest/helpers_spec.rb +90 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
- data/spec/chewy/query/criteria_spec.rb +503 -236
- data/spec/chewy/query/filters_spec.rb +96 -68
- data/spec/chewy/query/loading_spec.rb +80 -42
- data/spec/chewy/query/nodes/and_spec.rb +3 -7
- data/spec/chewy/query/nodes/bool_spec.rb +5 -13
- data/spec/chewy/query/nodes/equal_spec.rb +20 -20
- data/spec/chewy/query/nodes/exists_spec.rb +7 -7
- data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
- data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
- data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
- data/spec/chewy/query/nodes/missing_spec.rb +6 -5
- data/spec/chewy/query/nodes/not_spec.rb +5 -7
- data/spec/chewy/query/nodes/or_spec.rb +3 -7
- data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
- data/spec/chewy/query/nodes/query_spec.rb +3 -3
- data/spec/chewy/query/nodes/range_spec.rb +19 -19
- data/spec/chewy/query/nodes/raw_spec.rb +2 -2
- data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
- data/spec/chewy/query/nodes/script_spec.rb +5 -5
- data/spec/chewy/query/pagination/kaminari_spec.rb +3 -55
- data/spec/chewy/query/pagination/will_paginate_spec.rb +5 -0
- data/spec/chewy/query/pagination_spec.rb +25 -22
- data/spec/chewy/query_spec.rb +510 -505
- data/spec/chewy/rake_helper_spec.rb +381 -0
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/update_index_spec.rb +215 -113
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +117 -0
- data/spec/chewy/search/pagination/kaminari_examples.rb +71 -0
- data/spec/chewy/search/pagination/kaminari_spec.rb +21 -0
- data/spec/chewy/search/pagination/will_paginate_examples.rb +63 -0
- data/spec/chewy/search/pagination/will_paginate_spec.rb +23 -0
- data/spec/chewy/search/parameters/aggs_spec.rb +5 -0
- data/spec/chewy/search/parameters/bool_storage_examples.rb +53 -0
- data/spec/chewy/search/parameters/docvalue_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/explain_spec.rb +5 -0
- data/spec/chewy/search/parameters/filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/hash_storage_examples.rb +59 -0
- data/spec/chewy/search/parameters/highlight_spec.rb +5 -0
- data/spec/chewy/search/parameters/indices_spec.rb +191 -0
- data/spec/chewy/search/parameters/integer_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/limit_spec.rb +5 -0
- data/spec/chewy/search/parameters/load_spec.rb +60 -0
- data/spec/chewy/search/parameters/min_score_spec.rb +32 -0
- data/spec/chewy/search/parameters/none_spec.rb +5 -0
- data/spec/chewy/search/parameters/offset_spec.rb +5 -0
- data/spec/chewy/search/parameters/order_spec.rb +65 -0
- data/spec/chewy/search/parameters/post_filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/preference_spec.rb +5 -0
- data/spec/chewy/search/parameters/profile_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_storage_examples.rb +388 -0
- data/spec/chewy/search/parameters/request_cache_spec.rb +67 -0
- data/spec/chewy/search/parameters/rescore_spec.rb +62 -0
- data/spec/chewy/search/parameters/script_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/search_after_spec.rb +32 -0
- data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
- data/spec/chewy/search/parameters/source_spec.rb +156 -0
- data/spec/chewy/search/parameters/storage_spec.rb +60 -0
- data/spec/chewy/search/parameters/stored_fields_spec.rb +126 -0
- data/spec/chewy/search/parameters/string_array_storage_examples.rb +63 -0
- data/spec/chewy/search/parameters/string_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/suggest_spec.rb +5 -0
- data/spec/chewy/search/parameters/terminate_after_spec.rb +5 -0
- data/spec/chewy/search/parameters/timeout_spec.rb +5 -0
- data/spec/chewy/search/parameters/track_scores_spec.rb +5 -0
- data/spec/chewy/search/parameters/types_spec.rb +5 -0
- data/spec/chewy/search/parameters/version_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +145 -0
- data/spec/chewy/search/query_proxy_spec.rb +68 -0
- data/spec/chewy/search/request_spec.rb +685 -0
- data/spec/chewy/search/response_spec.rb +192 -0
- data/spec/chewy/search/scrolling_spec.rb +169 -0
- data/spec/chewy/search_spec.rb +37 -20
- data/spec/chewy/stash_spec.rb +95 -0
- data/spec/chewy/strategy/active_job_spec.rb +8 -2
- data/spec/chewy/strategy/atomic_spec.rb +4 -1
- data/spec/chewy/strategy/resque_spec.rb +8 -2
- data/spec/chewy/strategy/shoryuken_spec.rb +66 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +10 -2
- data/spec/chewy/strategy_spec.rb +6 -6
- data/spec/chewy/type/actions_spec.rb +29 -10
- data/spec/chewy/type/adapter/active_record_spec.rb +357 -139
- data/spec/chewy/type/adapter/mongoid_spec.rb +220 -101
- data/spec/chewy/type/adapter/object_spec.rb +129 -40
- data/spec/chewy/type/adapter/sequel_spec.rb +304 -152
- data/spec/chewy/type/import/bulk_builder_spec.rb +279 -0
- data/spec/chewy/type/import/bulk_request_spec.rb +102 -0
- data/spec/chewy/type/import/journal_builder_spec.rb +95 -0
- data/spec/chewy/type/import/routine_spec.rb +110 -0
- data/spec/chewy/type/import_spec.rb +360 -244
- data/spec/chewy/type/mapping_spec.rb +96 -29
- data/spec/chewy/type/observe_spec.rb +25 -15
- data/spec/chewy/type/syncer_spec.rb +123 -0
- data/spec/chewy/type/witchcraft_spec.rb +122 -44
- data/spec/chewy/type/wrapper_spec.rb +63 -23
- data/spec/chewy/type_spec.rb +32 -10
- data/spec/chewy_spec.rb +82 -12
- data/spec/spec_helper.rb +16 -2
- data/spec/support/active_record.rb +6 -2
- data/spec/support/class_helpers.rb +4 -19
- data/spec/support/mongoid.rb +17 -5
- data/spec/support/sequel.rb +6 -1
- metadata +250 -57
- data/gemfiles/rails.3.2.activerecord.gemfile +0 -15
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/sequel.4.31.gemfile +0 -13
- data/lib/chewy/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/scoping.rb +0 -20
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -60
data/spec/chewy/index_spec.rb
CHANGED
@@ -18,8 +18,8 @@ describe Chewy::Index do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
let!(:cities) { 2
|
22
|
-
let!(:countries) { 2
|
21
|
+
let!(:cities) { Array.new(2) { |i| City.create! id: i + 1 } }
|
22
|
+
let!(:countries) { Array.new(2) { |i| Country.create! id: i + 1 } }
|
23
23
|
|
24
24
|
specify do
|
25
25
|
expect { PlacesIndex.import }.to update_index(PlacesIndex::City).and_reindex(cities)
|
@@ -61,16 +61,28 @@ describe Chewy::Index do
|
|
61
61
|
specify { expect(stub_const('DeveloperIndex', Class.new(Chewy::Index)).index_name).to eq('developer') }
|
62
62
|
specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name).to eq('developers') }
|
63
63
|
|
64
|
+
specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name(suffix: '')).to eq('developers') }
|
65
|
+
specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name(suffix: '2013')).to eq('developers_2013') }
|
66
|
+
specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name(prefix: '')).to eq('developers') }
|
67
|
+
specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name(prefix: 'test')).to eq('test_developers') }
|
68
|
+
|
64
69
|
context do
|
65
70
|
before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
|
66
71
|
specify { expect(DummiesIndex.index_name).to eq('testing_dummies') }
|
67
72
|
specify { expect(stub_index(:dummies) { index_name :users }.index_name).to eq('testing_users') }
|
73
|
+
specify { expect(stub_index(:dummies) { index_name :users }.index_name(prefix: '')).to eq('users') }
|
68
74
|
end
|
69
75
|
end
|
70
76
|
|
71
|
-
describe '.
|
77
|
+
describe '.derivable_name' do
|
78
|
+
specify { expect(Class.new(Chewy::Index).derivable_name).to be_nil }
|
79
|
+
specify { expect(stub_index(:places).derivable_name).to eq('places') }
|
80
|
+
specify { expect(stub_index('namespace/places').derivable_name).to eq('namespace/places') }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '.prefix' do
|
72
84
|
before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
|
73
|
-
specify { expect(Class.new(Chewy::Index).
|
85
|
+
specify { expect(Class.new(Chewy::Index).prefix).to eq('testing') }
|
74
86
|
end
|
75
87
|
|
76
88
|
describe '.define_type' do
|
@@ -92,40 +104,39 @@ describe Chewy::Index do
|
|
92
104
|
before { stub_class('City::District', City) }
|
93
105
|
|
94
106
|
specify do
|
95
|
-
expect
|
107
|
+
expect do
|
96
108
|
Kernel.eval <<-DUMMY_CITY_INDEX
|
97
109
|
class DummyCityIndex < Chewy::Index
|
98
110
|
define_type City
|
99
111
|
define_type City::District
|
100
112
|
end
|
101
113
|
DUMMY_CITY_INDEX
|
102
|
-
|
114
|
+
end.not_to raise_error
|
103
115
|
end
|
104
116
|
|
105
117
|
specify do
|
106
|
-
expect
|
118
|
+
expect do
|
107
119
|
Kernel.eval <<-DUMMY_CITY_INDEX
|
108
120
|
class DummyCityIndex2 < Chewy::Index
|
109
121
|
define_type City
|
110
122
|
define_type City::Nothing
|
111
123
|
end
|
112
124
|
DUMMY_CITY_INDEX
|
113
|
-
|
125
|
+
end.to raise_error(NameError)
|
114
126
|
end
|
115
127
|
end
|
116
128
|
|
117
|
-
context 'type methods should be deprecated and can\'t redefine
|
129
|
+
context 'type methods should be deprecated and can\'t redefine existing ones' do
|
118
130
|
before do
|
119
131
|
stub_index(:places) do
|
120
|
-
def self.city
|
121
|
-
end
|
132
|
+
def self.city; end
|
122
133
|
define_type :city
|
123
134
|
define_type :country
|
124
135
|
end
|
125
136
|
end
|
126
137
|
|
127
138
|
specify { expect(PlacesIndex.city).to be_nil }
|
128
|
-
specify { expect(PlacesIndex
|
139
|
+
specify { expect(PlacesIndex::Country).to be < Chewy::Type }
|
129
140
|
end
|
130
141
|
end
|
131
142
|
|
@@ -136,19 +147,24 @@ describe Chewy::Index do
|
|
136
147
|
specify { expect(DummiesIndex.type_hash['dummy'].type_name).to eq('dummy') }
|
137
148
|
end
|
138
149
|
|
150
|
+
describe '.type' do
|
151
|
+
specify { expect(DummiesIndex.type('dummy')).to eq(DummiesIndex::Dummy) }
|
152
|
+
specify { expect { DummiesIndex.type('not-the-dummy') }.to raise_error(Chewy::UndefinedType) }
|
153
|
+
end
|
154
|
+
|
139
155
|
specify { expect(DummiesIndex.type_names).to eq(DummiesIndex.type_hash.keys) }
|
140
156
|
|
141
157
|
describe '.types' do
|
142
158
|
specify { expect(DummiesIndex.types).to eq(DummiesIndex.type_hash.values) }
|
143
|
-
specify { expect(DummiesIndex.types(:dummy)).to be_a Chewy::
|
144
|
-
specify { expect(DummiesIndex.types(:user)).to be_a Chewy::
|
159
|
+
specify { expect(DummiesIndex.types(:dummy)).to be_a Chewy::Search::Request }
|
160
|
+
specify { expect(DummiesIndex.types(:user)).to be_a Chewy::Search::Request }
|
145
161
|
end
|
146
162
|
|
147
163
|
describe '.settings' do
|
148
164
|
before do
|
149
165
|
allow(Chewy).to receive_messages(config: Chewy::Config.send(:new))
|
150
166
|
|
151
|
-
Chewy.analyzer :name, filter: [
|
167
|
+
Chewy.analyzer :name, filter: %w[lowercase icu_folding names_nysiis]
|
152
168
|
Chewy.analyzer :phone, tokenizer: 'ngram', char_filter: ['phone']
|
153
169
|
Chewy.tokenizer :ngram, type: 'nGram', min_gram: 3, max_gram: 3
|
154
170
|
Chewy.char_filter :phone, type: 'pattern_replace', pattern: '[^\d]', replacement: ''
|
@@ -157,85 +173,165 @@ describe Chewy::Index do
|
|
157
173
|
|
158
174
|
let(:documents) { stub_index(:documents) { settings analysis: {analyzer: [:name, :phone, {sorted: {option: :baz}}]} } }
|
159
175
|
|
160
|
-
specify { expect { documents.settings_hash }.to_not change(documents._settings, :inspect)
|
161
|
-
specify
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
176
|
+
specify { expect { documents.settings_hash }.to_not change(documents._settings, :inspect) }
|
177
|
+
specify do
|
178
|
+
expect(documents.settings_hash).to eq(settings: {analysis: {
|
179
|
+
analyzer: {name: {filter: %w[lowercase icu_folding names_nysiis]},
|
180
|
+
phone: {tokenizer: 'ngram', char_filter: ['phone']},
|
181
|
+
sorted: {option: :baz}},
|
182
|
+
tokenizer: {ngram: {type: 'nGram', min_gram: 3, max_gram: 3}},
|
183
|
+
char_filter: {phone: {type: 'pattern_replace', pattern: '[^\d]', replacement: ''}},
|
184
|
+
filter: {names_nysiis: {type: 'phonetic', encoder: 'nysiis', replace: false}}
|
185
|
+
}})
|
186
|
+
end
|
169
187
|
end
|
170
188
|
|
171
189
|
describe '.scopes' do
|
172
190
|
before do
|
173
191
|
stub_index(:places) do
|
174
|
-
def self.by_rating
|
175
|
-
end
|
192
|
+
def self.by_rating; end
|
176
193
|
|
177
|
-
def self.
|
194
|
+
def self.colors(*colors)
|
195
|
+
filter(terms: {colors: colors.flatten(1).map(&:to_s)})
|
178
196
|
end
|
179
197
|
|
180
198
|
define_type :city do
|
181
|
-
def self.by_id
|
182
|
-
|
199
|
+
def self.by_id; end
|
200
|
+
field :colors
|
183
201
|
end
|
184
202
|
end
|
185
203
|
end
|
186
204
|
|
187
205
|
specify { expect(described_class.scopes).to eq([]) }
|
188
|
-
specify { expect(PlacesIndex.scopes).to match_array([
|
189
|
-
|
206
|
+
specify { expect(PlacesIndex.scopes).to match_array(%i[by_rating colors]) }
|
207
|
+
|
208
|
+
context do
|
209
|
+
before do
|
210
|
+
Chewy.massacre
|
211
|
+
PlacesIndex::City.import!(
|
212
|
+
double(colors: ['red']),
|
213
|
+
double(colors: %w[red green]),
|
214
|
+
double(colors: %w[green yellow])
|
215
|
+
)
|
216
|
+
end
|
190
217
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
218
|
+
specify do
|
219
|
+
# This `blank?`` call is for the messed scopes bug reproduction. See #573
|
220
|
+
PlacesIndex::City.blank?
|
221
|
+
expect(PlacesIndex.colors(:green).map(&:colors))
|
222
|
+
.to contain_exactly(%w[red green], %w[green yellow])
|
223
|
+
end
|
224
|
+
|
225
|
+
specify do
|
226
|
+
# This `blank?` call is for the messed scopes bug reproduction. See #573
|
227
|
+
PlacesIndex::City.blank?
|
228
|
+
expect(PlacesIndex::City.colors(:green).map(&:colors))
|
229
|
+
.to contain_exactly(%w[red green], %w[green yellow])
|
230
|
+
end
|
231
|
+
end
|
197
232
|
end
|
198
233
|
|
199
234
|
describe '.settings_hash' do
|
200
235
|
before { allow(Chewy).to receive_messages(config: Chewy::Config.send(:new)) }
|
201
236
|
|
202
237
|
specify { expect(stub_index(:documents).settings_hash).to eq({}) }
|
203
|
-
specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.settings_hash).to eq(
|
238
|
+
specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.settings_hash).to eq(settings: {number_of_shards: 1}) }
|
204
239
|
end
|
205
240
|
|
206
241
|
describe '.mappings_hash' do
|
207
242
|
specify { expect(stub_index(:documents).mappings_hash).to eq({}) }
|
208
243
|
specify { expect(stub_index(:documents) { define_type :document }.mappings_hash).to eq({}) }
|
209
|
-
specify
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
244
|
+
specify do
|
245
|
+
expect(stub_index(:documents) do
|
246
|
+
define_type :document do
|
247
|
+
field :date, type: 'date'
|
248
|
+
end
|
249
|
+
end.mappings_hash).to eq(mappings: {document: {properties: {date: {type: 'date'}}}})
|
250
|
+
end
|
251
|
+
specify do
|
252
|
+
expect(stub_index(:documents) do
|
253
|
+
define_type :document do
|
254
|
+
field :name
|
255
|
+
end
|
256
|
+
define_type :document2 do
|
257
|
+
field :name
|
258
|
+
end
|
259
|
+
end.mappings_hash[:mappings].keys).to match_array(%i[document document2])
|
260
|
+
end
|
222
261
|
end
|
223
262
|
|
224
|
-
describe '.
|
263
|
+
describe '.specification_hash' do
|
225
264
|
before { allow(Chewy).to receive_messages(config: Chewy::Config.send(:new)) }
|
226
265
|
|
227
|
-
specify { expect(stub_index(:documents).
|
228
|
-
specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.
|
229
|
-
specify
|
230
|
-
|
231
|
-
|
266
|
+
specify { expect(stub_index(:documents).specification_hash).to eq({}) }
|
267
|
+
specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.specification_hash.keys).to eq([:settings]) }
|
268
|
+
specify do
|
269
|
+
expect(stub_index(:documents) do
|
270
|
+
define_type :document do
|
271
|
+
field :name
|
272
|
+
end
|
273
|
+
end.specification_hash.keys).to eq([:mappings])
|
274
|
+
end
|
275
|
+
specify do
|
276
|
+
expect(stub_index(:documents) do
|
277
|
+
settings number_of_shards: 1
|
278
|
+
define_type :document do
|
279
|
+
field :name
|
280
|
+
end
|
281
|
+
end.specification_hash.keys).to match_array(%i[mappings settings])
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe '.specification' do
|
286
|
+
subject { stub_index(:documents) }
|
287
|
+
specify { expect(subject.specification).to be_a(Chewy::Index::Specification) }
|
288
|
+
specify { expect(subject.specification).to equal(subject.specification) }
|
289
|
+
end
|
290
|
+
|
291
|
+
describe '.default_prefix' do
|
292
|
+
before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
|
293
|
+
|
294
|
+
context do
|
295
|
+
before { expect(ActiveSupport::Deprecation).to receive(:warn).once }
|
296
|
+
specify { expect(DummiesIndex.default_prefix).to eq('testing') }
|
297
|
+
end
|
298
|
+
|
299
|
+
context do
|
300
|
+
before do
|
301
|
+
DummiesIndex.class_eval do
|
302
|
+
def self.default_prefix
|
303
|
+
'borogoves'
|
304
|
+
end
|
305
|
+
end
|
232
306
|
end
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
307
|
+
|
308
|
+
before { expect(ActiveSupport::Deprecation).to receive(:warn).once }
|
309
|
+
specify { expect(DummiesIndex.index_name).to eq('borogoves_dummies') }
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
context 'index call inside index', :orm do
|
314
|
+
before do
|
315
|
+
stub_index(:cities) do
|
316
|
+
define_type :city do
|
317
|
+
field :country_name, value: (lambda do |city|
|
318
|
+
CountriesIndex::Country.filter(term: {_id: city.country_id}).first.name
|
319
|
+
end)
|
320
|
+
end
|
238
321
|
end
|
239
|
-
|
322
|
+
|
323
|
+
stub_index(:countries) do
|
324
|
+
define_type :country do
|
325
|
+
field :name
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
CountriesIndex::Country.import!(double(id: 1, name: 'Country'))
|
330
|
+
end
|
331
|
+
|
332
|
+
specify do
|
333
|
+
expect { CitiesIndex::City.import!(double(country_id: 1)) }
|
334
|
+
.to update_index(CitiesIndex::City).and_reindex(country_name: 'Country')
|
335
|
+
end
|
240
336
|
end
|
241
337
|
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Journal do
|
4
|
+
context 'journaling', :orm do
|
5
|
+
['', 'namespace/'].each do |namespace|
|
6
|
+
context namespace.present? ? 'with namespace' : 'without namespace' do
|
7
|
+
before do
|
8
|
+
stub_model(:city) do
|
9
|
+
update_index "#{namespace}places#city", :self
|
10
|
+
end
|
11
|
+
stub_model(:country) do
|
12
|
+
update_index "#{namespace}places#country", :self
|
13
|
+
end
|
14
|
+
|
15
|
+
stub_index("#{namespace}places") do
|
16
|
+
define_type City do
|
17
|
+
default_import_options journal: true
|
18
|
+
end
|
19
|
+
define_type Country do
|
20
|
+
default_import_options journal: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Chewy.massacre
|
25
|
+
Chewy.settings[:prefix] = 'some_prefix'
|
26
|
+
Timecop.freeze(time)
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
Chewy.settings[:prefix] = nil
|
31
|
+
Timecop.return
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:time) { Time.now }
|
35
|
+
let(:import_time) { time + 1 }
|
36
|
+
let(:update_time) { time + 2 }
|
37
|
+
let(:destroy_time) { time + 3 }
|
38
|
+
|
39
|
+
def timestamp(time)
|
40
|
+
time.to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
specify do
|
44
|
+
places_index = namespace.present? ? Namespace::PlacesIndex : PlacesIndex
|
45
|
+
Chewy.strategy(:urgent) do
|
46
|
+
cities = Array.new(2) { |i| City.create!(id: i + 1) }
|
47
|
+
countries = Array.new(2) { |i| Country.create!(id: i + 1) }
|
48
|
+
Country.create!(id: 3)
|
49
|
+
|
50
|
+
Timecop.freeze(import_time)
|
51
|
+
|
52
|
+
places_index.import
|
53
|
+
|
54
|
+
expect(Chewy::Stash::Journal.exists?).to eq true
|
55
|
+
|
56
|
+
Timecop.freeze(update_time)
|
57
|
+
cities.first.update_attributes!(name: 'Supername')
|
58
|
+
|
59
|
+
Timecop.freeze(destroy_time)
|
60
|
+
countries.last.destroy
|
61
|
+
|
62
|
+
journal_entries = Chewy::Stash::Journal.order(:created_at).hits.map { |r| r['_source'] }
|
63
|
+
expected_journal = [
|
64
|
+
{
|
65
|
+
'index_name' => "#{namespace}places",
|
66
|
+
'type_name' => 'city',
|
67
|
+
'action' => 'index',
|
68
|
+
'references' => ['1'].map(&Base64.method(:encode64)),
|
69
|
+
'created_at' => time.utc.as_json
|
70
|
+
},
|
71
|
+
{
|
72
|
+
'index_name' => "#{namespace}places",
|
73
|
+
'type_name' => 'city',
|
74
|
+
'action' => 'index',
|
75
|
+
'references' => ['2'].map(&Base64.method(:encode64)),
|
76
|
+
'created_at' => time.utc.as_json
|
77
|
+
},
|
78
|
+
{
|
79
|
+
'index_name' => "#{namespace}places",
|
80
|
+
'type_name' => 'country',
|
81
|
+
'action' => 'index',
|
82
|
+
'references' => ['1'].map(&Base64.method(:encode64)),
|
83
|
+
'created_at' => time.utc.as_json
|
84
|
+
},
|
85
|
+
{
|
86
|
+
'index_name' => "#{namespace}places",
|
87
|
+
'type_name' => 'country',
|
88
|
+
'action' => 'index',
|
89
|
+
'references' => ['2'].map(&Base64.method(:encode64)),
|
90
|
+
'created_at' => time.utc.as_json
|
91
|
+
},
|
92
|
+
{
|
93
|
+
'index_name' => "#{namespace}places",
|
94
|
+
'type_name' => 'country',
|
95
|
+
'action' => 'index',
|
96
|
+
'references' => ['3'].map(&Base64.method(:encode64)),
|
97
|
+
'created_at' => time.utc.as_json
|
98
|
+
},
|
99
|
+
{
|
100
|
+
'index_name' => "#{namespace}places",
|
101
|
+
'type_name' => 'city',
|
102
|
+
'action' => 'index',
|
103
|
+
'references' => %w[1 2].map(&Base64.method(:encode64)),
|
104
|
+
'created_at' => import_time.utc.as_json
|
105
|
+
},
|
106
|
+
{
|
107
|
+
'index_name' => "#{namespace}places",
|
108
|
+
'type_name' => 'country',
|
109
|
+
'action' => 'index',
|
110
|
+
'references' => %w[1 2 3].map(&Base64.method(:encode64)),
|
111
|
+
'created_at' => import_time.utc.as_json
|
112
|
+
},
|
113
|
+
{
|
114
|
+
'index_name' => "#{namespace}places",
|
115
|
+
'type_name' => 'city',
|
116
|
+
'action' => 'index',
|
117
|
+
'references' => ['1'].map(&Base64.method(:encode64)),
|
118
|
+
'created_at' => update_time.utc.as_json
|
119
|
+
},
|
120
|
+
{
|
121
|
+
'index_name' => "#{namespace}places",
|
122
|
+
'type_name' => 'country',
|
123
|
+
'action' => 'delete',
|
124
|
+
'references' => ['2'].map(&Base64.method(:encode64)),
|
125
|
+
'created_at' => destroy_time.utc.as_json
|
126
|
+
}
|
127
|
+
]
|
128
|
+
|
129
|
+
expect(Chewy::Stash::Journal.count).to eq 9
|
130
|
+
expect(journal_entries).to eq expected_journal
|
131
|
+
|
132
|
+
journal_entries = Chewy::Stash::Journal.entries(import_time - 1)
|
133
|
+
expect(journal_entries.size).to eq 4
|
134
|
+
|
135
|
+
# simulate lost data
|
136
|
+
Chewy.client.delete(index: "#{Chewy.settings[:prefix]}_places", type: 'city', id: 1, refresh: true)
|
137
|
+
expect(places_index::City.count).to eq 1
|
138
|
+
|
139
|
+
described_class.new.apply(time)
|
140
|
+
expect(places_index::City.count).to eq 2
|
141
|
+
|
142
|
+
clean_response = described_class.new.clean(import_time)
|
143
|
+
expect(clean_response['deleted'] || clean_response['_indices']['_all']['deleted']).to eq 7
|
144
|
+
Chewy.client.indices.refresh
|
145
|
+
expect(Chewy::Stash::Journal.count).to eq 2
|
146
|
+
|
147
|
+
Timecop.return
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context do
|
155
|
+
before { Chewy.massacre }
|
156
|
+
before do
|
157
|
+
stub_model(:city) do
|
158
|
+
update_index 'cities', :self
|
159
|
+
end
|
160
|
+
stub_model(:country) do
|
161
|
+
update_index 'countries', :self
|
162
|
+
end
|
163
|
+
|
164
|
+
stub_index(:cities) do
|
165
|
+
define_type City do
|
166
|
+
default_import_options journal: true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
stub_index(:countries) do
|
170
|
+
define_type Country do
|
171
|
+
default_import_options journal: true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#apply' do
|
177
|
+
specify { expect(described_class.new(CitiesIndex).apply(2.minutes.ago)).to eq(0) }
|
178
|
+
|
179
|
+
context 'with an index filter' do
|
180
|
+
let(:time) { Time.now }
|
181
|
+
|
182
|
+
before { Timecop.freeze(time) }
|
183
|
+
after { Timecop.return }
|
184
|
+
|
185
|
+
specify do
|
186
|
+
Chewy.strategy(:urgent) do
|
187
|
+
Array.new(2) { |i| City.create!(id: i + 1) }
|
188
|
+
Array.new(2) { |i| Country.create!(id: i + 1) }
|
189
|
+
|
190
|
+
# simulate lost data
|
191
|
+
Chewy.client.delete(index: 'cities', type: 'city', id: 1, refresh: true)
|
192
|
+
Chewy.client.delete(index: 'countries', type: 'country', id: 1, refresh: true)
|
193
|
+
expect(CitiesIndex.all.to_a.length).to eq 1
|
194
|
+
expect(CountriesIndex.all.to_a.length).to eq 1
|
195
|
+
|
196
|
+
# Replay on specific index
|
197
|
+
expect(described_class.new(CitiesIndex).apply(time)).to eq(2)
|
198
|
+
expect(CitiesIndex.all.to_a.length).to eq 2
|
199
|
+
expect(CountriesIndex.all.to_a.length).to eq 1
|
200
|
+
|
201
|
+
# Replay on both
|
202
|
+
Chewy.client.delete(index: 'cities', type: 'city', id: 1, refresh: true)
|
203
|
+
expect(CitiesIndex.all.to_a.length).to eq 1
|
204
|
+
expect(described_class.new(CitiesIndex, CountriesIndex).apply(time)).to eq(4)
|
205
|
+
expect(CitiesIndex.all.to_a.length).to eq 2
|
206
|
+
expect(CountriesIndex.all.to_a.length).to eq 2
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'retries' do
|
212
|
+
let(:time) { Time.now.to_i }
|
213
|
+
before do
|
214
|
+
Timecop.freeze
|
215
|
+
Chewy.strategy(:urgent)
|
216
|
+
City.create!(id: 1)
|
217
|
+
end
|
218
|
+
|
219
|
+
after do
|
220
|
+
Chewy.strategy.pop
|
221
|
+
Timecop.return
|
222
|
+
end
|
223
|
+
|
224
|
+
specify 'journal was cleaned after the first call' do
|
225
|
+
expect(Chewy::Stash::Journal).to receive(:entries).exactly(2).and_call_original
|
226
|
+
expect(described_class.new.apply(time)).to eq(1)
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'endless journal' do
|
230
|
+
let(:count_of_checks) { 10 } # default
|
231
|
+
let!(:journal_entries) do
|
232
|
+
record = Chewy::Stash::Journal.entries(time).first
|
233
|
+
Array.new(count_of_checks) do |i|
|
234
|
+
Chewy::Stash::Journal::Journal.new(
|
235
|
+
record.attributes.merge(
|
236
|
+
'created_at' => time.to_i + i,
|
237
|
+
'references' => [i.to_s]
|
238
|
+
)
|
239
|
+
)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
specify '10 retries by default' do
|
244
|
+
expect(Chewy::Stash::Journal)
|
245
|
+
.to receive(:entries).exactly(count_of_checks) { [journal_entries.shift].compact }
|
246
|
+
expect(described_class.new.apply(time)).to eq(10)
|
247
|
+
end
|
248
|
+
|
249
|
+
specify 'with :once parameter set' do
|
250
|
+
expect(Chewy::Stash::Journal)
|
251
|
+
.to receive(:entries).exactly(1) { [journal_entries.shift].compact }
|
252
|
+
expect(described_class.new.apply(time, retries: 1)).to eq(1)
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'with retries parameter set' do
|
256
|
+
let(:retries) { 5 }
|
257
|
+
|
258
|
+
specify do
|
259
|
+
expect(Chewy::Stash::Journal)
|
260
|
+
.to receive(:entries).exactly(retries) { [journal_entries.shift].compact }
|
261
|
+
expect(described_class.new.apply(time, retries: retries)).to eq(5)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'chewy/minitest'
|
3
|
+
|
4
|
+
describe :minitest_helper do
|
5
|
+
class << self
|
6
|
+
alias_method :teardown, :after
|
7
|
+
end
|
8
|
+
|
9
|
+
def assert_includes(haystack, needle, _comment)
|
10
|
+
expect(haystack).to include(needle)
|
11
|
+
end
|
12
|
+
|
13
|
+
include ::Chewy::Minitest::Helpers
|
14
|
+
|
15
|
+
before do
|
16
|
+
Chewy.massacre
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
stub_index(:dummies) do
|
21
|
+
define_type :dummy do
|
22
|
+
root value: ->(_o) { {} }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'assert_indexes' do
|
28
|
+
specify 'doesn\'t fail when index updates correctly' do
|
29
|
+
expect do
|
30
|
+
assert_indexes DummiesIndex::Dummy do
|
31
|
+
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
32
|
+
end
|
33
|
+
end.to_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
specify 'fails when index doesn\'t update' do
|
37
|
+
expect do
|
38
|
+
assert_indexes DummiesIndex::Dummy do
|
39
|
+
end
|
40
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
41
|
+
end
|
42
|
+
|
43
|
+
specify 'SearchIndexReceiver catches the indexes' do
|
44
|
+
receiver = assert_indexes DummiesIndex::Dummy do
|
45
|
+
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
46
|
+
end
|
47
|
+
|
48
|
+
expect(receiver).to be_a(SearchIndexReceiver)
|
49
|
+
|
50
|
+
expect(
|
51
|
+
receiver.indexes_for(DummiesIndex::Dummy)
|
52
|
+
.map { |index| index[:_id] }
|
53
|
+
).to match_array([41, 42])
|
54
|
+
end
|
55
|
+
|
56
|
+
specify 'Real index is bypassed when asserting' do
|
57
|
+
expect(DummiesIndex::Dummy).not_to receive(:bulk)
|
58
|
+
|
59
|
+
assert_indexes DummiesIndex::Dummy do
|
60
|
+
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
specify 'Real index is allowed when asserting' do
|
65
|
+
expect(DummiesIndex::Dummy).to receive(:bulk)
|
66
|
+
|
67
|
+
assert_indexes DummiesIndex::Dummy, bypass_actual_index: false do
|
68
|
+
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'run_indexing' do
|
74
|
+
specify 'pushes onto the chewy strategy stack' do
|
75
|
+
Chewy.strategy :bypass do
|
76
|
+
run_indexing do
|
77
|
+
expect(Chewy.strategy.current.name).to be(:atomic)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
specify 'allows tester to specify the strategy' do
|
83
|
+
Chewy.strategy :atomic do
|
84
|
+
run_indexing strategy: :bypass do
|
85
|
+
expect(Chewy.strategy.current.name).to be(:bypass)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|