chewy 0.8.4 → 7.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- data/.github/workflows/ruby.yml +74 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +132 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +554 -245
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +14 -11
- data/Guardfile +8 -6
- data/LICENSE.txt +1 -1
- data/README.md +748 -623
- data/Rakefile +11 -1
- data/chewy.gemspec +15 -19
- data/gemfiles/rails.5.2.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
- data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
- data/lib/chewy/config.rb +64 -50
- data/lib/chewy/errors.rb +10 -16
- data/lib/chewy/fields/base.rb +122 -32
- data/lib/chewy/fields/root.rb +48 -23
- data/lib/chewy/index/actions.rb +140 -54
- data/lib/chewy/index/adapter/active_record.rb +112 -0
- data/lib/chewy/{type → index}/adapter/base.rb +31 -12
- data/lib/chewy/index/adapter/object.rb +249 -0
- data/lib/chewy/index/adapter/orm.rb +194 -0
- data/lib/chewy/index/aliases.rb +14 -4
- data/lib/chewy/index/crutch.rb +40 -0
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/index/import/bulk_request.rb +77 -0
- data/lib/chewy/index/import/journal_builder.rb +44 -0
- data/lib/chewy/index/import/routine.rb +139 -0
- data/lib/chewy/index/import.rb +243 -0
- data/lib/chewy/{type → index}/mapping.rb +79 -68
- data/lib/chewy/index/observe/active_record_methods.rb +87 -0
- data/lib/chewy/index/observe/callback.rb +34 -0
- data/lib/chewy/index/observe.rb +17 -0
- data/lib/chewy/index/settings.rb +10 -5
- data/lib/chewy/index/specification.rb +61 -0
- data/lib/chewy/index/syncer.rb +221 -0
- data/lib/chewy/{type → index}/witchcraft.rb +100 -39
- data/lib/chewy/index/wrapper.rb +95 -0
- data/lib/chewy/index.rb +216 -140
- data/lib/chewy/journal.rb +66 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +150 -0
- data/lib/chewy/minitest/search_index_receiver.rb +76 -0
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +12 -25
- data/lib/chewy/rake_helper.rb +335 -37
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +106 -90
- data/lib/chewy/rspec.rb +3 -1
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/runtime.rb +1 -1
- data/lib/chewy/search/loader.rb +61 -0
- data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
- 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/collapse.rb +16 -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/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/indices.rb +78 -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 +25 -0
- data/lib/chewy/search/parameters/offset.rb +17 -0
- data/lib/chewy/search/parameters/order.rb +51 -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 +77 -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/track_total_hits.rb +16 -0
- data/lib/chewy/search/parameters/version.rb +16 -0
- data/lib/chewy/search/parameters.rb +170 -0
- data/lib/chewy/search/query_proxy.rb +264 -0
- data/lib/chewy/search/request.rb +1071 -0
- data/lib/chewy/search/response.rb +119 -0
- data/lib/chewy/search/scoping.rb +49 -0
- data/lib/chewy/search/scrolling.rb +137 -0
- data/lib/chewy/search.rb +68 -28
- data/lib/chewy/stash.rb +68 -0
- data/lib/chewy/strategy/active_job.rb +3 -2
- data/lib/chewy/strategy/atomic.rb +2 -4
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +13 -3
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +148 -0
- data/lib/chewy/strategy/delayed_sidekiq/worker.rb +52 -0
- data/lib/chewy/strategy/delayed_sidekiq.rb +17 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +15 -2
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/strategy.rb +16 -20
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +81 -82
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +99 -32
- data/migration_guide.md +56 -0
- data/spec/chewy/config_spec.rb +87 -15
- data/spec/chewy/fields/base_spec.rb +542 -233
- data/spec/chewy/fields/root_spec.rb +115 -17
- data/spec/chewy/fields/time_fields_spec.rb +13 -12
- data/spec/chewy/index/actions_spec.rb +595 -77
- data/spec/chewy/index/adapter/active_record_spec.rb +601 -0
- data/spec/chewy/index/adapter/object_spec.rb +243 -0
- data/spec/chewy/index/aliases_spec.rb +5 -5
- data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
- data/spec/chewy/index/import/bulk_request_spec.rb +95 -0
- data/spec/chewy/index/import/journal_builder_spec.rb +87 -0
- data/spec/chewy/index/import/routine_spec.rb +110 -0
- data/spec/chewy/index/import_spec.rb +615 -0
- 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 +103 -50
- data/spec/chewy/index/specification_spec.rb +159 -0
- data/spec/chewy/index/syncer_spec.rb +118 -0
- data/spec/chewy/index/witchcraft_spec.rb +245 -0
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +149 -121
- data/spec/chewy/journal_spec.rb +223 -0
- data/spec/chewy/minitest/helpers_spec.rb +198 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +118 -0
- data/spec/chewy/multi_search_spec.rb +84 -0
- data/spec/chewy/rake_helper_spec.rb +656 -0
- data/spec/chewy/repository_spec.rb +8 -8
- 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 +220 -114
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +83 -0
- data/spec/chewy/search/pagination/kaminari_examples.rb +69 -0
- data/spec/chewy/search/pagination/kaminari_spec.rb +21 -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/collapse_spec.rb +5 -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/ignore_unavailable_spec.rb +67 -0
- data/spec/chewy/search/parameters/indices_spec.rb +99 -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 +72 -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 +434 -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 +35 -0
- data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
- data/spec/chewy/search/parameters/source_spec.rb +162 -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/track_total_hits_spec.rb +5 -0
- data/spec/chewy/search/parameters/version_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +161 -0
- data/spec/chewy/search/query_proxy_spec.rb +119 -0
- data/spec/chewy/search/request_spec.rb +880 -0
- data/spec/chewy/search/response_spec.rb +202 -0
- data/spec/chewy/search/scrolling_spec.rb +171 -0
- data/spec/chewy/search_spec.rb +82 -55
- data/spec/chewy/stash_spec.rb +85 -0
- data/spec/chewy/strategy/active_job_spec.rb +27 -8
- data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
- data/spec/chewy/strategy/atomic_spec.rb +13 -11
- data/spec/chewy/strategy/delayed_sidekiq_spec.rb +190 -0
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +19 -7
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +65 -88
- data/spec/spec_helper.rb +11 -20
- data/spec/support/active_record.rb +48 -6
- data/spec/support/class_helpers.rb +4 -19
- metadata +299 -183
- data/.travis.yml +0 -76
- data/Appraisals +0 -76
- 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.gemfile +0 -15
- 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.gemfile +0 -15
- 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.gemfile +0 -16
- 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/backports/deep_dup.rb +0 -46
- data/lib/chewy/backports/duplicable.rb +0 -90
- data/lib/chewy/query/compose.rb +0 -69
- data/lib/chewy/query/criteria.rb +0 -181
- 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 -32
- 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 -106
- data/lib/chewy/query/nodes/has_child.rb +0 -14
- data/lib/chewy/query/nodes/has_parent.rb +0 -14
- data/lib/chewy/query/nodes/has_relation.rb +0 -61
- 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 -18
- 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 -31
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/pagination.rb +0 -16
- data/lib/chewy/query/scoping.rb +0 -20
- data/lib/chewy/query.rb +0 -1026
- data/lib/chewy/strategy/resque.rb +0 -26
- data/lib/chewy/type/actions.rb +0 -19
- data/lib/chewy/type/adapter/active_record.rb +0 -72
- data/lib/chewy/type/adapter/mongoid.rb +0 -58
- data/lib/chewy/type/adapter/object.rb +0 -89
- data/lib/chewy/type/adapter/orm.rb +0 -156
- data/lib/chewy/type/adapter/sequel.rb +0 -75
- data/lib/chewy/type/crutch.rb +0 -31
- data/lib/chewy/type/import.rb +0 -224
- data/lib/chewy/type/observe.rb +0 -76
- data/lib/chewy/type/wrapper.rb +0 -53
- data/lib/chewy/type.rb +0 -89
- data/lib/sequel/plugins/chewy_observe.rb +0 -78
- data/spec/chewy/query/criteria_spec.rb +0 -433
- data/spec/chewy/query/filters_spec.rb +0 -173
- data/spec/chewy/query/loading_spec.rb +0 -86
- data/spec/chewy/query/nodes/and_spec.rb +0 -16
- data/spec/chewy/query/nodes/bool_spec.rb +0 -22
- 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 -40
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -40
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -15
- data/spec/chewy/query/nodes/not_spec.rb +0 -16
- data/spec/chewy/query/nodes/or_spec.rb +0 -16
- 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 -31
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -57
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -60
- data/spec/chewy/query/pagination_spec.rb +0 -36
- data/spec/chewy/query_spec.rb +0 -632
- data/spec/chewy/strategy/resque_spec.rb +0 -40
- data/spec/chewy/type/actions_spec.rb +0 -31
- data/spec/chewy/type/adapter/active_record_spec.rb +0 -317
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -253
- data/spec/chewy/type/adapter/object_spec.rb +0 -139
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -320
- data/spec/chewy/type/import_spec.rb +0 -433
- data/spec/chewy/type/mapping_spec.rb +0 -106
- data/spec/chewy/type/observe_spec.rb +0 -127
- data/spec/chewy/type/witchcraft_spec.rb +0 -154
- data/spec/chewy/type/wrapper_spec.rb +0 -58
- data/spec/chewy/type_spec.rb +0 -33
- data/spec/support/mongoid.rb +0 -81
- data/spec/support/sequel.rb +0 -75
@@ -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
|
@@ -14,11 +19,11 @@ if defined?(::ActiveJob)
|
|
14
19
|
|
15
20
|
before do
|
16
21
|
stub_model(:city) do
|
17
|
-
update_index('cities
|
22
|
+
update_index('cities') { self }
|
18
23
|
end
|
19
24
|
|
20
25
|
stub_index(:cities) do
|
21
|
-
|
26
|
+
index_scope City
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
@@ -27,7 +32,7 @@ if defined?(::ActiveJob)
|
|
27
32
|
|
28
33
|
specify do
|
29
34
|
expect { [city, other_city].map(&:save!) }
|
30
|
-
.not_to update_index(CitiesIndex
|
35
|
+
.not_to update_index(CitiesIndex, strategy: :active_job)
|
31
36
|
end
|
32
37
|
|
33
38
|
specify do
|
@@ -36,19 +41,33 @@ 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
|
43
56
|
::ActiveJob::Base.queue_adapter = :inline
|
44
57
|
expect { [city, other_city].map(&:save!) }
|
45
|
-
.to update_index(CitiesIndex
|
58
|
+
.to update_index(CitiesIndex, strategy: :active_job)
|
46
59
|
.and_reindex(city, other_city).only
|
47
60
|
end
|
48
61
|
|
49
62
|
specify do
|
50
|
-
expect(CitiesIndex
|
51
|
-
Chewy::Strategy::ActiveJob::Worker.new.perform(
|
63
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
|
64
|
+
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
65
|
+
end
|
66
|
+
|
67
|
+
specify do
|
68
|
+
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
69
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
|
70
|
+
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
52
71
|
end
|
53
72
|
end
|
54
73
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Strategy::AtomicNoRefresh, :orm do
|
4
|
+
around { |example| Chewy.strategy(:bypass) { example.run } }
|
5
|
+
|
6
|
+
before do
|
7
|
+
stub_model(:country) do
|
8
|
+
update_index('countries') { self }
|
9
|
+
end
|
10
|
+
|
11
|
+
stub_index(:countries) do
|
12
|
+
index_scope Country
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:country) { Country.create!(name: 'hello', country_code: 'HL') }
|
17
|
+
let(:other_country) { Country.create!(name: 'world', country_code: 'WD') }
|
18
|
+
|
19
|
+
specify do
|
20
|
+
expect { [country, other_country].map(&:save!) }
|
21
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
22
|
+
.and_reindex(country, other_country).only.no_refresh
|
23
|
+
end
|
24
|
+
|
25
|
+
specify do
|
26
|
+
expect { [country, other_country].map(&:destroy) }
|
27
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
28
|
+
.and_delete(country, other_country).only.no_refresh
|
29
|
+
end
|
30
|
+
|
31
|
+
context do
|
32
|
+
before do
|
33
|
+
stub_index(:countries) do
|
34
|
+
index_scope Country
|
35
|
+
root id: -> { country_code }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
specify do
|
40
|
+
expect { [country, other_country].map(&:save!) }
|
41
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
42
|
+
.and_reindex('HL', 'WD').only.no_refresh
|
43
|
+
end
|
44
|
+
|
45
|
+
specify do
|
46
|
+
expect { [country, other_country].map(&:destroy) }
|
47
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
48
|
+
.and_delete('HL', 'WD').only.no_refresh
|
49
|
+
end
|
50
|
+
|
51
|
+
specify do
|
52
|
+
expect do
|
53
|
+
country.save!
|
54
|
+
other_country.destroy
|
55
|
+
end
|
56
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
57
|
+
.and_reindex('HL').and_delete('WD').only.no_refresh
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -5,11 +5,11 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_model(:country) do
|
8
|
-
update_index('countries
|
8
|
+
update_index('countries') { self }
|
9
9
|
end
|
10
10
|
|
11
11
|
stub_index(:countries) do
|
12
|
-
|
12
|
+
index_scope Country
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -18,41 +18,43 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
18
18
|
|
19
19
|
specify do
|
20
20
|
expect { [country, other_country].map(&:save!) }
|
21
|
-
.to update_index(CountriesIndex
|
21
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
22
22
|
.and_reindex(country, other_country).only
|
23
23
|
end
|
24
24
|
|
25
25
|
specify do
|
26
26
|
expect { [country, other_country].map(&:destroy) }
|
27
|
-
.to update_index(CountriesIndex
|
27
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
28
28
|
.and_delete(country, other_country).only
|
29
29
|
end
|
30
30
|
|
31
31
|
context do
|
32
32
|
before do
|
33
33
|
stub_index(:countries) do
|
34
|
-
|
35
|
-
|
36
|
-
end
|
34
|
+
index_scope Country
|
35
|
+
root id: -> { country_code } do
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
40
|
specify do
|
42
41
|
expect { [country, other_country].map(&:save!) }
|
43
|
-
.to update_index(CountriesIndex
|
42
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
44
43
|
.and_reindex('HL', 'WD').only
|
45
44
|
end
|
46
45
|
|
47
46
|
specify do
|
48
47
|
expect { [country, other_country].map(&:destroy) }
|
49
|
-
.to update_index(CountriesIndex
|
48
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
50
49
|
.and_delete('HL', 'WD').only
|
51
50
|
end
|
52
51
|
|
53
52
|
specify do
|
54
|
-
expect
|
55
|
-
.
|
53
|
+
expect do
|
54
|
+
country.save!
|
55
|
+
other_country.destroy
|
56
|
+
end
|
57
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
56
58
|
.and_reindex('HL').and_delete('WD').only
|
57
59
|
end
|
58
60
|
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined?(Sidekiq)
|
4
|
+
require 'sidekiq/testing'
|
5
|
+
require 'mock_redis'
|
6
|
+
|
7
|
+
describe Chewy::Strategy::DelayedSidekiq do
|
8
|
+
around do |example|
|
9
|
+
Chewy.strategy(:bypass) { example.run }
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
redis = MockRedis.new
|
14
|
+
allow(Sidekiq).to receive(:redis).and_yield(redis)
|
15
|
+
Sidekiq::Worker.clear_all
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
stub_model(:city) do
|
20
|
+
update_index('cities') { self }
|
21
|
+
end
|
22
|
+
|
23
|
+
stub_index(:cities) do
|
24
|
+
index_scope City
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:city) { City.create!(name: 'hello') }
|
29
|
+
let(:other_city) { City.create!(name: 'world') }
|
30
|
+
|
31
|
+
it 'does not trigger immediate reindex due to it`s async nature' do
|
32
|
+
expect { [city, other_city].map(&:save!) }
|
33
|
+
.not_to update_index(CitiesIndex, strategy: :delayed_sidekiq)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "respects 'refresh: false' options" do
|
37
|
+
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
38
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], refresh: false)
|
39
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [city.id, other_city.id])
|
40
|
+
scheduler.postpone
|
41
|
+
Chewy::Strategy::DelayedSidekiq::Worker.drain
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with default config' do
|
45
|
+
it 'does schedule a job that triggers reindex with default options' do
|
46
|
+
Timecop.freeze do
|
47
|
+
expect(Sidekiq::Client).to receive(:push).with(
|
48
|
+
hash_including(
|
49
|
+
'queue' => 'chewy',
|
50
|
+
'at' => (Time.current.to_i.ceil(-1) + 2.seconds).to_i,
|
51
|
+
'class' => Chewy::Strategy::DelayedSidekiq::Worker,
|
52
|
+
'args' => ['CitiesIndex', an_instance_of(Integer)]
|
53
|
+
)
|
54
|
+
).and_call_original
|
55
|
+
|
56
|
+
expect($stdout).not_to receive(:puts)
|
57
|
+
|
58
|
+
Sidekiq::Testing.inline! do
|
59
|
+
expect { [city, other_city].map(&:save!) }
|
60
|
+
.to update_index(CitiesIndex, strategy: :delayed_sidekiq)
|
61
|
+
.and_reindex(city, other_city).only
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with custom config' do
|
68
|
+
before do
|
69
|
+
CitiesIndex.strategy_config(
|
70
|
+
delayed_sidekiq: {
|
71
|
+
reindex_wrapper: lambda { |&reindex|
|
72
|
+
puts 'hello'
|
73
|
+
reindex.call
|
74
|
+
},
|
75
|
+
margin: 5,
|
76
|
+
latency: 60
|
77
|
+
}
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'respects :strategy_config options' do
|
82
|
+
Timecop.freeze do
|
83
|
+
expect(Sidekiq::Client).to receive(:push).with(
|
84
|
+
hash_including(
|
85
|
+
'queue' => 'chewy',
|
86
|
+
'at' => (60.seconds.from_now.change(sec: 0) + 5.seconds).to_i,
|
87
|
+
'class' => Chewy::Strategy::DelayedSidekiq::Worker,
|
88
|
+
'args' => ['CitiesIndex', an_instance_of(Integer)]
|
89
|
+
)
|
90
|
+
).and_call_original
|
91
|
+
|
92
|
+
expect($stdout).to receive(:puts).with('hello') # check that reindex_wrapper works
|
93
|
+
|
94
|
+
Sidekiq::Testing.inline! do
|
95
|
+
expect { [city, other_city].map(&:save!) }
|
96
|
+
.to update_index(CitiesIndex, strategy: :delayed_sidekiq)
|
97
|
+
.and_reindex(city, other_city).only
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'two reindex call within the timewindow' do
|
104
|
+
it 'accumulates all ids does the reindex one time' do
|
105
|
+
Timecop.freeze do
|
106
|
+
expect(CitiesIndex).to receive(:import!).with([other_city.id, city.id]).once
|
107
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [city.id])
|
108
|
+
scheduler.postpone
|
109
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [other_city.id])
|
110
|
+
scheduler.postpone
|
111
|
+
Chewy::Strategy::DelayedSidekiq::Worker.drain
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'one call with update_fields another one without update_fields' do
|
116
|
+
it 'does reindex of all fields' do
|
117
|
+
Timecop.freeze do
|
118
|
+
expect(CitiesIndex).to receive(:import!).with([other_city.id, city.id]).once
|
119
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [city.id], update_fields: ['name'])
|
120
|
+
scheduler.postpone
|
121
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [other_city.id])
|
122
|
+
scheduler.postpone
|
123
|
+
Chewy::Strategy::DelayedSidekiq::Worker.drain
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'both calls with different update fields' do
|
129
|
+
it 'deos reindex with union of fields' do
|
130
|
+
Timecop.freeze do
|
131
|
+
expect(CitiesIndex).to receive(:import!).with([other_city.id, city.id], update_fields: %w[description name]).once
|
132
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [city.id], update_fields: ['name'])
|
133
|
+
scheduler.postpone
|
134
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [other_city.id], update_fields: ['description'])
|
135
|
+
scheduler.postpone
|
136
|
+
Chewy::Strategy::DelayedSidekiq::Worker.drain
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'two calls within different timewindows' do
|
143
|
+
it 'does two separate reindexes' do
|
144
|
+
Timecop.freeze do
|
145
|
+
expect(CitiesIndex).to receive(:import!).with([city.id]).once
|
146
|
+
expect(CitiesIndex).to receive(:import!).with([other_city.id]).once
|
147
|
+
Timecop.travel(20.seconds.ago) do
|
148
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [city.id])
|
149
|
+
scheduler.postpone
|
150
|
+
end
|
151
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [other_city.id])
|
152
|
+
scheduler.postpone
|
153
|
+
Chewy::Strategy::DelayedSidekiq::Worker.drain
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'first call has update_fields' do
|
159
|
+
it 'does first reindex with the expected update_fields and second without update_fields' do
|
160
|
+
Timecop.freeze do
|
161
|
+
expect(CitiesIndex).to receive(:import!).with([city.id], update_fields: ['name']).once
|
162
|
+
expect(CitiesIndex).to receive(:import!).with([other_city.id]).once
|
163
|
+
Timecop.travel(20.seconds.ago) do
|
164
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [city.id], update_fields: ['name'])
|
165
|
+
scheduler.postpone
|
166
|
+
end
|
167
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [other_city.id])
|
168
|
+
scheduler.postpone
|
169
|
+
Chewy::Strategy::DelayedSidekiq::Worker.drain
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'both calls have update_fields option' do
|
175
|
+
it 'does both reindexes with their expected update_fields option' do
|
176
|
+
Timecop.freeze do
|
177
|
+
expect(CitiesIndex).to receive(:import!).with([city.id], update_fields: ['name']).once
|
178
|
+
expect(CitiesIndex).to receive(:import!).with([other_city.id], update_fields: ['description']).once
|
179
|
+
Timecop.travel(20.seconds.ago) do
|
180
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [city.id], update_fields: ['name'])
|
181
|
+
scheduler.postpone
|
182
|
+
end
|
183
|
+
scheduler = Chewy::Strategy::DelayedSidekiq::Scheduler.new(CitiesIndex, [other_city.id], update_fields: ['description'])
|
184
|
+
scheduler.postpone
|
185
|
+
Chewy::Strategy::DelayedSidekiq::Worker.drain
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined?(::Sidekiq)
|
4
|
+
require 'sidekiq/testing'
|
5
|
+
|
6
|
+
describe Chewy::Strategy::LazySidekiq do
|
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
|
13
|
+
before { ::Sidekiq::Worker.clear_all }
|
14
|
+
|
15
|
+
context 'strategy' do
|
16
|
+
before do
|
17
|
+
stub_model(:city) do
|
18
|
+
update_index('cities') { self }
|
19
|
+
end
|
20
|
+
|
21
|
+
stub_index(:cities) do
|
22
|
+
index_scope City
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:city) { City.create!(name: 'hello') }
|
27
|
+
let(:other_city) { City.create!(name: 'world') }
|
28
|
+
|
29
|
+
it 'does not update indices synchronously' do
|
30
|
+
expect { [city, other_city].map(&:save!) }
|
31
|
+
.not_to update_index(CitiesIndex, strategy: :lazy_sidekiq)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'updates indices asynchronously on record save' do
|
35
|
+
expect(::Sidekiq::Client).to receive(:push)
|
36
|
+
.with(hash_including(
|
37
|
+
'class' => Chewy::Strategy::LazySidekiq::IndicesUpdateWorker,
|
38
|
+
'queue' => 'low'
|
39
|
+
))
|
40
|
+
.and_call_original
|
41
|
+
.once
|
42
|
+
::Sidekiq::Testing.inline! do
|
43
|
+
expect { [city, other_city].map(&:save!) }
|
44
|
+
.to update_index(CitiesIndex, strategy: :lazy_sidekiq)
|
45
|
+
.and_reindex(city, other_city).only
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'updates indices asynchronously with falling back to sidekiq strategy on record destroy' do
|
50
|
+
expect(::Sidekiq::Client).not_to receive(:push)
|
51
|
+
.with(hash_including(
|
52
|
+
'class' => Chewy::Strategy::LazySidekiq::IndicesUpdateWorker,
|
53
|
+
'queue' => 'low'
|
54
|
+
))
|
55
|
+
expect(::Sidekiq::Client).to receive(:push)
|
56
|
+
.with(hash_including(
|
57
|
+
'class' => Chewy::Strategy::Sidekiq::Worker,
|
58
|
+
'queue' => 'low',
|
59
|
+
'args' => ['CitiesIndex', [city.id, other_city.id]]
|
60
|
+
))
|
61
|
+
.and_call_original
|
62
|
+
.once
|
63
|
+
::Sidekiq::Testing.inline! do
|
64
|
+
expect { [city, other_city].map(&:destroy) }.to update_index(CitiesIndex, strategy: :sidekiq)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'calls Index#import!' do
|
69
|
+
allow(City).to receive(:where).with(id: [city.id, other_city.id]).and_return([city, other_city])
|
70
|
+
expect(city).to receive(:run_chewy_callbacks).and_call_original
|
71
|
+
expect(other_city).to receive(:run_chewy_callbacks).and_call_original
|
72
|
+
|
73
|
+
expect do
|
74
|
+
::Sidekiq::Testing.inline! do
|
75
|
+
Chewy::Strategy::LazySidekiq::IndicesUpdateWorker.new.perform({'City' => [city.id, other_city.id]})
|
76
|
+
end
|
77
|
+
end.to update_index(CitiesIndex).and_reindex(city, other_city).only
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when Chewy.disable_refresh_async is true' do
|
81
|
+
before do
|
82
|
+
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'calls Index#import! with refresh false' do
|
86
|
+
allow(City).to receive(:where).with(id: [city.id, other_city.id]).and_return([city, other_city])
|
87
|
+
expect(city).to receive(:run_chewy_callbacks).and_call_original
|
88
|
+
expect(other_city).to receive(:run_chewy_callbacks).and_call_original
|
89
|
+
|
90
|
+
expect do
|
91
|
+
::Sidekiq::Testing.inline! do
|
92
|
+
Chewy::Strategy::LazySidekiq::IndicesUpdateWorker.new.perform({'City' => [city.id, other_city.id]})
|
93
|
+
end
|
94
|
+
end.to update_index(CitiesIndex).and_reindex(city, other_city).only.no_refresh
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'integration' do
|
100
|
+
around { |example| ::Sidekiq::Testing.inline! { example.run } }
|
101
|
+
|
102
|
+
let(:update_condition) { true }
|
103
|
+
|
104
|
+
before do
|
105
|
+
city_model
|
106
|
+
country_model
|
107
|
+
|
108
|
+
City.belongs_to :country
|
109
|
+
Country.has_many :cities
|
110
|
+
|
111
|
+
stub_index(:cities) do
|
112
|
+
index_scope City
|
113
|
+
end
|
114
|
+
|
115
|
+
stub_index(:countries) do
|
116
|
+
index_scope Country
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'state dependent' do
|
121
|
+
let(:city_model) do
|
122
|
+
stub_model(:city) do
|
123
|
+
update_index(-> { 'cities' }, :self)
|
124
|
+
update_index('countries') { changes['country_id'] || previous_changes['country_id'] || country }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
let(:country_model) do
|
129
|
+
stub_model(:country) do
|
130
|
+
update_index('cities', if: -> { state_dependent_update_condition }) { cities }
|
131
|
+
update_index(-> { 'countries' }, :self)
|
132
|
+
attr_accessor :state_dependent_update_condition
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'city updates' do
|
137
|
+
let!(:country1) { Country.create!(id: 1) }
|
138
|
+
let!(:country2) { Country.create!(id: 2) }
|
139
|
+
let!(:city) { City.create!(id: 1, country: country1) }
|
140
|
+
|
141
|
+
it 'does not update index of removed entity because model state on the moment of save cannot be fetched' do
|
142
|
+
expect { city.update!(country: nil) }.not_to update_index('countries', strategy: :lazy_sidekiq)
|
143
|
+
end
|
144
|
+
it 'does not update index of removed entity because model state on the moment of save cannot be fetched' do
|
145
|
+
expect { city.update!(country: country2) }.to update_index('countries', strategy: :lazy_sidekiq).and_reindex(country2).only
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'country updates' do
|
150
|
+
let!(:country) do
|
151
|
+
cities = Array.new(2) { |i| City.create!(id: i) }
|
152
|
+
Country.create!(id: 1, cities: cities, state_dependent_update_condition: update_condition)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'does not update index because state of attribute cannot be fetched' do
|
156
|
+
expect { country.save! }.not_to update_index('cities', strategy: :lazy_sidekiq)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'state independent' do
|
162
|
+
let(:city_model) do
|
163
|
+
stub_model(:city) do
|
164
|
+
update_index(-> { 'cities' }, :self)
|
165
|
+
update_index('countries') { country }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
let(:country_model) do
|
170
|
+
stub_model(:country) do
|
171
|
+
update_index('cities', if: -> { state_independent_update_condition }) { cities }
|
172
|
+
update_index(-> { 'countries' }, :self)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
before do
|
177
|
+
allow_any_instance_of(Country).to receive(:state_independent_update_condition).and_return(update_condition)
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'when city updates' do
|
181
|
+
let!(:country1) { Country.create!(id: 1) }
|
182
|
+
let!(:country2) { Country.create!(id: 2) }
|
183
|
+
let!(:city) { City.create!(id: 1, country: country1) }
|
184
|
+
|
185
|
+
specify { expect { city.save! }.to update_index('cities', strategy: :lazy_sidekiq).and_reindex(city).only }
|
186
|
+
specify { expect { city.save! }.to update_index('countries', strategy: :lazy_sidekiq).and_reindex(country1).only }
|
187
|
+
|
188
|
+
specify { expect { city.destroy }.not_to update_index('cities').and_reindex(city).only }
|
189
|
+
specify { expect { city.destroy }.to update_index('countries', strategy: :sidekiq).and_reindex(country1).only }
|
190
|
+
|
191
|
+
specify { expect { city.update!(country: nil) }.to update_index('cities', strategy: :lazy_sidekiq).and_reindex(city).only }
|
192
|
+
specify { expect { city.update!(country: country2) }.to update_index('cities', strategy: :lazy_sidekiq).and_reindex(city).only }
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when country updates' do
|
196
|
+
let!(:country) do
|
197
|
+
cities = Array.new(2) { |i| City.create!(id: i) }
|
198
|
+
Country.create!(id: 1, cities: cities)
|
199
|
+
end
|
200
|
+
specify { expect { country.save! }.to update_index('cities', strategy: :lazy_sidekiq).and_reindex(country.cities).only }
|
201
|
+
specify { expect { country.save! }.to update_index('countries', strategy: :lazy_sidekiq).and_reindex(country).only }
|
202
|
+
|
203
|
+
specify { expect { country.destroy }.to update_index('cities', strategy: :sidekiq).and_reindex(country.cities).only }
|
204
|
+
specify { expect { country.destroy }.not_to update_index('countries').and_reindex(country).only }
|
205
|
+
|
206
|
+
context 'when update condition is false' do
|
207
|
+
let(:update_condition) { false }
|
208
|
+
specify { expect { country.save! }.not_to update_index('cities', strategy: :lazy_sidekiq) }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -4,15 +4,20 @@ 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
|
11
|
-
update_index('cities
|
16
|
+
update_index('cities') { self }
|
12
17
|
end
|
13
18
|
|
14
19
|
stub_index(:cities) do
|
15
|
-
|
20
|
+
index_scope City
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
@@ -21,20 +26,27 @@ if defined?(::Sidekiq)
|
|
21
26
|
|
22
27
|
specify do
|
23
28
|
expect { [city, other_city].map(&:save!) }
|
24
|
-
.not_to update_index(CitiesIndex
|
29
|
+
.not_to update_index(CitiesIndex, strategy: :sidekiq)
|
25
30
|
end
|
26
31
|
|
27
32
|
specify do
|
33
|
+
expect(::Sidekiq::Client).to receive(:push).with(hash_including('queue' => 'low')).and_call_original
|
28
34
|
::Sidekiq::Testing.inline! do
|
29
35
|
expect { [city, other_city].map(&:save!) }
|
30
|
-
.to update_index(CitiesIndex
|
36
|
+
.to update_index(CitiesIndex, strategy: :sidekiq)
|
31
37
|
.and_reindex(city, other_city).only
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
35
41
|
specify do
|
36
|
-
expect(CitiesIndex
|
37
|
-
Chewy::Strategy::Sidekiq::Worker.new.perform(
|
42
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
|
43
|
+
Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
44
|
+
end
|
45
|
+
|
46
|
+
specify do
|
47
|
+
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
48
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
|
49
|
+
Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
38
50
|
end
|
39
51
|
end
|
40
52
|
end
|