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
@@ -0,0 +1,656 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
describe Chewy::RakeHelper, :orm do
|
5
|
+
before { Chewy.massacre }
|
6
|
+
|
7
|
+
before do
|
8
|
+
described_class.instance_variable_set(:@journal_exists, journal_exists)
|
9
|
+
|
10
|
+
stub_model(:city)
|
11
|
+
stub_model(:country)
|
12
|
+
|
13
|
+
stub_index(:cities) do
|
14
|
+
index_scope City
|
15
|
+
field :name
|
16
|
+
field :updated_at, type: 'date'
|
17
|
+
end
|
18
|
+
stub_index(:countries) do
|
19
|
+
index_scope Country
|
20
|
+
end
|
21
|
+
stub_index(:users)
|
22
|
+
|
23
|
+
allow(described_class).to receive(:all_indexes) { [CitiesIndex, CountriesIndex, UsersIndex] }
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:journal_exists) { true }
|
27
|
+
let!(:cities) { Array.new(3) { |i| City.create!(name: "Name#{i + 1}") } }
|
28
|
+
let!(:countries) { Array.new(2) { |i| Country.create!(name: "Name#{i + 1}") } }
|
29
|
+
let(:journal) do
|
30
|
+
Chewy::Stash::Journal.import([
|
31
|
+
{
|
32
|
+
index_name: 'cities',
|
33
|
+
type_name: 'city',
|
34
|
+
action: 'index',
|
35
|
+
references: cities.first(2).map(&:id).map(&:to_s)
|
36
|
+
.map(&:to_json).map(&Base64.method(:encode64)),
|
37
|
+
created_at: 2.minutes.since
|
38
|
+
},
|
39
|
+
{
|
40
|
+
index_name: 'countries',
|
41
|
+
type_name: 'country',
|
42
|
+
action: 'index',
|
43
|
+
references: [Base64.encode64(countries.first.id.to_s.to_json)],
|
44
|
+
created_at: 4.minutes.since
|
45
|
+
}
|
46
|
+
])
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.reset' do
|
50
|
+
before { journal }
|
51
|
+
|
52
|
+
specify do
|
53
|
+
output = StringIO.new
|
54
|
+
expect { described_class.reset(output: output) }
|
55
|
+
.to update_index(CitiesIndex)
|
56
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
57
|
+
\\AResetting CitiesIndex
|
58
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
59
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
60
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
61
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
62
|
+
Resetting CountriesIndex
|
63
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
64
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
65
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
66
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
67
|
+
Resetting UsersIndex
|
68
|
+
Imported UsersIndex in 1s, stats:\s
|
69
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
70
|
+
Total: \\d+s\\Z
|
71
|
+
OUTPUT
|
72
|
+
end
|
73
|
+
|
74
|
+
specify do
|
75
|
+
output = StringIO.new
|
76
|
+
expect { described_class.reset(only: 'cities', output: output) }
|
77
|
+
.to update_index(CitiesIndex)
|
78
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
79
|
+
\\AResetting CitiesIndex
|
80
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
81
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
82
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
83
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
84
|
+
Total: \\d+s\\Z
|
85
|
+
OUTPUT
|
86
|
+
end
|
87
|
+
|
88
|
+
specify do
|
89
|
+
output = StringIO.new
|
90
|
+
expect { described_class.reset(except: [CitiesIndex, CountriesIndex], output: output) }
|
91
|
+
.not_to update_index(CitiesIndex)
|
92
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
93
|
+
\\AResetting UsersIndex
|
94
|
+
Imported UsersIndex in 1s, stats:\s
|
95
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
96
|
+
Total: \\d+s\\Z
|
97
|
+
OUTPUT
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when journal is missing' do
|
101
|
+
let(:journal_exists) { false }
|
102
|
+
|
103
|
+
specify do
|
104
|
+
output = StringIO.new
|
105
|
+
expect { described_class.reset(only: [CitiesIndex], output: output) }
|
106
|
+
.to update_index(CitiesIndex)
|
107
|
+
expect(output.string).to include(
|
108
|
+
"############################################################\n"\
|
109
|
+
"WARN: You are risking to lose some changes during the reset.\n" \
|
110
|
+
" Please consider enabling journaling.\n" \
|
111
|
+
' See https://github.com/toptal/chewy#journaling'
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.upgrade' do
|
118
|
+
specify do
|
119
|
+
output = StringIO.new
|
120
|
+
expect { described_class.upgrade(output: output) }
|
121
|
+
.to update_index(CitiesIndex)
|
122
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
123
|
+
\\AResetting CitiesIndex
|
124
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
125
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
126
|
+
Resetting CountriesIndex
|
127
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
128
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
129
|
+
Resetting UsersIndex
|
130
|
+
Imported UsersIndex in 1s, stats:\s
|
131
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
132
|
+
Total: \\d+s\\Z
|
133
|
+
OUTPUT
|
134
|
+
end
|
135
|
+
|
136
|
+
context do
|
137
|
+
before do
|
138
|
+
CitiesIndex.reset!
|
139
|
+
CountriesIndex.reset!
|
140
|
+
end
|
141
|
+
|
142
|
+
specify do
|
143
|
+
output = StringIO.new
|
144
|
+
expect { described_class.upgrade(output: output) }
|
145
|
+
.not_to update_index(CitiesIndex)
|
146
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
147
|
+
\\ASkipping CitiesIndex, the specification didn't change
|
148
|
+
Skipping CountriesIndex, the specification didn't change
|
149
|
+
Resetting UsersIndex
|
150
|
+
Imported UsersIndex in 1s, stats:\s
|
151
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
152
|
+
Total: \\d+s\\Z
|
153
|
+
OUTPUT
|
154
|
+
end
|
155
|
+
|
156
|
+
specify do
|
157
|
+
output = StringIO.new
|
158
|
+
expect { described_class.upgrade(except: [CitiesIndex, CountriesIndex], output: output) }
|
159
|
+
.not_to update_index(CitiesIndex)
|
160
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
161
|
+
\\AResetting UsersIndex
|
162
|
+
Imported UsersIndex in 1s, stats:\s
|
163
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
164
|
+
Total: \\d+s\\Z
|
165
|
+
OUTPUT
|
166
|
+
end
|
167
|
+
|
168
|
+
context do
|
169
|
+
before { UsersIndex.reset! }
|
170
|
+
|
171
|
+
specify do
|
172
|
+
output = StringIO.new
|
173
|
+
expect { described_class.upgrade(except: %w[cities countries], output: output) }
|
174
|
+
.not_to update_index(CitiesIndex)
|
175
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
176
|
+
\\ANo index specification was changed
|
177
|
+
Total: \\d+s\\Z
|
178
|
+
OUTPUT
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '.update' do
|
185
|
+
specify do
|
186
|
+
output = StringIO.new
|
187
|
+
expect { described_class.update(output: output) }
|
188
|
+
.not_to update_index(CitiesIndex)
|
189
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
190
|
+
\\ASkipping CitiesIndex, it does not exists \\(use rake chewy:reset\\[cities\\] to create and update it\\)
|
191
|
+
Skipping CountriesIndex, it does not exists \\(use rake chewy:reset\\[countries\\] to create and update it\\)
|
192
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
193
|
+
Total: \\d+s\\Z
|
194
|
+
OUTPUT
|
195
|
+
end
|
196
|
+
|
197
|
+
context do
|
198
|
+
before do
|
199
|
+
CitiesIndex.reset!
|
200
|
+
CountriesIndex.reset!
|
201
|
+
end
|
202
|
+
|
203
|
+
specify do
|
204
|
+
output = StringIO.new
|
205
|
+
expect { described_class.update(output: output) }
|
206
|
+
.to update_index(CitiesIndex)
|
207
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
208
|
+
\\AUpdating CitiesIndex
|
209
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
210
|
+
Updating CountriesIndex
|
211
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
212
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
213
|
+
Total: \\d+s\\Z
|
214
|
+
OUTPUT
|
215
|
+
end
|
216
|
+
|
217
|
+
specify do
|
218
|
+
output = StringIO.new
|
219
|
+
expect { described_class.update(only: 'countries', output: output) }
|
220
|
+
.not_to update_index(CitiesIndex)
|
221
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
222
|
+
\\AUpdating CountriesIndex
|
223
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
224
|
+
Total: \\d+s\\Z
|
225
|
+
OUTPUT
|
226
|
+
end
|
227
|
+
|
228
|
+
specify do
|
229
|
+
output = StringIO.new
|
230
|
+
expect { described_class.update(except: CountriesIndex, output: output) }
|
231
|
+
.to update_index(CitiesIndex)
|
232
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
233
|
+
\\AUpdating CitiesIndex
|
234
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
235
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
236
|
+
Total: \\d+s\\Z
|
237
|
+
OUTPUT
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe '.sync' do
|
243
|
+
specify do
|
244
|
+
output = StringIO.new
|
245
|
+
expect { described_class.sync(output: output) }
|
246
|
+
.to update_index(CitiesIndex)
|
247
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
248
|
+
\\ASynchronizing CitiesIndex
|
249
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
250
|
+
Missing documents: \\[[^\\]]+\\]
|
251
|
+
Took \\d+s
|
252
|
+
Synchronizing CountriesIndex
|
253
|
+
CountriesIndex doesn't support outdated synchronization
|
254
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
255
|
+
Missing documents: \\[[^\\]]+\\]
|
256
|
+
Took \\d+s
|
257
|
+
Synchronizing UsersIndex
|
258
|
+
UsersIndex doesn't support outdated synchronization
|
259
|
+
Skipping UsersIndex, up to date
|
260
|
+
Took \\d+s
|
261
|
+
Total: \\d+s\\Z
|
262
|
+
OUTPUT
|
263
|
+
end
|
264
|
+
|
265
|
+
context do
|
266
|
+
before do
|
267
|
+
CitiesIndex.import(cities.first(2))
|
268
|
+
CountriesIndex.import
|
269
|
+
|
270
|
+
cities.first.update(name: 'Name5')
|
271
|
+
end
|
272
|
+
|
273
|
+
specify do
|
274
|
+
output = StringIO.new
|
275
|
+
expect { described_class.sync(output: output) }
|
276
|
+
.to update_index(CitiesIndex)
|
277
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
278
|
+
\\ASynchronizing CitiesIndex
|
279
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
280
|
+
Missing documents: \\["#{cities.last.id}"\\]
|
281
|
+
Outdated documents: \\["#{cities.first.id}"\\]
|
282
|
+
Took \\d+s
|
283
|
+
Synchronizing CountriesIndex
|
284
|
+
CountriesIndex doesn't support outdated synchronization
|
285
|
+
Skipping CountriesIndex, up to date
|
286
|
+
Took \\d+s
|
287
|
+
Synchronizing UsersIndex
|
288
|
+
UsersIndex doesn't support outdated synchronization
|
289
|
+
Skipping UsersIndex, up to date
|
290
|
+
Took \\d+s
|
291
|
+
Total: \\d+s\\Z
|
292
|
+
OUTPUT
|
293
|
+
end
|
294
|
+
|
295
|
+
specify do
|
296
|
+
output = StringIO.new
|
297
|
+
expect { described_class.sync(only: CitiesIndex, output: output) }
|
298
|
+
.to update_index(CitiesIndex)
|
299
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
300
|
+
\\ASynchronizing CitiesIndex
|
301
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
302
|
+
Missing documents: \\["#{cities.last.id}"\\]
|
303
|
+
Outdated documents: \\["#{cities.first.id}"\\]
|
304
|
+
Took \\d+s
|
305
|
+
Total: \\d+s\\Z
|
306
|
+
OUTPUT
|
307
|
+
end
|
308
|
+
|
309
|
+
specify do
|
310
|
+
output = StringIO.new
|
311
|
+
expect { described_class.sync(except: ['cities'], output: output) }
|
312
|
+
.not_to update_index(CitiesIndex)
|
313
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
314
|
+
\\ASynchronizing CountriesIndex
|
315
|
+
CountriesIndex doesn't support outdated synchronization
|
316
|
+
Skipping CountriesIndex, up to date
|
317
|
+
Took \\d+s
|
318
|
+
Synchronizing UsersIndex
|
319
|
+
UsersIndex doesn't support outdated synchronization
|
320
|
+
Skipping UsersIndex, up to date
|
321
|
+
Took \\d+s
|
322
|
+
Total: \\d+s\\Z
|
323
|
+
OUTPUT
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
describe '.journal_apply' do
|
329
|
+
specify { expect { described_class.journal_apply }.to raise_error ArgumentError }
|
330
|
+
specify do
|
331
|
+
output = StringIO.new
|
332
|
+
described_class.journal_apply(time: Time.now, output: output)
|
333
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
334
|
+
\\AApplying journal entries created after [+-:\\d\\s]+
|
335
|
+
No journal entries were created after the specified time
|
336
|
+
Total: \\d+s\\Z
|
337
|
+
OUTPUT
|
338
|
+
end
|
339
|
+
|
340
|
+
context do
|
341
|
+
before { journal }
|
342
|
+
|
343
|
+
specify do
|
344
|
+
output = StringIO.new
|
345
|
+
expect { described_class.journal_apply(time: Time.now, output: output) }
|
346
|
+
.to update_index(CitiesIndex)
|
347
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
348
|
+
\\AApplying journal entries created after [+-:\\d\\s]+
|
349
|
+
Applying journal to \\[CitiesIndex, CountriesIndex\\], 3 entries, stage 1
|
350
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
351
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
352
|
+
Total: \\d+s\\Z
|
353
|
+
OUTPUT
|
354
|
+
end
|
355
|
+
|
356
|
+
specify do
|
357
|
+
output = StringIO.new
|
358
|
+
expect { described_class.journal_apply(time: 3.minutes.since, output: output) }
|
359
|
+
.not_to update_index(CitiesIndex)
|
360
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
361
|
+
\\AApplying journal entries created after [+-:\\d\\s]+
|
362
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
363
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
364
|
+
Total: \\d+s\\Z
|
365
|
+
OUTPUT
|
366
|
+
end
|
367
|
+
|
368
|
+
specify do
|
369
|
+
output = StringIO.new
|
370
|
+
expect { described_class.journal_apply(time: Time.now, only: CitiesIndex, output: output) }
|
371
|
+
.to update_index(CitiesIndex)
|
372
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
373
|
+
\\AApplying journal entries created after [+-:\\d\\s]+
|
374
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
375
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
376
|
+
Total: \\d+s\\Z
|
377
|
+
OUTPUT
|
378
|
+
end
|
379
|
+
|
380
|
+
specify do
|
381
|
+
output = StringIO.new
|
382
|
+
expect { described_class.journal_apply(time: Time.now, except: CitiesIndex, output: output) }
|
383
|
+
.not_to update_index(CitiesIndex)
|
384
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
385
|
+
\\AApplying journal entries created after [+-:\\d\\s]+
|
386
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
387
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
388
|
+
Total: \\d+s\\Z
|
389
|
+
OUTPUT
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
describe '.journal_clean' do
|
395
|
+
before { journal }
|
396
|
+
|
397
|
+
specify do
|
398
|
+
output = StringIO.new
|
399
|
+
described_class.journal_clean(output: output)
|
400
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
401
|
+
\\ACleaned up 2 journal entries
|
402
|
+
Total: \\d+s\\Z
|
403
|
+
OUTPUT
|
404
|
+
end
|
405
|
+
|
406
|
+
specify do
|
407
|
+
output = StringIO.new
|
408
|
+
described_class.journal_clean(time: 3.minutes.since, output: output)
|
409
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
410
|
+
\\ACleaning journal entries created before [+-:\\d\\s]+
|
411
|
+
Cleaned up 1 journal entries
|
412
|
+
Total: \\d+s\\Z
|
413
|
+
OUTPUT
|
414
|
+
end
|
415
|
+
|
416
|
+
specify do
|
417
|
+
output = StringIO.new
|
418
|
+
described_class.journal_clean(only: CitiesIndex, output: output)
|
419
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
420
|
+
\\ACleaned up 1 journal entries
|
421
|
+
Total: \\d+s\\Z
|
422
|
+
OUTPUT
|
423
|
+
end
|
424
|
+
|
425
|
+
specify do
|
426
|
+
output = StringIO.new
|
427
|
+
described_class.journal_clean(except: CitiesIndex, output: output)
|
428
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
429
|
+
\\ACleaned up 1 journal entries
|
430
|
+
Total: \\d+s\\Z
|
431
|
+
OUTPUT
|
432
|
+
end
|
433
|
+
|
434
|
+
it 'executes asynchronously' do
|
435
|
+
output = StringIO.new
|
436
|
+
expect(Chewy.client).to receive(:delete_by_query).with(
|
437
|
+
{
|
438
|
+
body: {query: {match_all: {}}},
|
439
|
+
index: ['chewy_journal'],
|
440
|
+
refresh: false,
|
441
|
+
requests_per_second: 10.0,
|
442
|
+
scroll_size: 200,
|
443
|
+
wait_for_completion: false
|
444
|
+
}
|
445
|
+
).and_call_original
|
446
|
+
described_class.journal_clean(
|
447
|
+
output: output,
|
448
|
+
delete_by_query_options: {
|
449
|
+
wait_for_completion: false,
|
450
|
+
requests_per_second: 10.0,
|
451
|
+
scroll_size: 200
|
452
|
+
}
|
453
|
+
)
|
454
|
+
|
455
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
456
|
+
\\ATask to cleanup the journal has been created, [^\\n]*
|
457
|
+
Total: \\d+s\\Z
|
458
|
+
OUTPUT
|
459
|
+
end
|
460
|
+
|
461
|
+
context 'execute "chewy:journal:clean" rake task' do
|
462
|
+
subject(:task) { Rake.application['chewy:journal:clean'] }
|
463
|
+
before do
|
464
|
+
Rake::DefaultLoader.new.load('lib/tasks/chewy.rake')
|
465
|
+
Rake::Task.define_task(:environment)
|
466
|
+
end
|
467
|
+
it 'does not raise error' do
|
468
|
+
expect { task.invoke }.to_not raise_error
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
describe '.create_missing_indexes!' do
|
474
|
+
before do
|
475
|
+
[CountriesIndex, Chewy::Stash::Specification].map(&:create!)
|
476
|
+
|
477
|
+
# To avoid flaky issues when previous specs were run
|
478
|
+
expect(Chewy::Index).to receive(:descendants).and_return(
|
479
|
+
[
|
480
|
+
UsersIndex,
|
481
|
+
CountriesIndex,
|
482
|
+
CitiesIndex,
|
483
|
+
Chewy::Stash::Specification,
|
484
|
+
Chewy::Stash::Journal
|
485
|
+
]
|
486
|
+
)
|
487
|
+
end
|
488
|
+
|
489
|
+
specify do
|
490
|
+
output = StringIO.new
|
491
|
+
described_class.create_missing_indexes!(output: output)
|
492
|
+
expect(CitiesIndex.exists?).to be_truthy
|
493
|
+
expect(UsersIndex.exists?).to be_truthy
|
494
|
+
expect(Chewy::Stash::Journal.exists?).to be_falsey
|
495
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
496
|
+
UsersIndex index successfully created
|
497
|
+
CitiesIndex index successfully created
|
498
|
+
Total: \\d+s\\Z
|
499
|
+
OUTPUT
|
500
|
+
end
|
501
|
+
|
502
|
+
context 'when verbose' do
|
503
|
+
specify do
|
504
|
+
output = StringIO.new
|
505
|
+
described_class.create_missing_indexes!(output: output, env: {'VERBOSE' => '1'})
|
506
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
507
|
+
UsersIndex index successfully created
|
508
|
+
CountriesIndex already exists, skipping
|
509
|
+
CitiesIndex index successfully created
|
510
|
+
Chewy::Stash::Specification already exists, skipping
|
511
|
+
Total: \\d+s\\Z
|
512
|
+
OUTPUT
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
context 'when journaling is enabled' do
|
517
|
+
before { Chewy.config.settings[:journal] = true }
|
518
|
+
after { Chewy.config.settings.delete(:journal) }
|
519
|
+
specify do
|
520
|
+
described_class.create_missing_indexes!(output: StringIO.new)
|
521
|
+
expect(Chewy::Stash::Journal.exists?).to be_truthy
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
describe '.journal_create' do
|
527
|
+
specify do
|
528
|
+
output = StringIO.new
|
529
|
+
described_class.journal_create(output: output)
|
530
|
+
expect(Chewy::Stash::Journal.exists?).to be_truthy
|
531
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
532
|
+
Total: \\d+s\\Z
|
533
|
+
OUTPUT
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
describe '.reindex' do
|
538
|
+
before do
|
539
|
+
journal
|
540
|
+
CitiesIndex.create!
|
541
|
+
CountriesIndex.create!
|
542
|
+
end
|
543
|
+
|
544
|
+
let(:source_index) { 'cities' }
|
545
|
+
let(:dest_index) { 'countries' }
|
546
|
+
|
547
|
+
context 'with correct arguments' do
|
548
|
+
specify do
|
549
|
+
output = StringIO.new
|
550
|
+
described_class.reindex(source: source_index, dest: dest_index, output: output)
|
551
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
552
|
+
\\Source index is cities
|
553
|
+
\\Destination index is countries
|
554
|
+
cities index successfully reindexed with countries index data
|
555
|
+
Total: \\d+s\\Z
|
556
|
+
OUTPUT
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
context 'with missing indexes' do
|
561
|
+
context 'without dest index' do
|
562
|
+
specify do
|
563
|
+
output = StringIO.new
|
564
|
+
expect { described_class.reindex(source: source_index, output: output) }
|
565
|
+
.to raise_error ArgumentError
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
context 'without source index' do
|
570
|
+
specify do
|
571
|
+
output = StringIO.new
|
572
|
+
expect { described_class.reindex(dest: dest_index, output: output) }
|
573
|
+
.to raise_error ArgumentError
|
574
|
+
end
|
575
|
+
end
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
describe '.update_mapping' do
|
580
|
+
before do
|
581
|
+
journal
|
582
|
+
CitiesIndex.create!
|
583
|
+
end
|
584
|
+
|
585
|
+
let(:index_name) { CitiesIndex.index_name }
|
586
|
+
let(:nonexistent_index) { 'wrong_index' }
|
587
|
+
|
588
|
+
context 'with existing index' do
|
589
|
+
specify do
|
590
|
+
output = StringIO.new
|
591
|
+
described_class.update_mapping(name: index_name, output: output)
|
592
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
593
|
+
\\Index name is cities
|
594
|
+
cities index successfully updated
|
595
|
+
Total: \\d+s\\Z
|
596
|
+
OUTPUT
|
597
|
+
end
|
598
|
+
end
|
599
|
+
|
600
|
+
context 'with non-existent index name' do
|
601
|
+
specify do
|
602
|
+
output = StringIO.new
|
603
|
+
expect { described_class.update_mapping(name: nonexistent_index, output: output) }
|
604
|
+
.to raise_error NameError
|
605
|
+
end
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
describe '.delete_by_query_options_from_env' do
|
610
|
+
subject(:options) { described_class.delete_by_query_options_from_env(env) }
|
611
|
+
let(:env) do
|
612
|
+
{
|
613
|
+
'WAIT_FOR_COMPLETION' => 'false',
|
614
|
+
'REQUESTS_PER_SECOND' => '10',
|
615
|
+
'SCROLL_SIZE' => '5000'
|
616
|
+
}
|
617
|
+
end
|
618
|
+
|
619
|
+
it 'parses the options' do
|
620
|
+
expect(options).to eq(
|
621
|
+
wait_for_completion: false,
|
622
|
+
requests_per_second: 10.0,
|
623
|
+
scroll_size: 5000
|
624
|
+
)
|
625
|
+
end
|
626
|
+
|
627
|
+
context 'with different boolean values' do
|
628
|
+
it 'parses the option correctly' do
|
629
|
+
%w[1 t true TRUE on ON].each do |v|
|
630
|
+
expect(described_class.delete_by_query_options_from_env({'WAIT_FOR_COMPLETION' => v}))
|
631
|
+
.to eq(wait_for_completion: true)
|
632
|
+
end
|
633
|
+
|
634
|
+
%w[0 f false FALSE off OFF].each do |v|
|
635
|
+
expect(described_class.delete_by_query_options_from_env({'WAIT_FOR_COMPLETION' => v}))
|
636
|
+
.to eq(wait_for_completion: false)
|
637
|
+
end
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
context 'with other env' do
|
642
|
+
let(:env) { {'SOME_ENV' => '123', 'REQUESTS_PER_SECOND' => '15'} }
|
643
|
+
|
644
|
+
it 'parses only the options' do
|
645
|
+
expect(options).to eq(requests_per_second: 15.0)
|
646
|
+
end
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
650
|
+
describe '.subscribed_task_stats' do
|
651
|
+
specify do
|
652
|
+
block_output = described_class.subscribed_task_stats(StringIO.new) { 'expected output' }
|
653
|
+
expect(block_output).to eq('expected output')
|
654
|
+
end
|
655
|
+
end
|
656
|
+
end
|
@@ -13,8 +13,8 @@ describe Chewy::Repository do
|
|
13
13
|
|
14
14
|
context do
|
15
15
|
before { subject.analyzer(:name, option: :foo) }
|
16
|
-
specify { expect(subject.analyzer(:name)).to eq(
|
17
|
-
specify { expect(subject.analyzers).to eq(
|
16
|
+
specify { expect(subject.analyzer(:name)).to eq(option: :foo) }
|
17
|
+
specify { expect(subject.analyzers).to eq(name: {option: :foo}) }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -23,8 +23,8 @@ describe Chewy::Repository do
|
|
23
23
|
|
24
24
|
context do
|
25
25
|
before { subject.tokenizer(:name, option: :foo) }
|
26
|
-
specify { expect(subject.tokenizer(:name)).to eq(
|
27
|
-
specify { expect(subject.tokenizers).to eq(
|
26
|
+
specify { expect(subject.tokenizer(:name)).to eq(option: :foo) }
|
27
|
+
specify { expect(subject.tokenizers).to eq(name: {option: :foo}) }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -33,8 +33,8 @@ describe Chewy::Repository do
|
|
33
33
|
|
34
34
|
context do
|
35
35
|
before { subject.filter(:name, option: :foo) }
|
36
|
-
specify { expect(subject.filter(:name)).to eq(
|
37
|
-
specify { expect(subject.filters).to eq(
|
36
|
+
specify { expect(subject.filter(:name)).to eq(option: :foo) }
|
37
|
+
specify { expect(subject.filters).to eq(name: {option: :foo}) }
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -43,8 +43,8 @@ describe Chewy::Repository do
|
|
43
43
|
|
44
44
|
context do
|
45
45
|
before { subject.char_filter(:name, option: :foo) }
|
46
|
-
specify { expect(subject.char_filter(:name)).to eq(
|
47
|
-
specify { expect(subject.char_filters).to eq(
|
46
|
+
specify { expect(subject.char_filter(:name)).to eq(option: :foo) }
|
47
|
+
specify { expect(subject.char_filters).to eq(name: {option: :foo}) }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|