chewy 0.9.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +214 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +41 -19
- data/.rubocop_todo.yml +2 -2
- data/.yardopts +5 -0
- data/Appraisals +58 -28
- data/CHANGELOG.md +153 -12
- data/Gemfile +20 -12
- data/LEGACY_DSL.md +497 -0
- data/LICENSE.txt +1 -1
- data/README.md +338 -528
- data/chewy.gemspec +11 -12
- data/gemfiles/rails.5.2.activerecord.gemfile +17 -0
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +17 -0
- data/gemfiles/rails.6.0.activerecord.gemfile +17 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
- data/gemfiles/ruby3.gemfile +10 -0
- data/gemfiles/sequel.4.45.gemfile +11 -0
- data/lib/chewy.rb +79 -44
- data/lib/chewy/backports/duplicable.rb +1 -1
- data/lib/chewy/config.rb +43 -17
- data/lib/chewy/errors.rb +2 -2
- data/lib/chewy/fields/base.rb +56 -31
- data/lib/chewy/fields/root.rb +44 -11
- data/lib/chewy/index.rb +237 -149
- data/lib/chewy/index/actions.rb +100 -35
- data/lib/chewy/index/aliases.rb +2 -1
- data/lib/chewy/index/settings.rb +11 -5
- data/lib/chewy/index/specification.rb +60 -0
- data/lib/chewy/journal.rb +40 -92
- data/lib/chewy/minitest/helpers.rb +6 -6
- data/lib/chewy/minitest/search_index_receiver.rb +17 -17
- data/lib/chewy/query.rb +182 -122
- data/lib/chewy/query/compose.rb +13 -13
- data/lib/chewy/query/criteria.rb +13 -13
- data/lib/chewy/query/filters.rb +21 -4
- data/lib/chewy/query/loading.rb +1 -2
- data/lib/chewy/query/nodes/and.rb +2 -2
- data/lib/chewy/query/nodes/bool.rb +1 -1
- data/lib/chewy/query/nodes/equal.rb +2 -2
- data/lib/chewy/query/nodes/exists.rb +1 -1
- data/lib/chewy/query/nodes/field.rb +1 -1
- data/lib/chewy/query/nodes/has_relation.rb +2 -2
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +1 -1
- data/lib/chewy/query/nodes/not.rb +2 -2
- data/lib/chewy/query/nodes/or.rb +2 -2
- data/lib/chewy/query/nodes/prefix.rb +1 -1
- data/lib/chewy/query/nodes/query.rb +2 -2
- data/lib/chewy/query/nodes/range.rb +4 -4
- data/lib/chewy/query/nodes/regexp.rb +4 -4
- data/lib/chewy/query/nodes/script.rb +3 -3
- data/lib/chewy/query/pagination.rb +10 -1
- data/lib/chewy/railtie.rb +4 -3
- data/lib/chewy/rake_helper.rb +265 -48
- data/lib/chewy/rspec/update_index.rb +33 -27
- data/lib/chewy/search.rb +79 -26
- data/lib/chewy/search/loader.rb +83 -0
- data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
- data/lib/chewy/search/pagination/will_paginate.rb +43 -0
- data/lib/chewy/search/parameters.rb +168 -0
- data/lib/chewy/search/parameters/aggs.rb +16 -0
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/concerns/bool_storage.rb +24 -0
- data/lib/chewy/search/parameters/concerns/hash_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/integer_storage.rb +14 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +238 -0
- data/lib/chewy/search/parameters/concerns/string_array_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/string_storage.rb +14 -0
- data/lib/chewy/search/parameters/docvalue_fields.rb +12 -0
- data/lib/chewy/search/parameters/explain.rb +16 -0
- data/lib/chewy/search/parameters/filter.rb +47 -0
- data/lib/chewy/search/parameters/highlight.rb +16 -0
- data/lib/chewy/search/parameters/indices.rb +123 -0
- data/lib/chewy/search/parameters/indices_boost.rb +52 -0
- data/lib/chewy/search/parameters/limit.rb +17 -0
- data/lib/chewy/search/parameters/load.rb +32 -0
- data/lib/chewy/search/parameters/min_score.rb +16 -0
- data/lib/chewy/search/parameters/none.rb +27 -0
- data/lib/chewy/search/parameters/offset.rb +17 -0
- data/lib/chewy/search/parameters/order.rb +64 -0
- data/lib/chewy/search/parameters/post_filter.rb +19 -0
- data/lib/chewy/search/parameters/preference.rb +16 -0
- data/lib/chewy/search/parameters/profile.rb +16 -0
- data/lib/chewy/search/parameters/query.rb +19 -0
- data/lib/chewy/search/parameters/request_cache.rb +27 -0
- data/lib/chewy/search/parameters/rescore.rb +29 -0
- data/lib/chewy/search/parameters/script_fields.rb +16 -0
- data/lib/chewy/search/parameters/search_after.rb +20 -0
- data/lib/chewy/search/parameters/search_type.rb +16 -0
- data/lib/chewy/search/parameters/source.rb +73 -0
- data/lib/chewy/search/parameters/storage.rb +95 -0
- data/lib/chewy/search/parameters/stored_fields.rb +63 -0
- data/lib/chewy/search/parameters/suggest.rb +16 -0
- data/lib/chewy/search/parameters/terminate_after.rb +16 -0
- data/lib/chewy/search/parameters/timeout.rb +16 -0
- data/lib/chewy/search/parameters/track_scores.rb +16 -0
- data/lib/chewy/search/parameters/types.rb +20 -0
- data/lib/chewy/search/parameters/version.rb +16 -0
- data/lib/chewy/search/query_proxy.rb +257 -0
- data/lib/chewy/search/request.rb +1046 -0
- data/lib/chewy/search/response.rb +119 -0
- data/lib/chewy/search/scoping.rb +50 -0
- data/lib/chewy/search/scrolling.rb +134 -0
- data/lib/chewy/stash.rb +79 -0
- data/lib/chewy/strategy.rb +10 -3
- data/lib/chewy/strategy/active_job.rb +2 -1
- data/lib/chewy/strategy/atomic.rb +2 -4
- data/lib/chewy/strategy/bypass.rb +1 -1
- data/lib/chewy/strategy/resque.rb +1 -0
- data/lib/chewy/strategy/shoryuken.rb +40 -0
- data/lib/chewy/strategy/sidekiq.rb +13 -3
- data/lib/chewy/type.rb +29 -7
- data/lib/chewy/type/actions.rb +26 -2
- data/lib/chewy/type/adapter/active_record.rb +44 -29
- data/lib/chewy/type/adapter/base.rb +27 -7
- data/lib/chewy/type/adapter/mongoid.rb +19 -10
- data/lib/chewy/type/adapter/object.rb +187 -26
- data/lib/chewy/type/adapter/orm.rb +59 -32
- data/lib/chewy/type/adapter/sequel.rb +33 -19
- data/lib/chewy/type/crutch.rb +1 -1
- data/lib/chewy/type/import.rb +146 -191
- data/lib/chewy/type/import/bulk_builder.rb +122 -0
- data/lib/chewy/type/import/bulk_request.rb +78 -0
- data/lib/chewy/type/import/journal_builder.rb +45 -0
- data/lib/chewy/type/import/routine.rb +138 -0
- data/lib/chewy/type/mapping.rb +51 -35
- data/lib/chewy/type/observe.rb +17 -13
- data/lib/chewy/type/syncer.rb +222 -0
- data/lib/chewy/type/witchcraft.rb +32 -16
- data/lib/chewy/type/wrapper.rb +30 -4
- data/lib/chewy/version.rb +1 -1
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/lib/tasks/chewy.rake +84 -26
- data/spec/chewy/config_spec.rb +98 -1
- data/spec/chewy/fields/base_spec.rb +170 -135
- data/spec/chewy/fields/root_spec.rb +124 -20
- data/spec/chewy/fields/time_fields_spec.rb +2 -3
- data/spec/chewy/index/actions_spec.rb +214 -52
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +67 -38
- data/spec/chewy/index/specification_spec.rb +169 -0
- data/spec/chewy/index_spec.rb +108 -64
- data/spec/chewy/journal_spec.rb +150 -55
- data/spec/chewy/minitest/helpers_spec.rb +4 -4
- data/spec/chewy/minitest/search_index_receiver_spec.rb +1 -1
- data/spec/chewy/query/criteria_spec.rb +179 -179
- data/spec/chewy/query/filters_spec.rb +16 -16
- data/spec/chewy/query/loading_spec.rb +22 -20
- data/spec/chewy/query/nodes/and_spec.rb +2 -2
- data/spec/chewy/query/nodes/bool_spec.rb +4 -4
- data/spec/chewy/query/nodes/equal_spec.rb +19 -19
- data/spec/chewy/query/nodes/exists_spec.rb +6 -6
- data/spec/chewy/query/nodes/has_child_spec.rb +19 -19
- data/spec/chewy/query/nodes/has_parent_spec.rb +19 -19
- data/spec/chewy/query/nodes/missing_spec.rb +5 -5
- data/spec/chewy/query/nodes/not_spec.rb +4 -2
- data/spec/chewy/query/nodes/or_spec.rb +2 -2
- data/spec/chewy/query/nodes/prefix_spec.rb +5 -5
- data/spec/chewy/query/nodes/query_spec.rb +2 -2
- data/spec/chewy/query/nodes/range_spec.rb +18 -18
- data/spec/chewy/query/nodes/raw_spec.rb +1 -1
- data/spec/chewy/query/nodes/regexp_spec.rb +14 -14
- data/spec/chewy/query/nodes/script_spec.rb +4 -4
- data/spec/chewy/query/pagination/kaminari_spec.rb +3 -55
- data/spec/chewy/query/pagination/will_paginate_spec.rb +5 -0
- data/spec/chewy/query/pagination_spec.rb +25 -21
- data/spec/chewy/query_spec.rb +503 -561
- data/spec/chewy/rake_helper_spec.rb +381 -0
- data/spec/chewy/repository_spec.rb +4 -4
- data/spec/chewy/rspec/update_index_spec.rb +89 -56
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +117 -0
- data/spec/chewy/search/pagination/kaminari_examples.rb +71 -0
- data/spec/chewy/search/pagination/kaminari_spec.rb +21 -0
- data/spec/chewy/search/pagination/will_paginate_examples.rb +63 -0
- data/spec/chewy/search/pagination/will_paginate_spec.rb +23 -0
- data/spec/chewy/search/parameters/aggs_spec.rb +5 -0
- data/spec/chewy/search/parameters/bool_storage_examples.rb +53 -0
- data/spec/chewy/search/parameters/docvalue_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/explain_spec.rb +5 -0
- data/spec/chewy/search/parameters/filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/hash_storage_examples.rb +59 -0
- data/spec/chewy/search/parameters/highlight_spec.rb +5 -0
- data/spec/chewy/search/parameters/indices_spec.rb +191 -0
- data/spec/chewy/search/parameters/integer_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/limit_spec.rb +5 -0
- data/spec/chewy/search/parameters/load_spec.rb +60 -0
- data/spec/chewy/search/parameters/min_score_spec.rb +32 -0
- data/spec/chewy/search/parameters/none_spec.rb +5 -0
- data/spec/chewy/search/parameters/offset_spec.rb +5 -0
- data/spec/chewy/search/parameters/order_spec.rb +65 -0
- data/spec/chewy/search/parameters/post_filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/preference_spec.rb +5 -0
- data/spec/chewy/search/parameters/profile_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_storage_examples.rb +388 -0
- data/spec/chewy/search/parameters/request_cache_spec.rb +67 -0
- data/spec/chewy/search/parameters/rescore_spec.rb +62 -0
- data/spec/chewy/search/parameters/script_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/search_after_spec.rb +32 -0
- data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
- data/spec/chewy/search/parameters/source_spec.rb +156 -0
- data/spec/chewy/search/parameters/storage_spec.rb +60 -0
- data/spec/chewy/search/parameters/stored_fields_spec.rb +126 -0
- data/spec/chewy/search/parameters/string_array_storage_examples.rb +63 -0
- data/spec/chewy/search/parameters/string_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/suggest_spec.rb +5 -0
- data/spec/chewy/search/parameters/terminate_after_spec.rb +5 -0
- data/spec/chewy/search/parameters/timeout_spec.rb +5 -0
- data/spec/chewy/search/parameters/track_scores_spec.rb +5 -0
- data/spec/chewy/search/parameters/types_spec.rb +5 -0
- data/spec/chewy/search/parameters/version_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +147 -0
- data/spec/chewy/search/query_proxy_spec.rb +68 -0
- data/spec/chewy/search/request_spec.rb +685 -0
- data/spec/chewy/search/response_spec.rb +198 -0
- data/spec/chewy/search/scrolling_spec.rb +169 -0
- data/spec/chewy/search_spec.rb +33 -16
- data/spec/chewy/stash_spec.rb +95 -0
- data/spec/chewy/strategy/active_job_spec.rb +21 -2
- data/spec/chewy/strategy/resque_spec.rb +6 -0
- data/spec/chewy/strategy/shoryuken_spec.rb +70 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +13 -1
- data/spec/chewy/strategy_spec.rb +6 -6
- data/spec/chewy/type/actions_spec.rb +29 -10
- data/spec/chewy/type/adapter/active_record_spec.rb +203 -91
- data/spec/chewy/type/adapter/mongoid_spec.rb +112 -54
- data/spec/chewy/type/adapter/object_spec.rb +101 -28
- data/spec/chewy/type/adapter/sequel_spec.rb +149 -82
- data/spec/chewy/type/import/bulk_builder_spec.rb +279 -0
- data/spec/chewy/type/import/bulk_request_spec.rb +102 -0
- data/spec/chewy/type/import/journal_builder_spec.rb +95 -0
- data/spec/chewy/type/import/routine_spec.rb +110 -0
- data/spec/chewy/type/import_spec.rb +356 -271
- data/spec/chewy/type/mapping_spec.rb +96 -29
- data/spec/chewy/type/observe_spec.rb +9 -5
- data/spec/chewy/type/syncer_spec.rb +123 -0
- data/spec/chewy/type/witchcraft_spec.rb +61 -29
- data/spec/chewy/type/wrapper_spec.rb +63 -23
- data/spec/chewy/type_spec.rb +28 -7
- data/spec/chewy_spec.rb +75 -7
- data/spec/spec_helper.rb +17 -3
- data/spec/support/active_record.rb +5 -1
- data/spec/support/class_helpers.rb +0 -14
- data/spec/support/mongoid.rb +15 -3
- data/spec/support/sequel.rb +6 -1
- metadata +219 -58
- data/.travis.yml +0 -36
- data/gemfiles/rails.3.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -15
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -17
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.4.0.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.4.0.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.5.1.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.will_paginate.gemfile +0 -15
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -17
- data/gemfiles/rails.5.0.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.activerecord.will_paginate.gemfile +0 -16
- data/gemfiles/sequel.4.38.gemfile +0 -14
- data/lib/chewy/journal/apply.rb +0 -31
- data/lib/chewy/journal/clean.rb +0 -24
- data/lib/chewy/journal/entry.rb +0 -83
- data/lib/chewy/journal/query.rb +0 -87
- data/lib/chewy/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/scoping.rb +0 -20
- data/spec/chewy/journal/apply_spec.rb +0 -120
- data/spec/chewy/journal/entry_spec.rb +0 -237
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -59
data/lib/chewy/version.rb
CHANGED
@@ -36,40 +36,25 @@ module Sequel
|
|
36
36
|
callback_options = ChewyObserve.extract_callback_options!(args)
|
37
37
|
update_proc = ChewyObserve.update_proc(type_name, *args, &block)
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
set_callback(:destroy_commit, callback_options, &update_proc)
|
42
|
-
else
|
43
|
-
set_callback(:save, callback_options, &update_proc)
|
44
|
-
set_callback(:destroy, callback_options, &update_proc)
|
45
|
-
end
|
39
|
+
set_callback(:save, callback_options, &update_proc)
|
40
|
+
set_callback(:destroy, callback_options, &update_proc)
|
46
41
|
end
|
47
42
|
end
|
48
43
|
|
49
44
|
# Instance level methods for Sequel::Model
|
50
45
|
#
|
51
46
|
module InstanceMethods
|
52
|
-
def after_commit
|
53
|
-
run_callbacks(:commit) do
|
54
|
-
super
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def after_destroy_commit
|
59
|
-
run_callbacks(:destroy_commit) do
|
60
|
-
super
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
47
|
def after_save
|
65
48
|
run_callbacks(:save) do
|
66
49
|
super
|
50
|
+
db.after_commit {} if Chewy.use_after_commit_callbacks
|
67
51
|
end
|
68
52
|
end
|
69
53
|
|
70
54
|
def after_destroy
|
71
55
|
run_callbacks(:destroy) do
|
72
56
|
super
|
57
|
+
db.after_commit {} if Chewy.use_after_commit_callbacks
|
73
58
|
end
|
74
59
|
end
|
75
60
|
end
|
data/lib/tasks/chewy.rake
CHANGED
@@ -1,34 +1,96 @@
|
|
1
1
|
require 'chewy/rake_helper'
|
2
2
|
|
3
|
+
def parse_classes(args)
|
4
|
+
if args.present? && args.first.tr!('-', '')
|
5
|
+
{except: args}
|
6
|
+
else
|
7
|
+
{only: args}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_parallel_args(args)
|
12
|
+
options = {}
|
13
|
+
options[:parallel] = args.first =~ /\A\d+\z/ ? Integer(args.shift) : true
|
14
|
+
options.merge!(parse_classes(args))
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse_journal_args(args)
|
18
|
+
options = {}
|
19
|
+
options[:time] = Time.parse(args.shift) if args.first =~ /\A\d+/
|
20
|
+
options.merge!(parse_classes(args))
|
21
|
+
end
|
22
|
+
|
3
23
|
namespace :chewy do
|
4
|
-
desc '
|
24
|
+
desc 'Destroys, recreates and imports data for the specified indexes or all of them'
|
5
25
|
task reset: :environment do |_task, args|
|
6
|
-
Chewy::RakeHelper.
|
7
|
-
|
26
|
+
Chewy::RakeHelper.reset(parse_classes(args.extras))
|
27
|
+
end
|
8
28
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Chewy::RakeHelper.reset_index(indexes)
|
13
|
-
end
|
14
|
-
end
|
29
|
+
desc 'Resets data for the specified indexes or all of them only if the index specification is changed'
|
30
|
+
task upgrade: :environment do |_task, args|
|
31
|
+
Chewy::RakeHelper.upgrade(parse_classes(args.extras))
|
15
32
|
end
|
16
33
|
|
17
|
-
desc 'Updates data specified
|
34
|
+
desc 'Updates data for the specified indexes/types or all of them'
|
18
35
|
task update: :environment do |_task, args|
|
19
|
-
Chewy::RakeHelper.
|
20
|
-
|
36
|
+
Chewy::RakeHelper.update(parse_classes(args.extras))
|
37
|
+
end
|
21
38
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
39
|
+
desc 'Synchronizes data for the specified indexes/types or all of them'
|
40
|
+
task sync: :environment do |_task, args|
|
41
|
+
Chewy::RakeHelper.sync(parse_classes(args.extras))
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Resets all the indexes with the specification changed and synchronizes the rest of them'
|
45
|
+
task deploy: :environment do
|
46
|
+
processed = Chewy::RakeHelper.upgrade
|
47
|
+
Chewy::RakeHelper.sync(except: processed)
|
48
|
+
end
|
49
|
+
|
50
|
+
namespace :parallel do
|
51
|
+
desc 'Parallel version of `rake chewy:reset`'
|
52
|
+
task reset: :environment do |_task, args|
|
53
|
+
Chewy::RakeHelper.reset(parse_parallel_args(args.extras))
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'Parallel version of `rake chewy:upgrade`'
|
57
|
+
task upgrade: :environment do |_task, args|
|
58
|
+
Chewy::RakeHelper.upgrade(parse_parallel_args(args.extras))
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Parallel version of `rake chewy:update`'
|
62
|
+
task update: :environment do |_task, args|
|
63
|
+
Chewy::RakeHelper.update(parse_parallel_args(args.extras))
|
64
|
+
end
|
65
|
+
|
66
|
+
desc 'Parallel version of `rake chewy:sync`'
|
67
|
+
task sync: :environment do |_task, args|
|
68
|
+
Chewy::RakeHelper.sync(parse_parallel_args(args.extras))
|
69
|
+
end
|
70
|
+
|
71
|
+
desc 'Parallel version of `rake chewy:deploy`'
|
72
|
+
task deploy: :environment do |_task, args|
|
73
|
+
parallel = args.extras.first =~ /\A\d+\z/ ? Integer(args.extras.first) : true
|
74
|
+
processed = Chewy::RakeHelper.upgrade(parallel: parallel)
|
75
|
+
Chewy::RakeHelper.sync(except: processed, parallel: parallel)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
namespace :journal do
|
80
|
+
desc 'Applies changes that were done after the specified time for the specified indexes/types or all of them'
|
81
|
+
task apply: :environment do |_task, args|
|
82
|
+
Chewy::RakeHelper.journal_apply(parse_journal_args(args.extras))
|
83
|
+
end
|
84
|
+
|
85
|
+
desc 'Removes journal records created before the specified timestamp for the specified indexes/types or all of them'
|
86
|
+
task clean: :environment do |_task, args|
|
87
|
+
Chewy::RakeHelper.journal_clean(parse_journal_args(args.extras))
|
27
88
|
end
|
28
89
|
end
|
29
90
|
|
30
|
-
desc 'Applies changes that were done from specified moment (as a timestamp)'
|
31
91
|
task apply_changes_from: :environment do |_task, args|
|
92
|
+
ActiveSupport::Deprecation.warn '`rake chewy:apply_changes_from` is deprecated and will be removed soon, use `rake chewy:journal:apply` instead'
|
93
|
+
|
32
94
|
Chewy::RakeHelper.subscribed_task_stats do
|
33
95
|
params = args.extras
|
34
96
|
|
@@ -37,18 +99,14 @@ namespace :chewy do
|
|
37
99
|
else
|
38
100
|
timestamp, retries = params
|
39
101
|
time = Time.at(timestamp.to_i)
|
40
|
-
Chewy::Journal
|
102
|
+
Chewy::Journal.new.apply(time, retries: (retries.to_i if retries))
|
41
103
|
end
|
42
104
|
end
|
43
105
|
end
|
44
106
|
|
45
|
-
desc 'Cleans journal index. It accepts timestamp until which journal will be cleaned'
|
46
107
|
task clean_journal: :environment do |_task, args|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
else
|
51
|
-
Chewy::Journal.delete!
|
52
|
-
end
|
108
|
+
ActiveSupport::Deprecation.warn '`rake chewy:clean_journal` is deprecated and will be removed soon, use `rake chewy:journal:clean` instead'
|
109
|
+
|
110
|
+
Chewy::Journal.new.clean(args.extras.first)
|
53
111
|
end
|
54
112
|
end
|
data/spec/chewy/config_spec.rb
CHANGED
@@ -13,6 +13,10 @@ describe Chewy::Config do
|
|
13
13
|
its(:request_strategy) { should == :atomic }
|
14
14
|
its(:use_after_commit_callbacks) { should == true }
|
15
15
|
its(:indices_path) { should == 'app/chewy' }
|
16
|
+
its(:reset_disable_refresh_interval) { should == false }
|
17
|
+
its(:reset_no_replicas) { should == false }
|
18
|
+
its(:disable_refresh_async) { should == false }
|
19
|
+
its(:search_class) { should be < Chewy::Search::Request }
|
16
20
|
|
17
21
|
describe '#transport_logger=' do
|
18
22
|
let(:logger) { Logger.new('/dev/null') }
|
@@ -50,11 +54,104 @@ describe Chewy::Config do
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
57
|
+
describe '#search_class=' do
|
58
|
+
specify do
|
59
|
+
expect { subject.search_class = Chewy::Query }
|
60
|
+
.to change { subject.search_class }
|
61
|
+
.from(be < Chewy::Search::Request)
|
62
|
+
.to(be < Chewy::Query)
|
63
|
+
end
|
64
|
+
|
65
|
+
context do
|
66
|
+
before { hide_const('Kaminari') }
|
67
|
+
|
68
|
+
specify do
|
69
|
+
expect(subject.search_class.included_modules)
|
70
|
+
.to include(Chewy::Search::Pagination::WillPaginate)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#search_class' do
|
76
|
+
context 'nothing is defined' do
|
77
|
+
before do
|
78
|
+
hide_const('Kaminari')
|
79
|
+
hide_const('WillPaginate')
|
80
|
+
end
|
81
|
+
|
82
|
+
specify do
|
83
|
+
expect(subject.search_class.included_modules)
|
84
|
+
.not_to include(Chewy::Search::Pagination::Kaminari)
|
85
|
+
end
|
86
|
+
|
87
|
+
specify do
|
88
|
+
expect(subject.search_class.included_modules)
|
89
|
+
.not_to include(Chewy::Search::Pagination::WillPaginate)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'kaminari' do
|
94
|
+
before { hide_const('WillPaginate') }
|
95
|
+
|
96
|
+
specify do
|
97
|
+
expect(subject.search_class.included_modules)
|
98
|
+
.to include(Chewy::Search::Pagination::Kaminari)
|
99
|
+
end
|
100
|
+
|
101
|
+
specify do
|
102
|
+
expect(subject.search_class.included_modules)
|
103
|
+
.not_to include(Chewy::Search::Pagination::WillPaginate)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'will_paginate' do
|
108
|
+
before { hide_const('Kaminari') }
|
109
|
+
|
110
|
+
specify do
|
111
|
+
expect(subject.search_class.included_modules)
|
112
|
+
.not_to include(Chewy::Search::Pagination::Kaminari)
|
113
|
+
end
|
114
|
+
|
115
|
+
specify do
|
116
|
+
expect(subject.search_class.included_modules)
|
117
|
+
.to include(Chewy::Search::Pagination::WillPaginate)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'both are defined' do
|
122
|
+
specify do
|
123
|
+
expect(subject.search_class.included_modules)
|
124
|
+
.to include(Chewy::Search::Pagination::Kaminari)
|
125
|
+
end
|
126
|
+
|
127
|
+
specify do
|
128
|
+
expect(subject.search_class.included_modules)
|
129
|
+
.not_to include(Chewy::Search::Pagination::WillPaginate)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
53
134
|
describe '#configuration' do
|
54
|
-
before { subject.settings = {
|
135
|
+
before { subject.settings = {indices_path: 'app/custom_indices_path'} }
|
55
136
|
|
56
137
|
specify do
|
57
138
|
expect(subject.configuration).to include(indices_path: 'app/custom_indices_path')
|
58
139
|
end
|
140
|
+
|
141
|
+
context 'when Rails::VERSION constant is defined' do
|
142
|
+
it 'looks for configuration in "config/chewy.yml"' do
|
143
|
+
module Rails
|
144
|
+
VERSION = '5.1.1'.freeze
|
145
|
+
|
146
|
+
def self.root
|
147
|
+
Pathname.new(__dir__)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
expect(File).to receive(:exist?)
|
152
|
+
.with(Pathname.new(__dir__).join('config', 'chewy.yml'))
|
153
|
+
subject.configuration
|
154
|
+
end
|
155
|
+
end
|
59
156
|
end
|
60
157
|
end
|
@@ -8,8 +8,10 @@ describe Chewy::Fields::Base do
|
|
8
8
|
let(:field) { described_class.new(:name, value: ->(o) { o.value }) }
|
9
9
|
|
10
10
|
specify { expect(field.compose(double(value: 'hello'))).to eq(name: 'hello') }
|
11
|
-
specify { expect(field.compose(double(value: %w
|
11
|
+
specify { expect(field.compose(double(value: %w[hello world]))).to eq(name: %w[hello world]) }
|
12
12
|
|
13
|
+
specify { expect(described_class.new(:name, value: :last_name).compose(double(last_name: 'hello'))).to eq(name: 'hello') }
|
14
|
+
specify { expect(described_class.new(:name, value: :last_name).compose('last_name' => 'hello')).to eq(name: 'hello') }
|
13
15
|
specify { expect(described_class.new(:name).compose(double(name: 'hello'))).to eq(name: 'hello') }
|
14
16
|
specify { expect(described_class.new(:false_value).compose(false_value: false)).to eq(false_value: false) }
|
15
17
|
specify { expect(described_class.new(:true_value).compose(true_value: true)).to eq(true_value: true) }
|
@@ -24,23 +26,24 @@ describe Chewy::Fields::Base do
|
|
24
26
|
|
25
27
|
specify do
|
26
28
|
expect(field.compose(double(value: double(subvalue1: 'hello', subvalue2: 'value', subname3: 'world'))))
|
27
|
-
.to eq(name: {
|
29
|
+
.to eq(name: {subname1: 'hello', subname2: 'value', subname3: 'world'})
|
28
30
|
end
|
29
31
|
specify do
|
30
32
|
expect(field.compose(double(value: [
|
31
33
|
double(subvalue1: 'hello1', subvalue2: 'value1', subname3: 'world1'),
|
32
34
|
double(subvalue1: 'hello2', subvalue2: 'value2', subname3: 'world2')
|
33
35
|
]))).to eq(name: [
|
34
|
-
{
|
35
|
-
{
|
36
|
+
{subname1: 'hello1', subname2: 'value1', subname3: 'world1'},
|
37
|
+
{subname1: 'hello2', subname2: 'value2', subname3: 'world2'}
|
36
38
|
])
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
context 'parent objects' do
|
41
|
-
let!(:country) { described_class.new(:name, value: ->(country) { country.cities }) }
|
42
|
-
let!(:city) { described_class.new(:name, value: ->(city, country) { city.districts.map { |district| [district, country.name] } }) }
|
43
|
-
let!(:district) { described_class.new(:name, value: ->(district, city, country) { [district, city.name, country.name] }) }
|
43
|
+
let!(:country) { described_class.new(:name, value: ->(country, crutches) { country.cities.map { |city| double(districts: city.districts, name: crutches.city_name) } }) }
|
44
|
+
let!(:city) { described_class.new(:name, value: ->(city, country, crutches) { city.districts.map { |district| [district, country.name, crutches.suffix] } }) }
|
45
|
+
let!(:district) { described_class.new(:name, value: ->(district, city, country, crutches) { [district, city.name, country.name, crutches] }) }
|
46
|
+
let(:crutches) { double(suffix: 'suffix', city_name: 'Bangkok') }
|
44
47
|
|
45
48
|
before do
|
46
49
|
country.children.push(city)
|
@@ -49,18 +52,18 @@ describe Chewy::Fields::Base do
|
|
49
52
|
|
50
53
|
specify do
|
51
54
|
expect(country.compose(double(name: 'Thailand', cities: [
|
52
|
-
double(
|
53
|
-
]))).to eq(name: [
|
54
|
-
{
|
55
|
-
{
|
56
|
-
{
|
57
|
-
]
|
55
|
+
double(districts: %w[First Second])
|
56
|
+
]), crutches)).to eq(name: [
|
57
|
+
{name: [
|
58
|
+
{name: [%w[First Thailand suffix], 'Bangkok', 'Thailand', crutches]},
|
59
|
+
{name: [%w[Second Thailand suffix], 'Bangkok', 'Thailand', crutches]}
|
60
|
+
]}
|
58
61
|
])
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
62
65
|
context 'implicit values' do
|
63
|
-
let(:field) { described_class.new(:name, type: '
|
66
|
+
let(:field) { described_class.new(:name, type: 'integer') }
|
64
67
|
before do
|
65
68
|
field.children.push(described_class.new(:name))
|
66
69
|
field.children.push(described_class.new(:untouched))
|
@@ -71,50 +74,52 @@ describe Chewy::Fields::Base do
|
|
71
74
|
|
72
75
|
context 'hash values' do
|
73
76
|
let(:field) { described_class.new(:name, type: 'object') }
|
74
|
-
let(:object) { double(name: {
|
77
|
+
let(:object) { double(name: {key1: 'value1', key2: 'value2'}) }
|
75
78
|
|
76
79
|
before do
|
77
80
|
field.children.push(described_class.new(:key1, value: ->(h) { h[:key1] }))
|
78
81
|
field.children.push(described_class.new(:key2, value: ->(h) { h[:key2] }))
|
79
82
|
end
|
80
83
|
|
81
|
-
specify { expect(field.compose(object)).to eq(name: {
|
84
|
+
specify { expect(field.compose(object)).to eq(name: {key1: 'value1', key2: 'value2'}) }
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
85
88
|
describe '#mappings_hash' do
|
86
89
|
let(:field) { described_class.new(:name, type: :object) }
|
87
|
-
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}", type: "
|
88
|
-
let(:fields2) { Array.new(2) { |i| described_class.new("name#{i + 3}", type: "
|
90
|
+
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}", type: "integer#{i + 1}") } }
|
91
|
+
let(:fields2) { Array.new(2) { |i| described_class.new("name#{i + 3}", type: "integer#{i + 3}") } }
|
89
92
|
before do
|
90
93
|
fields1.each { |m| field.children.push(m) }
|
91
94
|
fields2.each { |m| fields1[0].children.push(m) }
|
92
95
|
end
|
93
96
|
|
94
97
|
specify do
|
95
|
-
expect(field.mappings_hash).to eq(name: {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
98
|
+
expect(field.mappings_hash).to eq(name: {type: :object, properties: {
|
99
|
+
name1: {type: 'integer1', fields: {
|
100
|
+
name3: {type: 'integer3'}, name4: {type: 'integer4'}
|
101
|
+
}}, name2: {type: 'integer2'}
|
102
|
+
}})
|
100
103
|
end
|
101
104
|
|
102
105
|
context do
|
103
|
-
let(:field) { described_class.new(:name, type: :
|
104
|
-
let(:fields1)
|
106
|
+
let(:field) { described_class.new(:name, type: :integer) }
|
107
|
+
let(:fields1) do
|
108
|
+
[described_class.new(:name1), described_class.new(:name2, type: 'integer')]
|
109
|
+
end
|
105
110
|
|
106
111
|
specify do
|
107
|
-
expect(field.mappings_hash).to eq(name: {
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
+
expect(field.mappings_hash).to eq(name: {type: :integer, fields: {
|
113
|
+
name1: {type: 'object', properties: {
|
114
|
+
name3: {type: 'integer3'}, name4: {type: 'integer4'}
|
115
|
+
}}, name2: {type: 'integer'}
|
116
|
+
}})
|
112
117
|
end
|
113
118
|
end
|
114
119
|
end
|
115
120
|
|
116
121
|
context 'integration' do
|
117
|
-
context '
|
122
|
+
context 'default field type' do
|
118
123
|
before do
|
119
124
|
stub_index(:events) do
|
120
125
|
define_type :event do
|
@@ -123,108 +128,134 @@ describe Chewy::Fields::Base do
|
|
123
128
|
field :id
|
124
129
|
field :licenses do
|
125
130
|
field :id
|
126
|
-
field :
|
131
|
+
field :created_at, type: 'time'
|
127
132
|
end
|
128
133
|
end
|
129
134
|
end
|
130
135
|
end
|
131
136
|
end
|
132
137
|
|
138
|
+
around do |example|
|
139
|
+
previous_type = Chewy.default_field_type
|
140
|
+
Chewy.default_field_type = 'integer'
|
141
|
+
example.run
|
142
|
+
Chewy.default_field_type = previous_type
|
143
|
+
end
|
144
|
+
|
133
145
|
specify do
|
134
146
|
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
properties: {
|
148
|
+
id: {type: 'integer'},
|
149
|
+
category: {
|
150
|
+
type: 'object',
|
151
|
+
properties: {
|
152
|
+
id: {type: 'integer'},
|
153
|
+
licenses: {
|
154
|
+
type: 'object',
|
155
|
+
properties: {
|
156
|
+
id: {type: 'integer'},
|
157
|
+
created_at: {type: 'time'}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
})
|
152
164
|
end
|
165
|
+
end
|
153
166
|
|
167
|
+
context 'objects, hashes and arrays' do
|
168
|
+
before do
|
169
|
+
stub_index(:events) do
|
170
|
+
define_type :event do
|
171
|
+
field :id
|
172
|
+
field :category do
|
173
|
+
field :id
|
174
|
+
field :licenses do
|
175
|
+
field :id
|
176
|
+
field :name
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# rubocop:disable Style/BracesAroundHashParameters
|
154
184
|
specify do
|
155
|
-
expect(EventsIndex::Event.
|
156
|
-
|
157
|
-
)).to eq('
|
185
|
+
expect(EventsIndex::Event.root.compose({
|
186
|
+
id: 1, category: {id: 2, licenses: {id: 3, name: 'Name'}}
|
187
|
+
})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
158
188
|
end
|
159
189
|
|
160
190
|
specify do
|
161
|
-
expect(EventsIndex::Event.
|
162
|
-
{
|
163
|
-
{
|
164
|
-
])).to eq('
|
165
|
-
{
|
166
|
-
{
|
167
|
-
]
|
191
|
+
expect(EventsIndex::Event.root.compose({id: 1, category: [
|
192
|
+
{id: 2, 'licenses' => {id: 3, name: 'Name1'}},
|
193
|
+
{id: 4, licenses: nil}
|
194
|
+
]})).to eq('id' => 1, 'category' => [
|
195
|
+
{'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name1'}},
|
196
|
+
{'id' => 4, 'licenses' => nil.as_json}
|
197
|
+
])
|
168
198
|
end
|
169
199
|
|
170
200
|
specify do
|
171
|
-
expect(EventsIndex::Event.
|
172
|
-
{
|
173
|
-
]
|
174
|
-
{
|
175
|
-
]
|
201
|
+
expect(EventsIndex::Event.root.compose({'id' => 1, category: {id: 2, licenses: [
|
202
|
+
{id: 3, name: 'Name1'}, {id: 4, name: 'Name2'}
|
203
|
+
]}})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
|
204
|
+
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
205
|
+
]})
|
176
206
|
end
|
177
207
|
|
178
208
|
specify do
|
179
|
-
expect(EventsIndex::Event.
|
180
|
-
{
|
181
|
-
{
|
182
|
-
]
|
183
|
-
{
|
184
|
-
])).to eq('
|
185
|
-
{
|
186
|
-
{
|
187
|
-
]
|
188
|
-
{
|
189
|
-
]
|
209
|
+
expect(EventsIndex::Event.root.compose({id: 1, category: [
|
210
|
+
{id: 2, licenses: [
|
211
|
+
{id: 3, 'name' => 'Name1'}, {id: 4, name: 'Name2'}
|
212
|
+
]},
|
213
|
+
{id: 5, licenses: []}
|
214
|
+
]})).to eq('id' => 1, 'category' => [
|
215
|
+
{'id' => 2, 'licenses' => [
|
216
|
+
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
217
|
+
]},
|
218
|
+
{'id' => 5, 'licenses' => []}
|
219
|
+
])
|
190
220
|
end
|
221
|
+
# rubocop:enable Style/BracesAroundHashParameters
|
191
222
|
|
192
223
|
specify do
|
193
|
-
expect(EventsIndex::Event.
|
224
|
+
expect(EventsIndex::Event.root.compose(
|
194
225
|
double(id: 1, category: double(id: 2, licenses: double(id: 3, name: 'Name')))
|
195
|
-
)).to eq('
|
226
|
+
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
196
227
|
end
|
197
228
|
|
198
229
|
specify do
|
199
|
-
expect(EventsIndex::Event.
|
230
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: [
|
200
231
|
double(id: 2, licenses: double(id: 3, name: 'Name1')),
|
201
232
|
double(id: 4, licenses: nil)
|
202
|
-
]))).to eq('
|
203
|
-
{
|
204
|
-
{
|
205
|
-
]
|
233
|
+
]))).to eq('id' => 1, 'category' => [
|
234
|
+
{'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name1'}},
|
235
|
+
{'id' => 4, 'licenses' => nil.as_json}
|
236
|
+
])
|
206
237
|
end
|
207
238
|
|
208
239
|
specify do
|
209
|
-
expect(EventsIndex::Event.
|
240
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: double(id: 2, licenses: [
|
210
241
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
211
|
-
])))).to eq('
|
212
|
-
{
|
213
|
-
]
|
242
|
+
])))).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
|
243
|
+
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
244
|
+
]})
|
214
245
|
end
|
215
246
|
|
216
247
|
specify do
|
217
|
-
expect(EventsIndex::Event.
|
248
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: [
|
218
249
|
double(id: 2, licenses: [
|
219
250
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
220
251
|
]),
|
221
252
|
double(id: 5, licenses: [])
|
222
|
-
]))).to eq('
|
223
|
-
{
|
224
|
-
{
|
225
|
-
]
|
226
|
-
{
|
227
|
-
]
|
253
|
+
]))).to eq('id' => 1, 'category' => [
|
254
|
+
{'id' => 2, 'licenses' => [
|
255
|
+
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
256
|
+
]},
|
257
|
+
{'id' => 5, 'licenses' => []}
|
258
|
+
])
|
228
259
|
end
|
229
260
|
end
|
230
261
|
|
@@ -232,11 +263,11 @@ describe Chewy::Fields::Base do
|
|
232
263
|
before do
|
233
264
|
stub_index(:events) do
|
234
265
|
define_type :event do
|
235
|
-
field :id
|
266
|
+
field :id, type: 'integer'
|
236
267
|
field :category, value: -> { categories } do
|
237
|
-
field :id
|
268
|
+
field :id, type: 'integer'
|
238
269
|
field :licenses, value: -> { license } do
|
239
|
-
field :id
|
270
|
+
field :id, type: 'integer'
|
240
271
|
field :name
|
241
272
|
end
|
242
273
|
end
|
@@ -245,9 +276,9 @@ describe Chewy::Fields::Base do
|
|
245
276
|
end
|
246
277
|
|
247
278
|
specify do
|
248
|
-
expect(EventsIndex::Event.
|
279
|
+
expect(EventsIndex::Event.root.compose(
|
249
280
|
double(id: 1, categories: double(id: 2, license: double(id: 3, name: 'Name')))
|
250
|
-
)).to eq('
|
281
|
+
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
251
282
|
end
|
252
283
|
end
|
253
284
|
|
@@ -255,8 +286,8 @@ describe Chewy::Fields::Base do
|
|
255
286
|
before do
|
256
287
|
stub_index(:events) do
|
257
288
|
define_type :event do
|
258
|
-
field :id
|
259
|
-
field :name, type: '
|
289
|
+
field :id, type: 'integer'
|
290
|
+
field :name, type: 'integer' do
|
260
291
|
field :raw, analyzer: 'my_own'
|
261
292
|
end
|
262
293
|
field :category, type: 'object'
|
@@ -266,43 +297,43 @@ describe Chewy::Fields::Base do
|
|
266
297
|
|
267
298
|
specify do
|
268
299
|
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
300
|
+
properties: {
|
301
|
+
id: {type: 'integer'},
|
302
|
+
name: {
|
303
|
+
type: 'integer',
|
304
|
+
fields: {
|
305
|
+
raw: {analyzer: 'my_own', type: Chewy.default_field_type}
|
306
|
+
}
|
307
|
+
},
|
308
|
+
category: {type: 'object'}
|
309
|
+
}
|
310
|
+
})
|
280
311
|
end
|
281
312
|
|
282
313
|
specify do
|
283
|
-
expect(EventsIndex::Event.
|
284
|
-
double(id: 1, name: 'Jonny', category: double(id: 2, as_json: {
|
285
|
-
)).to eq(
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
314
|
+
expect(EventsIndex::Event.root.compose(
|
315
|
+
double(id: 1, name: 'Jonny', category: double(id: 2, as_json: {'name' => 'Borogoves'}))
|
316
|
+
)).to eq(
|
317
|
+
'id' => 1,
|
318
|
+
'name' => 'Jonny',
|
319
|
+
'category' => {'name' => 'Borogoves'}
|
320
|
+
)
|
290
321
|
end
|
291
322
|
|
292
323
|
specify do
|
293
|
-
expect(EventsIndex::Event.
|
324
|
+
expect(EventsIndex::Event.root.compose(
|
294
325
|
double(id: 1, name: 'Jonny', category: [
|
295
|
-
double(id: 2, as_json: {
|
296
|
-
double(id: 3, as_json: {
|
326
|
+
double(id: 2, as_json: {'name' => 'Borogoves1'}),
|
327
|
+
double(id: 3, as_json: {'name' => 'Borogoves2'})
|
297
328
|
])
|
298
|
-
)).to eq(
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
329
|
+
)).to eq(
|
330
|
+
'id' => 1,
|
331
|
+
'name' => 'Jonny',
|
332
|
+
'category' => [
|
333
|
+
{'name' => 'Borogoves1'},
|
334
|
+
{'name' => 'Borogoves2'}
|
335
|
+
]
|
336
|
+
)
|
306
337
|
end
|
307
338
|
end
|
308
339
|
|
@@ -320,7 +351,11 @@ describe Chewy::Fields::Base do
|
|
320
351
|
Country.has_many :cities, order: :id
|
321
352
|
end
|
322
353
|
when :mongoid
|
323
|
-
|
354
|
+
if Mongoid::VERSION.start_with?('6')
|
355
|
+
City.belongs_to :country, optional: true
|
356
|
+
else
|
357
|
+
City.belongs_to :country
|
358
|
+
end
|
324
359
|
Country.has_many :cities, order: :id.asc
|
325
360
|
when :sequel
|
326
361
|
City.many_to_one :country
|
@@ -351,9 +386,9 @@ describe Chewy::Fields::Base do
|
|
351
386
|
end
|
352
387
|
|
353
388
|
specify do
|
354
|
-
expect(CountriesIndex::Country.
|
355
|
-
{
|
356
|
-
]
|
389
|
+
expect(CountriesIndex::Country.root.compose(country_with_cities)).to eq('id' => 1, 'cities' => [
|
390
|
+
{'id' => 1, 'name' => 'City1'}, {'id' => 2, 'name' => 'City2'}
|
391
|
+
])
|
357
392
|
end
|
358
393
|
|
359
394
|
context 'nested object' do
|
@@ -370,9 +405,9 @@ describe Chewy::Fields::Base do
|
|
370
405
|
end
|
371
406
|
|
372
407
|
specify do
|
373
|
-
expect(CitiesIndex::City.
|
408
|
+
expect(CitiesIndex::City.root.compose(
|
374
409
|
City.create!(id: 1, country: Country.create!(id: 1, name: 'Country'))
|
375
|
-
)).to eq('
|
410
|
+
)).to eq('id' => 1, 'country' => {'id' => 1, 'name' => 'Country'})
|
376
411
|
end
|
377
412
|
end
|
378
413
|
end
|