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
@@ -3,7 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe Chewy::Index::Actions do
|
4
4
|
before { Chewy.massacre }
|
5
5
|
|
6
|
-
before
|
6
|
+
before do
|
7
|
+
stub_index :dummies
|
8
|
+
stub_index :dummies_suffixed
|
9
|
+
end
|
7
10
|
|
8
11
|
describe '.exists?' do
|
9
12
|
specify { expect(DummiesIndex.exists?).to eq(false) }
|
@@ -25,26 +28,40 @@ describe Chewy::Index::Actions do
|
|
25
28
|
end
|
26
29
|
|
27
30
|
context do
|
28
|
-
before
|
31
|
+
before do
|
32
|
+
DummiesIndex.create '2013'
|
33
|
+
DummiesSuffixedIndex.create 'should_not_appear'
|
34
|
+
end
|
35
|
+
|
29
36
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
|
30
37
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
|
31
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
38
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
32
39
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
33
40
|
specify { expect(DummiesIndex.create('2013')).to eq(false) }
|
34
41
|
specify { expect(DummiesIndex.create('2014')['acknowledged']).to eq(true) }
|
35
42
|
|
36
43
|
context do
|
37
44
|
before { DummiesIndex.create '2014' }
|
38
|
-
|
45
|
+
|
46
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
50
|
context do
|
43
|
-
before
|
51
|
+
before do
|
52
|
+
DummiesIndex.create '2013', alias: false
|
53
|
+
DummiesSuffixedIndex.create 'should_not_appear'
|
54
|
+
end
|
55
|
+
|
44
56
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
45
57
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
|
46
58
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
47
59
|
specify { expect(DummiesIndex.indexes).to eq([]) }
|
60
|
+
specify { expect(DummiesIndex.exists?).to eq(false) }
|
61
|
+
# Unfortunately, without alias we can't figure out that this dummies_2013 index is related to DummiesIndex
|
62
|
+
# it would be awesome to have the following specs passing
|
63
|
+
# specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
64
|
+
# specify { expect(DummiesIndex.exists?).to eq(true) }
|
48
65
|
end
|
49
66
|
end
|
50
67
|
|
@@ -53,46 +70,62 @@ describe Chewy::Index::Actions do
|
|
53
70
|
specify { expect(DummiesIndex.create!('2013')['acknowledged']).to eq(true) }
|
54
71
|
|
55
72
|
context do
|
56
|
-
before
|
73
|
+
before do
|
74
|
+
DummiesIndex.create
|
75
|
+
DummiesSuffixedIndex.create 'should_not_appear'
|
76
|
+
end
|
77
|
+
|
57
78
|
specify do
|
58
|
-
|
59
|
-
|
79
|
+
expect do
|
80
|
+
DummiesIndex.create!
|
81
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies/)
|
60
82
|
end
|
61
83
|
specify do
|
62
|
-
|
63
|
-
|
84
|
+
expect do
|
85
|
+
DummiesIndex.create!('2013')
|
86
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/)
|
64
87
|
end
|
65
|
-
specify { expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/) }
|
66
88
|
end
|
67
89
|
|
68
90
|
context do
|
69
|
-
before
|
91
|
+
before do
|
92
|
+
DummiesIndex.create! '2013'
|
93
|
+
DummiesSuffixedIndex.create! 'should_not_appear'
|
94
|
+
end
|
95
|
+
|
70
96
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
|
71
97
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
|
72
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
98
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
73
99
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
74
100
|
specify do
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
specify do
|
79
|
-
skip_on_version_lt('2.0', 'format of exception was changed')
|
80
|
-
expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies_2013/)
|
101
|
+
expect do
|
102
|
+
DummiesIndex.create!('2013')
|
103
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies_2013/)
|
81
104
|
end
|
82
105
|
specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
|
83
106
|
|
84
107
|
context do
|
85
108
|
before { DummiesIndex.create! '2014' }
|
86
|
-
|
109
|
+
|
110
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
87
111
|
end
|
88
112
|
end
|
89
113
|
|
90
114
|
context do
|
91
|
-
before
|
115
|
+
before do
|
116
|
+
DummiesIndex.create! '2013', alias: false
|
117
|
+
DummiesSuffixedIndex.create! 'should_not_appear'
|
118
|
+
end
|
119
|
+
|
92
120
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
93
121
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
|
94
122
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
95
123
|
specify { expect(DummiesIndex.indexes).to eq([]) }
|
124
|
+
specify { expect(DummiesIndex.exists?).to eq(false) }
|
125
|
+
# Unfortunately, without alias we can't figure out that this dummies_2013 index is related to DummiesIndex
|
126
|
+
# it would be awesome to have the following specs passing
|
127
|
+
# specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
128
|
+
# specify { expect(DummiesIndex.exists?).to eq(true) }
|
96
129
|
end
|
97
130
|
end
|
98
131
|
|
@@ -101,27 +134,40 @@ describe Chewy::Index::Actions do
|
|
101
134
|
specify { expect(DummiesIndex.delete('dummies_2013')).to eq(false) }
|
102
135
|
|
103
136
|
context do
|
104
|
-
before
|
137
|
+
before do
|
138
|
+
DummiesIndex.create
|
139
|
+
DummiesSuffixedIndex.create 'should_not_appear'
|
140
|
+
end
|
141
|
+
|
105
142
|
specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
|
106
143
|
|
107
144
|
context do
|
108
145
|
before { DummiesIndex.delete }
|
109
146
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
147
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
110
148
|
end
|
111
149
|
end
|
112
150
|
|
113
151
|
context do
|
114
|
-
before
|
152
|
+
before do
|
153
|
+
DummiesIndex.create '2013'
|
154
|
+
DummiesSuffixedIndex.create 'should_not_appear'
|
155
|
+
end
|
156
|
+
|
115
157
|
specify { expect(DummiesIndex.delete('2013')['acknowledged']).to eq(true) }
|
116
158
|
|
117
159
|
context do
|
118
160
|
before { DummiesIndex.delete('2013') }
|
119
161
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
120
162
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
|
163
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
121
164
|
end
|
122
165
|
|
123
166
|
context do
|
124
|
-
before
|
167
|
+
before do
|
168
|
+
DummiesIndex.create '2014'
|
169
|
+
end
|
170
|
+
|
125
171
|
specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
|
126
172
|
|
127
173
|
context do
|
@@ -129,6 +175,7 @@ describe Chewy::Index::Actions do
|
|
129
175
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
130
176
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
|
131
177
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
|
178
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
132
179
|
end
|
133
180
|
|
134
181
|
context do
|
@@ -136,6 +183,7 @@ describe Chewy::Index::Actions do
|
|
136
183
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
|
137
184
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
|
138
185
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
|
186
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
139
187
|
end
|
140
188
|
end
|
141
189
|
end
|
@@ -143,30 +191,45 @@ describe Chewy::Index::Actions do
|
|
143
191
|
|
144
192
|
describe '.delete!' do
|
145
193
|
specify { expect { DummiesIndex.delete! }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) }
|
146
|
-
specify
|
194
|
+
specify do
|
195
|
+
expect do
|
196
|
+
DummiesIndex.delete!('2013')
|
197
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
198
|
+
end
|
147
199
|
|
148
200
|
context do
|
149
|
-
before
|
201
|
+
before do
|
202
|
+
DummiesIndex.create
|
203
|
+
DummiesSuffixedIndex.create 'should_not_appear'
|
204
|
+
end
|
205
|
+
|
150
206
|
specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
|
151
207
|
|
152
208
|
context do
|
153
209
|
before { DummiesIndex.delete! }
|
154
210
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
211
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
155
212
|
end
|
156
213
|
end
|
157
214
|
|
158
215
|
context do
|
159
|
-
before
|
216
|
+
before do
|
217
|
+
DummiesIndex.create '2013'
|
218
|
+
DummiesSuffixedIndex.create 'should_not_appear'
|
219
|
+
end
|
220
|
+
|
160
221
|
specify { expect(DummiesIndex.delete!('2013')['acknowledged']).to eq(true) }
|
161
222
|
|
162
223
|
context do
|
163
224
|
before { DummiesIndex.delete!('2013') }
|
164
225
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
165
226
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
|
227
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
166
228
|
end
|
167
229
|
|
168
230
|
context do
|
169
231
|
before { DummiesIndex.create '2014' }
|
232
|
+
|
170
233
|
specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
|
171
234
|
|
172
235
|
context do
|
@@ -174,6 +237,7 @@ describe Chewy::Index::Actions do
|
|
174
237
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
|
175
238
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
|
176
239
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
|
240
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
177
241
|
end
|
178
242
|
|
179
243
|
context do
|
@@ -181,6 +245,7 @@ describe Chewy::Index::Actions do
|
|
181
245
|
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
|
182
246
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
|
183
247
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
|
248
|
+
specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
|
184
249
|
end
|
185
250
|
end
|
186
251
|
end
|
@@ -194,19 +259,19 @@ describe Chewy::Index::Actions do
|
|
194
259
|
before { DummiesIndex.purge }
|
195
260
|
specify { expect(DummiesIndex).to be_exists }
|
196
261
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
197
|
-
specify { expect(DummiesIndex.indexes).to eq([]) }
|
262
|
+
specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
|
198
263
|
|
199
264
|
context do
|
200
265
|
before { DummiesIndex.purge }
|
201
266
|
specify { expect(DummiesIndex).to be_exists }
|
202
267
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
203
|
-
specify { expect(DummiesIndex.indexes).to eq([]) }
|
268
|
+
specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
|
204
269
|
end
|
205
270
|
|
206
271
|
context do
|
207
272
|
before { DummiesIndex.purge('2013') }
|
208
273
|
specify { expect(DummiesIndex).to be_exists }
|
209
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
274
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
210
275
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
211
276
|
end
|
212
277
|
end
|
@@ -214,20 +279,20 @@ describe Chewy::Index::Actions do
|
|
214
279
|
context do
|
215
280
|
before { DummiesIndex.purge('2013') }
|
216
281
|
specify { expect(DummiesIndex).to be_exists }
|
217
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
282
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
218
283
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
219
284
|
|
220
285
|
context do
|
221
286
|
before { DummiesIndex.purge }
|
222
287
|
specify { expect(DummiesIndex).to be_exists }
|
223
288
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
224
|
-
specify { expect(DummiesIndex.indexes).to eq([]) }
|
289
|
+
specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
|
225
290
|
end
|
226
291
|
|
227
292
|
context do
|
228
293
|
before { DummiesIndex.purge('2014') }
|
229
294
|
specify { expect(DummiesIndex).to be_exists }
|
230
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
295
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
231
296
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2014']) }
|
232
297
|
end
|
233
298
|
end
|
@@ -241,19 +306,19 @@ describe Chewy::Index::Actions do
|
|
241
306
|
before { DummiesIndex.purge! }
|
242
307
|
specify { expect(DummiesIndex).to be_exists }
|
243
308
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
244
|
-
specify { expect(DummiesIndex.indexes).to eq([]) }
|
309
|
+
specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
|
245
310
|
|
246
311
|
context do
|
247
312
|
before { DummiesIndex.purge! }
|
248
313
|
specify { expect(DummiesIndex).to be_exists }
|
249
314
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
250
|
-
specify { expect(DummiesIndex.indexes).to eq([]) }
|
315
|
+
specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
|
251
316
|
end
|
252
317
|
|
253
318
|
context do
|
254
319
|
before { DummiesIndex.purge!('2013') }
|
255
320
|
specify { expect(DummiesIndex).to be_exists }
|
256
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
321
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
257
322
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
258
323
|
end
|
259
324
|
end
|
@@ -261,20 +326,20 @@ describe Chewy::Index::Actions do
|
|
261
326
|
context do
|
262
327
|
before { DummiesIndex.purge!('2013') }
|
263
328
|
specify { expect(DummiesIndex).to be_exists }
|
264
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
329
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
265
330
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
266
331
|
|
267
332
|
context do
|
268
333
|
before { DummiesIndex.purge! }
|
269
334
|
specify { expect(DummiesIndex).to be_exists }
|
270
335
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
271
|
-
specify { expect(DummiesIndex.indexes).to eq([]) }
|
336
|
+
specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
|
272
337
|
end
|
273
338
|
|
274
339
|
context do
|
275
340
|
before { DummiesIndex.purge!('2014') }
|
276
341
|
specify { expect(DummiesIndex).to be_exists }
|
277
|
-
specify { expect(DummiesIndex.aliases).to eq([]) }
|
342
|
+
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
278
343
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2014']) }
|
279
344
|
end
|
280
345
|
end
|
@@ -284,19 +349,30 @@ describe Chewy::Index::Actions do
|
|
284
349
|
before do
|
285
350
|
stub_model(:city)
|
286
351
|
stub_index(:cities) do
|
287
|
-
|
352
|
+
index_scope City
|
288
353
|
end
|
289
354
|
end
|
290
|
-
let!(:dummy_cities) { 3
|
355
|
+
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
291
356
|
|
292
357
|
specify { expect(CitiesIndex.import).to eq(true) }
|
293
358
|
|
359
|
+
specify 'with an empty array' do
|
360
|
+
expect(CitiesIndex).not_to receive(:exists?)
|
361
|
+
expect(CitiesIndex).not_to receive(:create!)
|
362
|
+
expect(CitiesIndex.import([])).to eq(true)
|
363
|
+
end
|
364
|
+
|
365
|
+
specify 'with an empty relation' do
|
366
|
+
expect(CitiesIndex).not_to receive(:exists?)
|
367
|
+
expect(CitiesIndex).not_to receive(:create!)
|
368
|
+
expect(CitiesIndex.import(City.where('1 = 2'))).to eq(true)
|
369
|
+
end
|
370
|
+
|
294
371
|
context do
|
295
372
|
before do
|
296
373
|
stub_index(:cities) do
|
297
|
-
|
298
|
-
|
299
|
-
end
|
374
|
+
index_scope City
|
375
|
+
field :name, type: 'object'
|
300
376
|
end
|
301
377
|
end
|
302
378
|
|
@@ -308,19 +384,30 @@ describe Chewy::Index::Actions do
|
|
308
384
|
before do
|
309
385
|
stub_model(:city)
|
310
386
|
stub_index(:cities) do
|
311
|
-
|
387
|
+
index_scope City
|
312
388
|
end
|
313
389
|
end
|
314
|
-
let!(:dummy_cities) { 3
|
390
|
+
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
315
391
|
|
316
392
|
specify { expect(CitiesIndex.import!).to eq(true) }
|
317
393
|
|
394
|
+
specify 'with an empty array' do
|
395
|
+
expect(CitiesIndex).not_to receive(:exists?)
|
396
|
+
expect(CitiesIndex).not_to receive(:create!)
|
397
|
+
expect(CitiesIndex.import!([])).to eq(true)
|
398
|
+
end
|
399
|
+
|
400
|
+
specify 'with an empty relation' do
|
401
|
+
expect(CitiesIndex).not_to receive(:exists?)
|
402
|
+
expect(CitiesIndex).not_to receive(:create!)
|
403
|
+
expect(CitiesIndex.import!(City.where('1 = 2'))).to eq(true)
|
404
|
+
end
|
405
|
+
|
318
406
|
context do
|
319
407
|
before do
|
320
408
|
stub_index(:cities) do
|
321
|
-
|
322
|
-
|
323
|
-
end
|
409
|
+
index_scope City
|
410
|
+
field :name, type: 'object'
|
324
411
|
end
|
325
412
|
end
|
326
413
|
|
@@ -332,62 +419,493 @@ describe Chewy::Index::Actions do
|
|
332
419
|
before do
|
333
420
|
stub_model(:city)
|
334
421
|
stub_index(:cities) do
|
335
|
-
|
422
|
+
index_scope City
|
336
423
|
end
|
337
424
|
end
|
338
425
|
|
339
|
-
before { City.create!(id: 1, name: 'Moscow') }
|
340
|
-
|
341
|
-
specify { expect(CitiesIndex.reset!).to eq(true) }
|
342
|
-
specify { expect(CitiesIndex.reset!('2013')).to eq(true) }
|
343
|
-
|
344
426
|
context do
|
345
|
-
before {
|
427
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
346
428
|
|
347
|
-
specify { expect(CitiesIndex.
|
348
|
-
specify { expect(CitiesIndex.
|
349
|
-
specify { expect(CitiesIndex.indexes).to eq([]) }
|
429
|
+
specify { expect(CitiesIndex.reset!).to eq(true) }
|
430
|
+
specify { expect(CitiesIndex.reset!('2013')).to eq(true) }
|
350
431
|
|
351
432
|
context do
|
352
|
-
before { CitiesIndex.reset!
|
433
|
+
before { CitiesIndex.reset! }
|
353
434
|
|
354
435
|
specify { expect(CitiesIndex.all).to have(1).item }
|
355
436
|
specify { expect(CitiesIndex.aliases).to eq([]) }
|
356
|
-
specify { expect(CitiesIndex.indexes).to eq(['
|
437
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities']) }
|
438
|
+
|
439
|
+
context do
|
440
|
+
before { CitiesIndex.reset!('2013') }
|
441
|
+
|
442
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
443
|
+
specify { expect(CitiesIndex.aliases).to eq(['cities']) }
|
444
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
|
445
|
+
end
|
446
|
+
|
447
|
+
context do
|
448
|
+
before { CitiesIndex.reset! }
|
449
|
+
|
450
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
451
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
452
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities']) }
|
453
|
+
end
|
357
454
|
end
|
358
455
|
|
359
456
|
context do
|
360
|
-
before { CitiesIndex.reset! }
|
457
|
+
before { CitiesIndex.reset!('2013') }
|
361
458
|
|
362
459
|
specify { expect(CitiesIndex.all).to have(1).item }
|
363
|
-
specify { expect(CitiesIndex.aliases).to eq([]) }
|
364
|
-
specify { expect(CitiesIndex.indexes).to eq([]) }
|
460
|
+
specify { expect(CitiesIndex.aliases).to eq(['cities']) }
|
461
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
|
462
|
+
|
463
|
+
context do
|
464
|
+
before { CitiesIndex.reset!('2014') }
|
465
|
+
|
466
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
467
|
+
specify { expect(CitiesIndex.aliases).to eq(['cities']) }
|
468
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2014']) }
|
469
|
+
specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
|
470
|
+
end
|
471
|
+
|
472
|
+
context do
|
473
|
+
before { CitiesIndex.reset! }
|
474
|
+
|
475
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
476
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
477
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities']) }
|
478
|
+
specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
|
479
|
+
end
|
365
480
|
end
|
366
481
|
end
|
367
482
|
|
368
|
-
context do
|
483
|
+
context 'reset_disable_refresh_interval' do
|
484
|
+
let(:suffix) { Time.now.to_i }
|
485
|
+
let(:name) { CitiesIndex.index_name(suffix: suffix) }
|
486
|
+
let(:before_import_body) do
|
487
|
+
{
|
488
|
+
index: {refresh_interval: -1}
|
489
|
+
}
|
490
|
+
end
|
491
|
+
let(:after_import_body) do
|
492
|
+
{
|
493
|
+
index: {refresh_interval: '1s'}
|
494
|
+
}
|
495
|
+
end
|
496
|
+
|
369
497
|
before { CitiesIndex.reset!('2013') }
|
498
|
+
before { allow(Chewy).to receive(:reset_disable_refresh_interval).and_return(reset_disable_refresh_interval) }
|
499
|
+
|
500
|
+
context 'activated' do
|
501
|
+
let(:reset_disable_refresh_interval) { true }
|
502
|
+
specify do
|
503
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
504
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
505
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
506
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
507
|
+
end
|
370
508
|
|
371
|
-
|
372
|
-
|
373
|
-
|
509
|
+
context 'refresh_interval already defined' do
|
510
|
+
before do
|
511
|
+
stub_index(:cities) do
|
512
|
+
settings index: {refresh_interval: '2s'}
|
513
|
+
index_scope City
|
514
|
+
end
|
515
|
+
end
|
374
516
|
|
375
|
-
|
376
|
-
|
517
|
+
let(:after_import_body) do
|
518
|
+
{
|
519
|
+
index: {refresh_interval: '2s'}
|
520
|
+
}
|
521
|
+
end
|
377
522
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
523
|
+
specify do
|
524
|
+
expect(CitiesIndex.client.indices)
|
525
|
+
.to receive(:put_settings).with(index: name, body: before_import_body).once
|
526
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
527
|
+
expect(CitiesIndex)
|
528
|
+
.to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
529
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
530
|
+
end
|
531
|
+
|
532
|
+
specify 'uses empty index settings if not defined' do
|
533
|
+
allow(Chewy).to receive(:wait_for_status).and_return(nil)
|
534
|
+
allow(CitiesIndex).to receive(:settings_hash).and_return({})
|
535
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
context 'not activated' do
|
541
|
+
let(:reset_disable_refresh_interval) { false }
|
542
|
+
specify do
|
543
|
+
expect(CitiesIndex.client.indices).not_to receive(:put_settings)
|
544
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
545
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
546
|
+
end
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
context 'reset_no_replicas' do
|
551
|
+
let(:suffix) { Time.now.to_i }
|
552
|
+
let(:name) { CitiesIndex.index_name(suffix: suffix) }
|
553
|
+
let(:before_import_body) do
|
554
|
+
{
|
555
|
+
index: {number_of_replicas: 0}
|
556
|
+
}
|
557
|
+
end
|
558
|
+
let(:after_import_body) do
|
559
|
+
{
|
560
|
+
index: {number_of_replicas: 0}
|
561
|
+
}
|
562
|
+
end
|
563
|
+
|
564
|
+
before { allow(Chewy).to receive(:reset_no_replicas).and_return(reset_no_replicas) }
|
565
|
+
|
566
|
+
context 'activated' do
|
567
|
+
let(:reset_no_replicas) { true }
|
568
|
+
specify do
|
569
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
570
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
571
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
572
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
context 'not activated' do
|
577
|
+
let(:reset_no_replicas) { false }
|
578
|
+
specify do
|
579
|
+
expect(CitiesIndex.client.indices).not_to receive(:put_settings)
|
580
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
581
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
586
|
+
xcontext 'applying journal' do
|
587
|
+
before do
|
588
|
+
stub_index(:cities) do
|
589
|
+
index_scope City
|
590
|
+
field :name, value: (lambda do
|
591
|
+
sleep(rating)
|
592
|
+
name
|
593
|
+
end)
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
let!(:cities) { Array.new(3) { |i| City.create!(id: i + 1, name: "Name#{i + 1}", rating: 1) } }
|
598
|
+
|
599
|
+
let(:parallel_update) do
|
600
|
+
Thread.new do
|
601
|
+
p 'start parallel'
|
602
|
+
sleep(1.5)
|
603
|
+
cities.first.update(name: 'NewName1', rating: 0)
|
604
|
+
cities.last.update(name: 'NewName3', rating: 0)
|
605
|
+
CitiesIndex::City.import!([cities.first, cities.last], journal: true)
|
606
|
+
p 'end parallel'
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
specify 'with journal application' do
|
611
|
+
cities
|
612
|
+
p 'cities created1'
|
613
|
+
::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
|
614
|
+
[
|
615
|
+
parallel_update,
|
616
|
+
Thread.new do
|
617
|
+
p 'start reset1'
|
618
|
+
CitiesIndex.reset!('suffix')
|
619
|
+
p 'end reset1'
|
620
|
+
end
|
621
|
+
].map(&:join)
|
622
|
+
::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
|
623
|
+
p 'expect1'
|
624
|
+
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
|
625
|
+
p 'end expect1'
|
382
626
|
end
|
383
627
|
|
628
|
+
specify 'without journal application' do
|
629
|
+
cities
|
630
|
+
p 'cities created2'
|
631
|
+
::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
|
632
|
+
[
|
633
|
+
parallel_update,
|
634
|
+
Thread.new do
|
635
|
+
p 'start reset2'
|
636
|
+
CitiesIndex.reset!('suffix', apply_journal: false)
|
637
|
+
p 'end reset2'
|
638
|
+
end
|
639
|
+
].map(&:join)
|
640
|
+
::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
|
641
|
+
p 'expect2'
|
642
|
+
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
|
643
|
+
p 'end expect2'
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
context 'journaling' do
|
648
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
649
|
+
|
650
|
+
specify do
|
651
|
+
CitiesIndex.reset!
|
652
|
+
expect(Chewy::Stash::Journal.count).to eq(0)
|
653
|
+
end
|
654
|
+
|
655
|
+
specify do
|
656
|
+
CitiesIndex.reset! journal: true
|
657
|
+
expect(Chewy::Stash::Journal.count).to be > 0
|
658
|
+
end
|
659
|
+
end
|
660
|
+
|
661
|
+
context 'other options' do
|
662
|
+
specify do
|
663
|
+
expect(CitiesIndex).to receive(:import).with(parallel: true, journal: false).once.and_return(true)
|
664
|
+
expect(CitiesIndex.reset!(parallel: true)).to eq(true)
|
665
|
+
end
|
666
|
+
|
667
|
+
specify do
|
668
|
+
expect(CitiesIndex)
|
669
|
+
.to receive(:import)
|
670
|
+
.with(suffix: 'suffix', parallel: true, journal: false, refresh: true)
|
671
|
+
.once.and_return(true)
|
672
|
+
expect(CitiesIndex.reset!('suffix', parallel: true)).to eq(true)
|
673
|
+
end
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
677
|
+
describe '.reset' do
|
678
|
+
before do
|
679
|
+
stub_model(:city)
|
680
|
+
stub_index(:cities) do
|
681
|
+
index_scope City
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
context do
|
686
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
687
|
+
|
688
|
+
specify { expect(CitiesIndex.reset).to eq(true) }
|
689
|
+
specify { expect(CitiesIndex.reset('2013')).to eq(true) }
|
690
|
+
|
384
691
|
context do
|
385
|
-
before { CitiesIndex.reset
|
692
|
+
before { CitiesIndex.reset }
|
386
693
|
|
387
694
|
specify { expect(CitiesIndex.all).to have(1).item }
|
388
695
|
specify { expect(CitiesIndex.aliases).to eq([]) }
|
389
|
-
specify { expect(CitiesIndex.indexes).to eq([]) }
|
390
|
-
|
696
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities']) }
|
697
|
+
end
|
698
|
+
end
|
699
|
+
end
|
700
|
+
|
701
|
+
describe '.sync' do
|
702
|
+
before do
|
703
|
+
stub_model(:city)
|
704
|
+
stub_index(:cities) do
|
705
|
+
index_scope City
|
706
|
+
field :name
|
707
|
+
field :updated_at, type: 'date'
|
708
|
+
end
|
709
|
+
end
|
710
|
+
|
711
|
+
let!(:cities) { Array.new(3) { |i| City.create!(name: "Name#{i + 1}") } }
|
712
|
+
|
713
|
+
before do
|
714
|
+
CitiesIndex.import
|
715
|
+
cities.first.destroy
|
716
|
+
cities.last.update(name: 'Name5')
|
717
|
+
end
|
718
|
+
|
719
|
+
let!(:additional_city) { City.create!(name: 'Name4') }
|
720
|
+
|
721
|
+
specify do
|
722
|
+
expect(CitiesIndex.sync).to match(
|
723
|
+
count: 3,
|
724
|
+
missing: contain_exactly(cities.first.id.to_s, additional_city.id.to_s),
|
725
|
+
outdated: [cities.last.id.to_s]
|
726
|
+
)
|
727
|
+
end
|
728
|
+
specify do
|
729
|
+
expect { CitiesIndex.sync }.to update_index(CitiesIndex)
|
730
|
+
.and_reindex(additional_city, cities.last)
|
731
|
+
.and_delete(cities.first).only
|
732
|
+
end
|
733
|
+
end
|
734
|
+
|
735
|
+
describe '.journal' do
|
736
|
+
specify { expect(DummiesIndex.journal).to be_a(Chewy::Journal) }
|
737
|
+
end
|
738
|
+
|
739
|
+
describe '.clear_cache' do
|
740
|
+
before do
|
741
|
+
stub_model(:city)
|
742
|
+
stub_index(:cities) do
|
743
|
+
index_scope City
|
744
|
+
end
|
745
|
+
end
|
746
|
+
|
747
|
+
let(:index_name) { 'test_index' }
|
748
|
+
let(:index_name_with_prefix) { 'cities_test_index' }
|
749
|
+
let(:unexisted_index_name) { 'wrong_index' }
|
750
|
+
|
751
|
+
context 'with existing index' do
|
752
|
+
before do
|
753
|
+
CitiesIndex.create(index_name)
|
754
|
+
end
|
755
|
+
|
756
|
+
specify do
|
757
|
+
expect(CitiesIndex)
|
758
|
+
.to receive(:clear_cache)
|
759
|
+
.and_call_original
|
760
|
+
expect { CitiesIndex.clear_cache({index: index_name_with_prefix}) }
|
761
|
+
.not_to raise_error
|
762
|
+
end
|
763
|
+
end
|
764
|
+
|
765
|
+
context 'with unexisting index' do
|
766
|
+
specify do
|
767
|
+
expect(CitiesIndex)
|
768
|
+
.to receive(:clear_cache)
|
769
|
+
.and_call_original
|
770
|
+
expect { CitiesIndex.clear_cache({index: unexisted_index_name}) }
|
771
|
+
.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
|
772
|
+
end
|
773
|
+
end
|
774
|
+
|
775
|
+
context 'without arguments' do
|
776
|
+
before do
|
777
|
+
CitiesIndex.create
|
778
|
+
end
|
779
|
+
|
780
|
+
specify do
|
781
|
+
expect(CitiesIndex)
|
782
|
+
.to receive(:clear_cache)
|
783
|
+
.and_call_original
|
784
|
+
expect { CitiesIndex.clear_cache }
|
785
|
+
.not_to raise_error
|
786
|
+
end
|
787
|
+
end
|
788
|
+
end
|
789
|
+
|
790
|
+
describe '.reindex' do
|
791
|
+
before do
|
792
|
+
stub_model(:city)
|
793
|
+
stub_index(:cities) do
|
794
|
+
index_scope City
|
795
|
+
end
|
796
|
+
CitiesIndex.create(source_index)
|
797
|
+
DummiesIndex.create(dest_index)
|
798
|
+
end
|
799
|
+
|
800
|
+
let(:source_index) { 'source_index' }
|
801
|
+
let(:source_index_with_prefix) { 'cities_source_index' }
|
802
|
+
let(:dest_index) { 'dest_index' }
|
803
|
+
let(:dest_index_with_prefix) { 'dummies_dest_index' }
|
804
|
+
let(:unexisting_index) { 'wrong_index' }
|
805
|
+
|
806
|
+
context 'with existing indexes' do
|
807
|
+
specify do
|
808
|
+
expect(CitiesIndex)
|
809
|
+
.to receive(:reindex)
|
810
|
+
.and_call_original
|
811
|
+
expect { CitiesIndex.reindex(source: source_index_with_prefix, dest: dest_index_with_prefix) }
|
812
|
+
.not_to raise_error
|
813
|
+
end
|
814
|
+
end
|
815
|
+
|
816
|
+
context 'with unexisting indexes' do
|
817
|
+
context 'source index' do
|
818
|
+
specify do
|
819
|
+
expect(CitiesIndex)
|
820
|
+
.to receive(:reindex)
|
821
|
+
.and_call_original
|
822
|
+
expect { CitiesIndex.reindex(source: unexisting_index, dest: dest_index_with_prefix) }
|
823
|
+
.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
context 'dest index' do
|
828
|
+
specify do
|
829
|
+
expect(CitiesIndex)
|
830
|
+
.to receive(:reindex)
|
831
|
+
.and_call_original
|
832
|
+
expect { CitiesIndex.reindex(source: source_index_with_prefix, dest: unexisting_index) }
|
833
|
+
.not_to raise_error
|
834
|
+
end
|
835
|
+
end
|
836
|
+
end
|
837
|
+
|
838
|
+
context 'with missing indexes' do
|
839
|
+
context 'without dest index' do
|
840
|
+
specify do
|
841
|
+
expect(DummiesIndex)
|
842
|
+
.to receive(:reindex)
|
843
|
+
.and_call_original
|
844
|
+
expect { DummiesIndex.reindex(source: source_index_with_prefix) }
|
845
|
+
.not_to raise_error
|
846
|
+
end
|
847
|
+
end
|
848
|
+
|
849
|
+
context 'without source index' do
|
850
|
+
specify do
|
851
|
+
expect(CitiesIndex)
|
852
|
+
.to receive(:reindex)
|
853
|
+
.and_call_original
|
854
|
+
expect { CitiesIndex.reindex(dest: dest_index_with_prefix) }
|
855
|
+
.not_to raise_error
|
856
|
+
end
|
857
|
+
end
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
describe 'update_mapping' do
|
862
|
+
before do
|
863
|
+
stub_model(:city)
|
864
|
+
stub_index(:cities) do
|
865
|
+
index_scope City
|
866
|
+
end
|
867
|
+
CitiesIndex.create
|
868
|
+
end
|
869
|
+
|
870
|
+
let(:index_name) { CitiesIndex.index_name }
|
871
|
+
let(:body_hash) { {properties: {new_field: {type: :text}}} }
|
872
|
+
let(:unexisting_index) { 'wrong_index' }
|
873
|
+
let(:empty_body_hash) { {} }
|
874
|
+
|
875
|
+
context 'with existing index' do
|
876
|
+
specify do
|
877
|
+
expect { CitiesIndex.update_mapping(index_name, body_hash) }
|
878
|
+
.not_to raise_error
|
879
|
+
end
|
880
|
+
end
|
881
|
+
|
882
|
+
context 'with unexisting arguments' do
|
883
|
+
context 'index name' do
|
884
|
+
specify do
|
885
|
+
expect { CitiesIndex.update_mapping(unexisting_index, body_hash) }
|
886
|
+
.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
|
887
|
+
end
|
888
|
+
end
|
889
|
+
|
890
|
+
context 'body hash' do
|
891
|
+
specify do
|
892
|
+
expect { CitiesIndex.update_mapping(index_name, empty_body_hash) }
|
893
|
+
.not_to raise_error
|
894
|
+
end
|
895
|
+
end
|
896
|
+
end
|
897
|
+
|
898
|
+
context 'with only argument' do
|
899
|
+
specify do
|
900
|
+
expect { CitiesIndex.update_mapping(index_name) }
|
901
|
+
.not_to raise_error
|
902
|
+
end
|
903
|
+
end
|
904
|
+
|
905
|
+
context 'without arguments' do
|
906
|
+
specify do
|
907
|
+
expect { CitiesIndex.update_mapping }
|
908
|
+
.not_to raise_error
|
391
909
|
end
|
392
910
|
end
|
393
911
|
end
|