chewy 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +58 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -7
- data/Guardfile +3 -1
- data/README.md +282 -245
- data/chewy.gemspec +3 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
- data/lib/chewy.rb +21 -75
- data/lib/chewy/config.rb +40 -40
- data/lib/chewy/errors.rb +0 -12
- data/lib/chewy/fields/base.rb +11 -1
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +46 -87
- data/lib/chewy/index/actions.rb +51 -32
- data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
- data/lib/chewy/{type → index}/crutch.rb +5 -5
- data/lib/chewy/{type → index}/import.rb +36 -27
- data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
- data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
- data/lib/chewy/{type → index}/import/routine.rb +15 -14
- data/lib/chewy/{type → index}/mapping.rb +26 -31
- data/lib/chewy/{type → index}/observe.rb +9 -19
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +60 -57
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/journal.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +9 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/railtie.rb +4 -2
- data/lib/chewy/rake_helper.rb +82 -107
- data/lib/chewy/rspec/update_index.rb +47 -43
- data/lib/chewy/search.rb +4 -17
- data/lib/chewy/search/loader.rb +18 -30
- data/lib/chewy/search/parameters.rb +4 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +82 -86
- data/lib/chewy/search/response.rb +4 -4
- data/lib/chewy/search/scoping.rb +6 -7
- data/lib/chewy/search/scrolling.rb +11 -11
- data/lib/chewy/stash.rb +14 -22
- data/lib/chewy/strategy.rb +3 -19
- data/lib/chewy/strategy/sidekiq.rb +1 -0
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +10 -22
- data/migration_guide.md +14 -0
- data/spec/chewy/config_spec.rb +14 -39
- data/spec/chewy/fields/base_spec.rb +412 -148
- data/spec/chewy/fields/root_spec.rb +16 -24
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +270 -24
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
- data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
- data/spec/chewy/{type → index}/import_spec.rb +102 -98
- data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
- data/spec/chewy/index/observe_spec.rb +116 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +7 -17
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +59 -102
- data/spec/chewy/journal_spec.rb +9 -22
- data/spec/chewy/minitest/helpers_spec.rb +13 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +145 -55
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/search/loader_spec.rb +19 -37
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/indices_spec.rb +2 -8
- data/spec/chewy/search/parameters/order_spec.rb +1 -1
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters_spec.rb +12 -3
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +222 -74
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +7 -9
- data/spec/chewy/search_spec.rb +32 -35
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +14 -100
- data/spec/spec_helper.rb +2 -21
- data/spec/support/active_record.rb +15 -5
- metadata +44 -103
- data/.circleci/config.yml +0 -214
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type.rb +0 -120
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
data/lib/chewy/type/actions.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module Chewy
|
|
2
|
-
class Type
|
|
3
|
-
module Actions
|
|
4
|
-
extend ActiveSupport::Concern
|
|
5
|
-
|
|
6
|
-
module ClassMethods
|
|
7
|
-
# Deletes all documents of a type and reimports them
|
|
8
|
-
#
|
|
9
|
-
# @example
|
|
10
|
-
# UsersIndex::User.reset
|
|
11
|
-
#
|
|
12
|
-
# @see Chewy::Type::Import::ClassMethods#import
|
|
13
|
-
# @see Chewy::Type::Import::ClassMethods#import
|
|
14
|
-
# @return [true, false] the result of import
|
|
15
|
-
def reset
|
|
16
|
-
delete_all
|
|
17
|
-
import
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Performs missing and outdated objects synchronization for the current type.
|
|
21
|
-
#
|
|
22
|
-
# @example
|
|
23
|
-
# UsersIndex::User.sync
|
|
24
|
-
#
|
|
25
|
-
# @see Chewy::Type::Syncer
|
|
26
|
-
# @param parallel [true, Integer, Hash] options for parallel execution or the number of processes
|
|
27
|
-
# @return [Hash{Symbol, Object}, nil] a number of missing and outdated documents reindexed and their ids, nil in case of errors
|
|
28
|
-
def sync(parallel: nil)
|
|
29
|
-
syncer = Syncer.new(self, parallel: parallel)
|
|
30
|
-
count = syncer.perform
|
|
31
|
-
{count: count, missing: syncer.missing_ids, outdated: syncer.outdated_ids} if count
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# A {Chewy::Journal} instance for the particular type
|
|
35
|
-
#
|
|
36
|
-
# @return [Chewy::Journal] journal instance
|
|
37
|
-
def journal
|
|
38
|
-
@journal ||= Chewy::Journal.new(self)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
require 'chewy/type/adapter/orm'
|
|
2
|
-
|
|
3
|
-
module Chewy
|
|
4
|
-
class Type
|
|
5
|
-
module Adapter
|
|
6
|
-
class Mongoid < Orm
|
|
7
|
-
def self.accepts?(target)
|
|
8
|
-
defined?(::Mongoid::Document) && (
|
|
9
|
-
target.is_a?(Class) && target.ancestors.include?(::Mongoid::Document) ||
|
|
10
|
-
target.is_a?(::Mongoid::Criteria))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def identify(collection)
|
|
14
|
-
super(collection).map { |id| id.is_a?(BSON::ObjectId) ? id.to_s : id }
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def cleanup_default_scope!
|
|
20
|
-
Chewy.logger.warn('Default type scope order, limit and offset are ignored and will be nullified') if Chewy.logger && @default_scope.options.values_at(:sort, :limit, :skip).compact.present?
|
|
21
|
-
|
|
22
|
-
@default_scope.options.delete(:limit)
|
|
23
|
-
@default_scope.options.delete(:skip)
|
|
24
|
-
@default_scope = @default_scope.reorder(nil)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def import_scope(scope, options)
|
|
28
|
-
pluck_in_batches(scope, **options.slice(:batch_size)).map do |ids|
|
|
29
|
-
yield grouped_objects(default_scope_where_ids_in(ids))
|
|
30
|
-
end.all?
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def primary_key
|
|
34
|
-
:_id
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def pluck(scope, fields: [])
|
|
38
|
-
scope.pluck(primary_key, *fields)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def pluck_in_batches(scope, fields: [], batch_size: nil, **options)
|
|
42
|
-
return enum_for(:pluck_in_batches, scope, fields: fields, batch_size: batch_size, **options) unless block_given?
|
|
43
|
-
|
|
44
|
-
scope.batch_size(batch_size).no_timeout.pluck(primary_key, *fields).each_slice(batch_size) do |batch|
|
|
45
|
-
yield batch
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def scope_where_ids_in(scope, ids)
|
|
50
|
-
scope.where(primary_key.in => ids)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def all_scope
|
|
54
|
-
target.all
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def relation_class
|
|
58
|
-
::Mongoid::Criteria
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def object_class
|
|
62
|
-
::Mongoid::Document
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
require 'chewy/type/adapter/base'
|
|
2
|
-
|
|
3
|
-
module Chewy
|
|
4
|
-
class Type
|
|
5
|
-
module Adapter
|
|
6
|
-
class Sequel < Orm
|
|
7
|
-
attr_reader :default_scope
|
|
8
|
-
alias_method :default_dataset, :default_scope
|
|
9
|
-
|
|
10
|
-
def self.accepts?(target)
|
|
11
|
-
defined?(::Sequel::Model) && (
|
|
12
|
-
target.is_a?(Class) && target < ::Sequel::Model ||
|
|
13
|
-
target.is_a?(::Sequel::Dataset))
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def cleanup_default_scope!
|
|
19
|
-
Chewy.logger.warn('Default type scope order, limit and offset are ignored and will be nullified') if Chewy.logger && @default_scope != @default_scope.unordered.unlimited
|
|
20
|
-
|
|
21
|
-
@default_scope = @default_scope.unordered.unlimited
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def import_scope(scope, options)
|
|
25
|
-
pluck_in_batches(scope, **options.slice(:batch_size)).inject(true) do |result, ids|
|
|
26
|
-
result & yield(grouped_objects(default_scope_where_ids_in(ids).all))
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def primary_key
|
|
31
|
-
target.primary_key
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def full_column_name(column)
|
|
35
|
-
::Sequel.qualify(target.table_name, column)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def all_scope
|
|
39
|
-
target.dataset
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def target_columns
|
|
43
|
-
@target_columns ||= target.columns.to_set
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def pluck(scope, fields: [])
|
|
47
|
-
fields = fields.map(&:to_sym).unshift(primary_key).map do |column|
|
|
48
|
-
target_columns.include?(column) ? full_column_name(column) : column
|
|
49
|
-
end
|
|
50
|
-
scope.distinct.select_map(fields.one? ? fields.first : fields)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def pluck_in_batches(scope, fields: [], batch_size: nil, **options)
|
|
54
|
-
return enum_for(:pluck_in_batches, scope, fields: fields, batch_size: batch_size, **options) unless block_given?
|
|
55
|
-
|
|
56
|
-
scope = scope.unordered.order(full_column_name(primary_key).asc).limit(batch_size)
|
|
57
|
-
|
|
58
|
-
ids = pluck(scope, fields: fields)
|
|
59
|
-
count = 0
|
|
60
|
-
|
|
61
|
-
while ids.present?
|
|
62
|
-
yield ids
|
|
63
|
-
break if ids.size < batch_size
|
|
64
|
-
last_id = ids.last.is_a?(Array) ? ids.last.first : ids.last
|
|
65
|
-
ids = pluck(scope.where { |_o| full_column_name(primary_key) > last_id }, fields: fields)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
count
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def scope_where_ids_in(scope, ids)
|
|
72
|
-
scope.where(full_column_name(primary_key) => Array.wrap(ids))
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def model_of_relation(relation)
|
|
76
|
-
relation.model
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def relation_class
|
|
80
|
-
::Sequel::Dataset
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def object_class
|
|
84
|
-
::Sequel::Model
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def load_scope_objects(*args)
|
|
88
|
-
super.all
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
require 'active_support/callbacks'
|
|
2
|
-
|
|
3
|
-
module Sequel
|
|
4
|
-
module Plugins
|
|
5
|
-
# This Sequel plugin adds support for chewy's model-observing hook for
|
|
6
|
-
# updating indexes after model save or destroy.
|
|
7
|
-
#
|
|
8
|
-
# Usage:
|
|
9
|
-
#
|
|
10
|
-
# # Make all model subclasses support the `update_index` hook (called
|
|
11
|
-
# # before loading subclasses).
|
|
12
|
-
# Sequel::Model.plugin :chewy_observe
|
|
13
|
-
#
|
|
14
|
-
# # Make the Album class support the `update_index` hooks.
|
|
15
|
-
# Album.plugin :chewy_observe
|
|
16
|
-
#
|
|
17
|
-
# # Declare one or more `update_index` observers in model.
|
|
18
|
-
# class Album < Sequel::Model
|
|
19
|
-
# update_index('albums#album') { self }
|
|
20
|
-
# end
|
|
21
|
-
#
|
|
22
|
-
module ChewyObserve
|
|
23
|
-
extend ::Chewy::Type::Observe::Helpers
|
|
24
|
-
|
|
25
|
-
def self.apply(model)
|
|
26
|
-
model.instance_eval do
|
|
27
|
-
include ActiveSupport::Callbacks
|
|
28
|
-
define_callbacks :commit, :destroy_commit, :save, :destroy
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Class level methods for Sequel::Model
|
|
33
|
-
#
|
|
34
|
-
module ClassMethods
|
|
35
|
-
def update_index(type_name, *args, &block)
|
|
36
|
-
callback_options = ChewyObserve.extract_callback_options!(args)
|
|
37
|
-
update_proc = ChewyObserve.update_proc(type_name, *args, &block)
|
|
38
|
-
|
|
39
|
-
set_callback(:save, callback_options, &update_proc)
|
|
40
|
-
set_callback(:destroy, callback_options, &update_proc)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Instance level methods for Sequel::Model
|
|
45
|
-
#
|
|
46
|
-
module InstanceMethods
|
|
47
|
-
def after_save
|
|
48
|
-
run_callbacks(:save) do
|
|
49
|
-
super
|
|
50
|
-
db.after_commit {} if Chewy.use_after_commit_callbacks
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def after_destroy
|
|
55
|
-
run_callbacks(:destroy) do
|
|
56
|
-
super
|
|
57
|
-
db.after_commit {} if Chewy.use_after_commit_callbacks
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
shared_examples :will_paginate do |request_base_class|
|
|
4
|
-
before { Chewy.massacre }
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
stub_index(:products) do
|
|
8
|
-
define_type(:product) do
|
|
9
|
-
field :name
|
|
10
|
-
field :age, type: 'integer'
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
let(:except_fields) { %w[_score _explanation] }
|
|
16
|
-
let(:request_class) do
|
|
17
|
-
Class.new(request_base_class).tap do |k|
|
|
18
|
-
k.include Chewy::Search::Pagination::WillPaginate
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
let(:search) { request_class.new(ProductsIndex).order(:age) }
|
|
22
|
-
|
|
23
|
-
specify { expect(search.total_pages).to eq(1) } # defaults to 1 on will_paginate
|
|
24
|
-
|
|
25
|
-
context do
|
|
26
|
-
let(:data) { Array.new(10) { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
|
27
|
-
|
|
28
|
-
before { ProductsIndex::Product.import!(data.map { |h| double(h) }) }
|
|
29
|
-
before { allow(::WillPaginate).to receive_messages(per_page: 3) }
|
|
30
|
-
|
|
31
|
-
describe '#page' do
|
|
32
|
-
specify { expect(search.map { |e| e.attributes.except(*except_fields) }).to match_array(data) }
|
|
33
|
-
specify { expect(search.page(1).map { |e| e.attributes.except(*except_fields) }).to eq(data[0..2]) }
|
|
34
|
-
specify { expect(search.page(2).map { |e| e.attributes.except(*except_fields) }).to eq(data[3..5]) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe '#paginate' do
|
|
38
|
-
specify { expect(search.paginate(page: 2, per_page: 4).map { |e| e.attributes.except(*except_fields) }).to eq(data[4..7]) }
|
|
39
|
-
specify { expect(search.paginate(per_page: 2, page: 3).page(3).map { |e| e.attributes.except(*except_fields) }).to eq(data[4..5]) }
|
|
40
|
-
specify { expect(search.paginate(per_page: 5).map { |e| e.attributes.except(*except_fields) }).to eq(data[0..4]) }
|
|
41
|
-
specify { expect(search.paginate(per_page: 4).map { |e| e.attributes.except(*except_fields) }).to eq(data[0..3]) }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe '#total_pages' do
|
|
45
|
-
specify { expect(search.paginate(page: 2, per_page: 5).total_pages).to eq(2) }
|
|
46
|
-
specify { expect(search.paginate(page: 3, per_page: 2).total_pages).to eq(5) }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe '#total_entries' do
|
|
50
|
-
specify { expect(search.paginate(page: 1, per_page: 4).total_entries).to eq(10) }
|
|
51
|
-
specify { expect(search.query(range: {age: {gt: 20}}).limit(3).total_entries).to eq(8) }
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe '#load' do
|
|
55
|
-
specify { expect(search.paginate(per_page: 2, page: 1).load.first.age).to eq(10) }
|
|
56
|
-
specify { expect(search.paginate(per_page: 2, page: 3).load.first.age).to eq(50) }
|
|
57
|
-
specify { expect(search.paginate(per_page: 2, page: 3).load.page(2).load.first.age).to eq(30) }
|
|
58
|
-
|
|
59
|
-
specify { expect(search.paginate(per_page: 4, page: 1).load.total_count).to eq(10) }
|
|
60
|
-
specify { expect(search.paginate(per_page: 2, page: 3).load.total_pages).to eq(5) }
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'chewy/search/pagination/will_paginate_examples'
|
|
2
|
-
|
|
3
|
-
describe Chewy::Search::Pagination::WillPaginate do
|
|
4
|
-
it_behaves_like :will_paginate, Chewy::Search::Request do
|
|
5
|
-
describe '#objects' do
|
|
6
|
-
let(:data) { Array.new(12) { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
|
7
|
-
|
|
8
|
-
before { ProductsIndex::Product.import!(data.map { |h| double(h) }) }
|
|
9
|
-
before { allow(::WillPaginate).to receive_messages(per_page: 17) }
|
|
10
|
-
|
|
11
|
-
# specify { expect(search.current_page).to eq(1) }
|
|
12
|
-
# specify { expect(search.per_page).to eq(0) }
|
|
13
|
-
specify { expect(search.objects.class).to eq(WillPaginate::Collection) }
|
|
14
|
-
specify { expect(search.objects.total_entries).to eq(12) }
|
|
15
|
-
specify { expect(search.objects.per_page).to eq(17) }
|
|
16
|
-
specify { expect(search.objects.current_page).to eq(1) }
|
|
17
|
-
specify { expect(search.paginate(per_page: 2, page: 3).objects.class).to eq(WillPaginate::Collection) }
|
|
18
|
-
specify { expect(search.paginate(per_page: 2, page: 3).objects.total_entries).to eq(12) }
|
|
19
|
-
specify { expect(search.paginate(per_page: 2, page: 3).objects.per_page).to eq(2) }
|
|
20
|
-
specify { expect(search.paginate(per_page: 2, page: 3).objects.current_page).to eq(3) }
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
if defined?(::Resque)
|
|
4
|
-
require 'resque_spec'
|
|
5
|
-
|
|
6
|
-
describe Chewy::Strategy::Resque, :orm do
|
|
7
|
-
around { |example| Chewy.strategy(:bypass) { example.run } }
|
|
8
|
-
before { ResqueSpec.reset! }
|
|
9
|
-
before do
|
|
10
|
-
stub_model(:city) do
|
|
11
|
-
update_index('cities#city') { self }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
stub_index(:cities) do
|
|
15
|
-
define_type City
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
let(:city) { City.create!(name: 'hello') }
|
|
20
|
-
let(:other_city) { City.create!(name: 'world') }
|
|
21
|
-
|
|
22
|
-
specify do
|
|
23
|
-
expect { [city, other_city].map(&:save!) }
|
|
24
|
-
.not_to update_index(CitiesIndex::City, strategy: :resque)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
specify do
|
|
28
|
-
with_resque do
|
|
29
|
-
expect { [city, other_city].map(&:save!) }
|
|
30
|
-
.to update_index(CitiesIndex::City, strategy: :resque)
|
|
31
|
-
.and_reindex(city, other_city).only
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
specify do
|
|
36
|
-
expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
|
|
37
|
-
Chewy::Strategy::Resque::Worker.perform('CitiesIndex::City', [city.id, other_city.id], suffix: '201601')
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
specify do
|
|
41
|
-
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
|
42
|
-
expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
|
|
43
|
-
Chewy::Strategy::Resque::Worker.perform('CitiesIndex::City', [city.id, other_city.id], suffix: '201601')
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
if defined?(::Shoryuken)
|
|
4
|
-
require 'aws-sdk-sqs'
|
|
5
|
-
|
|
6
|
-
describe Chewy::Strategy::Shoryuken do
|
|
7
|
-
around do |example|
|
|
8
|
-
shoryuken_settings = Chewy.settings[:shoryuken]
|
|
9
|
-
Chewy.settings[:shoryuken] = {queue: 'low'}
|
|
10
|
-
Chewy.strategy(:bypass) { example.run }
|
|
11
|
-
Chewy.settings[:shoryuken] = shoryuken_settings
|
|
12
|
-
end
|
|
13
|
-
before { ::Shoryuken.groups.clear }
|
|
14
|
-
before do
|
|
15
|
-
stub_model(:city) do
|
|
16
|
-
update_index('cities#city') { self }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
stub_index(:cities) do
|
|
20
|
-
define_type City
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
let(:city) { City.create!(name: 'hello') }
|
|
25
|
-
let(:other_city) { City.create!(name: 'world') }
|
|
26
|
-
let(:queue) { instance_double(::Shoryuken::Queue) }
|
|
27
|
-
|
|
28
|
-
before do
|
|
29
|
-
allow(::Shoryuken::Queue).to receive(:new).and_return(queue)
|
|
30
|
-
allow(queue).to receive(:send_message).and_return(nil)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
specify do
|
|
34
|
-
expect { [city, other_city].map(&:save!) }
|
|
35
|
-
.not_to update_index(CitiesIndex::City, strategy: :shoryuken)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
specify do
|
|
39
|
-
expect(Chewy::Strategy::Shoryuken::Worker).to receive(:perform_async)
|
|
40
|
-
.with(hash_including(type: 'CitiesIndex::City', ids: [city.id, other_city.id]), hash_including(queue: 'low'))
|
|
41
|
-
Chewy.strategy(:shoryuken) do
|
|
42
|
-
[city, other_city].map(&:save!)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
let(:body) do
|
|
47
|
-
{
|
|
48
|
-
'type' => 'CitiesIndex::City',
|
|
49
|
-
'ids' => [city.id, other_city.id],
|
|
50
|
-
'options' => {'suffix' => '201601'}
|
|
51
|
-
}
|
|
52
|
-
end
|
|
53
|
-
let(:sqs_msg) do
|
|
54
|
-
double id: 'fc754df7-9cc2-4c41-96ca-5996a44b771e',
|
|
55
|
-
body: body,
|
|
56
|
-
delete: nil
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
specify do
|
|
60
|
-
expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
|
|
61
|
-
Chewy::Strategy::Shoryuken::Worker.new.perform(sqs_msg, body)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
specify do
|
|
65
|
-
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
|
66
|
-
expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
|
|
67
|
-
Chewy::Strategy::Shoryuken::Worker.new.perform(sqs_msg, body)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|