chewy 0.8.3 → 0.8.4
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/.travis.yml +43 -11
- data/Appraisals +39 -12
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -1
- data/README.md +60 -7
- data/chewy.gemspec +12 -5
- data/gemfiles/{rails.4.0.mongoid.gemfile → rails.4.0.mongoid.4.0.0.gemfile} +1 -1
- data/gemfiles/{rails.4.0.mongoid.kaminari.gemfile → rails.4.0.mongoid.4.0.0.kaminari.gemfile} +1 -1
- data/gemfiles/{rails.4.0.mongoid.will_paginate.gemfile → rails.4.0.mongoid.4.0.0.will_paginate.gemfile} +1 -1
- data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +15 -0
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +14 -0
- data/gemfiles/{rails.4.1.mongoid.gemfile → rails.4.1.mongoid.4.0.0.gemfile} +1 -1
- data/gemfiles/{rails.4.1.mongoid.kaminari.gemfile → rails.4.1.mongoid.4.0.0.kaminari.gemfile} +1 -1
- data/gemfiles/{rails.4.1.mongoid.will_paginate.gemfile → rails.4.1.mongoid.4.0.0.will_paginate.gemfile} +1 -1
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +15 -0
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +14 -0
- data/gemfiles/{rails.4.2.mongoid.gemfile → rails.4.2.mongoid.4.0.0.gemfile} +1 -1
- data/gemfiles/{rails.4.2.mongoid.kaminari.gemfile → rails.4.2.mongoid.4.0.0.kaminari.gemfile} +1 -1
- data/gemfiles/{rails.4.2.mongoid.will_paginate.gemfile → rails.4.2.mongoid.4.0.0.will_paginate.gemfile} +1 -1
- data/gemfiles/rails.4.2.mongoid.5.1.0.gemfile +15 -0
- data/gemfiles/rails.4.2.mongoid.5.1.0.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.2.mongoid.5.1.0.will_paginate.gemfile +14 -0
- data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +16 -0
- data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +16 -0
- data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +15 -0
- data/gemfiles/{sequel.4.28.gemfile → sequel.4.31.gemfile} +1 -1
- data/lib/chewy.rb +7 -1
- data/lib/chewy/errors.rb +6 -0
- data/lib/chewy/fields/base.rb +12 -8
- data/lib/chewy/fields/root.rb +1 -1
- data/lib/chewy/index.rb +17 -8
- data/lib/chewy/index/actions.rb +4 -4
- data/lib/chewy/query.rb +8 -13
- data/lib/chewy/query/compose.rb +2 -2
- data/lib/chewy/query/criteria.rb +2 -2
- data/lib/chewy/query/loading.rb +1 -1
- data/lib/chewy/query/nodes/bool.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +2 -2
- data/lib/chewy/railtie.rb +15 -3
- data/lib/chewy/rake_helper.rb +5 -2
- data/lib/chewy/rspec/update_index.rb +17 -6
- data/lib/chewy/strategy.rb +7 -3
- data/lib/chewy/strategy/active_job.rb +2 -2
- data/lib/chewy/strategy/resque.rb +2 -2
- data/lib/chewy/strategy/sidekiq.rb +2 -2
- data/lib/chewy/type.rb +14 -0
- data/lib/chewy/type/adapter/active_record.rb +11 -1
- data/lib/chewy/type/adapter/orm.rb +13 -11
- data/lib/chewy/type/adapter/sequel.rb +10 -12
- data/lib/chewy/type/import.rb +53 -22
- data/lib/chewy/type/witchcraft.rb +208 -0
- data/lib/chewy/type/wrapper.rb +25 -7
- data/lib/chewy/version.rb +1 -1
- data/lib/tasks/chewy.rake +22 -14
- data/spec/chewy/fields/base_spec.rb +6 -2
- data/spec/chewy/fields/time_fields_spec.rb +4 -4
- data/spec/chewy/index/actions_spec.rb +32 -18
- data/spec/chewy/index_spec.rb +19 -0
- data/spec/chewy/query/pagination_spec.rb +1 -1
- data/spec/chewy/query_spec.rb +77 -21
- data/spec/chewy/rspec/update_index_spec.rb +75 -62
- data/spec/chewy/runtime_spec.rb +1 -1
- data/spec/chewy/strategy/active_job_spec.rb +6 -1
- data/spec/chewy/strategy/atomic_spec.rb +5 -5
- data/spec/chewy/strategy/resque_spec.rb +7 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +6 -1
- data/spec/chewy/strategy_spec.rb +13 -1
- data/spec/chewy/type/actions_spec.rb +4 -1
- data/spec/chewy/type/import_spec.rb +71 -2
- data/spec/chewy/type/observe_spec.rb +9 -9
- data/spec/chewy/type/witchcraft_spec.rb +154 -0
- data/spec/chewy/type/wrapper_spec.rb +30 -5
- data/spec/chewy/type_spec.rb +10 -0
- data/spec/chewy_spec.rb +29 -5
- data/spec/spec_helper.rb +2 -0
- data/spec/support/class_helpers.rb +15 -0
- data/spec/support/mongoid.rb +5 -0
- metadata +64 -21
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
def try_require lib
|
|
2
|
+
require lib
|
|
3
|
+
rescue LoadError
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
%w[method_source parser/current unparser].each { |lib| try_require lib }
|
|
7
|
+
|
|
8
|
+
module Chewy
|
|
9
|
+
class Type
|
|
10
|
+
module Witchcraft
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
class_attribute :_witchcraft, instance_reader: false, instance_writer: false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
module ClassMethods
|
|
18
|
+
def witchcraft!
|
|
19
|
+
self._witchcraft = true
|
|
20
|
+
check_requirements!
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def check_requirements!
|
|
24
|
+
messages = []
|
|
25
|
+
messages << "MethodSource gem is required for the Witchcraft™, please add `gem 'method_source'` to your Gemfile" unless Proc.method_defined?(:source)
|
|
26
|
+
messages << "Parser gem is required for the Witchcraft™, please add `gem 'parser'` to your Gemfile" unless '::Parser'.safe_constantize
|
|
27
|
+
messages << "Unparser gem is required for the Witchcraft™, please add `gem 'unparser'` to your Gemfile" unless '::Unparser'.safe_constantize
|
|
28
|
+
messages = messages.join("\n")
|
|
29
|
+
|
|
30
|
+
raise messages if messages.present?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def witchcraft?
|
|
34
|
+
!!_witchcraft
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def cauldron
|
|
38
|
+
@cauldron ||= Cauldron.new(self)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Cauldron
|
|
43
|
+
def initialize(type)
|
|
44
|
+
@type = type
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def brew(object, crutches = nil)
|
|
48
|
+
alicorn.call(object, crutches).as_json
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def alicorn
|
|
54
|
+
@alicorn ||= class_eval <<-RUBY
|
|
55
|
+
-> (object0, crutches) do
|
|
56
|
+
#{composed_values(@type.root_object, 0)}
|
|
57
|
+
end
|
|
58
|
+
RUBY
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def composed_values(field, nesting)
|
|
62
|
+
source = <<-RUBY
|
|
63
|
+
non_proc_values#{nesting} = #{non_proc_values(field, nesting)}
|
|
64
|
+
proc_values#{nesting} = #{proc_values(field, nesting)}
|
|
65
|
+
non_proc_values#{nesting}.merge!(proc_values#{nesting})
|
|
66
|
+
RUBY
|
|
67
|
+
source.gsub("\n,", ',')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def composed_value(field, fetcher, nesting)
|
|
71
|
+
nesting = nesting.next
|
|
72
|
+
if field.children.present? && !field.multi_field?
|
|
73
|
+
<<-RUBY
|
|
74
|
+
(result#{nesting} = #{fetcher}
|
|
75
|
+
if result#{nesting}.respond_to?(:to_ary)
|
|
76
|
+
result#{nesting}.map do |object#{nesting}|
|
|
77
|
+
#{composed_values(field, nesting)}
|
|
78
|
+
end
|
|
79
|
+
else
|
|
80
|
+
object#{nesting} = result#{nesting}
|
|
81
|
+
#{composed_values(field, nesting)}
|
|
82
|
+
end)
|
|
83
|
+
RUBY
|
|
84
|
+
else
|
|
85
|
+
fetcher
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def non_proc_values(field, nesting)
|
|
90
|
+
non_proc_fields = non_proc_fields_for(field)
|
|
91
|
+
object = "object#{nesting}"
|
|
92
|
+
|
|
93
|
+
if non_proc_fields.present?
|
|
94
|
+
<<-RUBY
|
|
95
|
+
(if #{object}.is_a?(Hash)
|
|
96
|
+
{
|
|
97
|
+
#{non_proc_fields.map do |field|
|
|
98
|
+
fetcher = "#{object}.has_key?(:#{field.name}) ? #{object}[:#{field.name}] : #{object}['#{field.name}']"
|
|
99
|
+
"#{field.name}: #{composed_value(field, fetcher, nesting)}"
|
|
100
|
+
end.join(', ')}
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
{
|
|
104
|
+
#{non_proc_fields.map do |field|
|
|
105
|
+
"#{field.name}: #{composed_value(field, "#{object}.#{field.name}", nesting)}"
|
|
106
|
+
end.join(', ')}
|
|
107
|
+
}
|
|
108
|
+
end)
|
|
109
|
+
RUBY
|
|
110
|
+
else
|
|
111
|
+
"{}"
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def proc_values(field, nesting)
|
|
116
|
+
proc_fields = proc_fields_for(field)
|
|
117
|
+
|
|
118
|
+
if proc_fields.present?
|
|
119
|
+
<<-RUBY
|
|
120
|
+
{
|
|
121
|
+
#{proc_fields.map do |field|
|
|
122
|
+
"#{field.name}: (#{composed_value(field, source_for(field.value, nesting), nesting)})"
|
|
123
|
+
end.join(', ')}
|
|
124
|
+
}
|
|
125
|
+
RUBY
|
|
126
|
+
else
|
|
127
|
+
"{}"
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def non_proc_fields_for(parent)
|
|
132
|
+
return [] unless parent
|
|
133
|
+
(parent.children || []).select { |field| !(field.value && field.value.is_a?(Proc)) }
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def proc_fields_for(parent)
|
|
137
|
+
return [] unless parent
|
|
138
|
+
(parent.children || []).select { |field| field.value && field.value.is_a?(Proc) }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def source_for(proc, nesting)
|
|
142
|
+
ast = Parser::CurrentRuby.parse(proc.source)
|
|
143
|
+
lambdas = exctract_lambdas(ast)
|
|
144
|
+
|
|
145
|
+
raise "No lambdas found, try to reformat your code:\n`#{proc.source}`" unless lambdas
|
|
146
|
+
|
|
147
|
+
source = lambdas.first
|
|
148
|
+
if proc.arity == 0
|
|
149
|
+
source = replace_self(source, :"object#{nesting}")
|
|
150
|
+
source = replace_send(source, :"object#{nesting}")
|
|
151
|
+
elsif proc.arity < 0
|
|
152
|
+
raise "Splat arguments are unsupported by witchcraft:\n`#{proc.source}"
|
|
153
|
+
else
|
|
154
|
+
(nesting + 1).times do |n|
|
|
155
|
+
source = replace_lvar(source, proc.parameters[n][1], :"object#{n}") if proc.parameters[n]
|
|
156
|
+
end
|
|
157
|
+
source = replace_lvar(source, proc.parameters[nesting + 1][1], :crutches) if proc.parameters[nesting + 1]
|
|
158
|
+
end
|
|
159
|
+
Unparser.unparse(source)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def exctract_lambdas(node)
|
|
163
|
+
if node.type == :block && node.children[0].type == :send && node.children[0].to_a == [nil, :lambda]
|
|
164
|
+
node.children[2]
|
|
165
|
+
else
|
|
166
|
+
node.children.map { |child| exctract_lambdas(child) }.flatten.compact
|
|
167
|
+
end if node.is_a?(Parser::AST::Node)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def replace_lvar(node, old_variable, new_variable)
|
|
171
|
+
if node.is_a?(Parser::AST::Node)
|
|
172
|
+
if node.type == :lvar && node.children.to_a == [old_variable]
|
|
173
|
+
node.updated(nil, [new_variable])
|
|
174
|
+
else
|
|
175
|
+
node.updated(nil, node.children.map { |child| replace_lvar(child, old_variable, new_variable) })
|
|
176
|
+
end
|
|
177
|
+
else
|
|
178
|
+
node
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def replace_send(node, variable)
|
|
183
|
+
if node.is_a?(Parser::AST::Node)
|
|
184
|
+
if node.type == :send && node.children[0].nil?
|
|
185
|
+
node.updated(nil, [Parser::AST::Node.new(:lvar, [variable]), *node.children[1..-1]])
|
|
186
|
+
else
|
|
187
|
+
node.updated(nil, node.children.map { |child| replace_send(child, variable) })
|
|
188
|
+
end
|
|
189
|
+
else
|
|
190
|
+
node
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def replace_self(node, variable)
|
|
195
|
+
if node.is_a?(Parser::AST::Node)
|
|
196
|
+
if node.type == :self
|
|
197
|
+
Parser::AST::Node.new(:lvar, [variable])
|
|
198
|
+
else
|
|
199
|
+
node.updated(nil, node.children.map { |child| replace_self(child, variable) })
|
|
200
|
+
end
|
|
201
|
+
else
|
|
202
|
+
node
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
data/lib/chewy/type/wrapper.rb
CHANGED
|
@@ -19,16 +19,34 @@ module Chewy
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def method_missing(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
else
|
|
26
|
-
nil
|
|
22
|
+
def method_missing(method_name, *args, &block)
|
|
23
|
+
method_name.to_s.match(/_highlight\z/) do |match|
|
|
24
|
+
return highlight(match.pre_match) if highlight?(match.pre_match)
|
|
27
25
|
end
|
|
26
|
+
return @attributes[method_name.to_s] if @attributes.key?(method_name.to_s)
|
|
27
|
+
return nil if attribute_defined?(method_name.to_s)
|
|
28
|
+
super
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
32
|
+
method_name.to_s.match(/_highlight\z/) { |m| highlight?(m.pre_match) } ||
|
|
33
|
+
@attributes.key?(method_name.to_s) ||
|
|
34
|
+
attribute_defined?(method_name.to_s) ||
|
|
35
|
+
super
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def attribute_defined?(attribute)
|
|
41
|
+
self.class.root_object && self.class.root_object.children.find { |a| a.name.to_s == attribute }.present?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def highlight(attribute)
|
|
45
|
+
_data["highlight"][attribute].first
|
|
28
46
|
end
|
|
29
47
|
|
|
30
|
-
def
|
|
31
|
-
|
|
48
|
+
def highlight?(attribute)
|
|
49
|
+
_data.key?("highlight") && _data["highlight"].key?(attribute)
|
|
32
50
|
end
|
|
33
51
|
end
|
|
34
52
|
end
|
data/lib/chewy/version.rb
CHANGED
data/lib/tasks/chewy.rake
CHANGED
|
@@ -3,39 +3,47 @@ require 'chewy/rake_helper'
|
|
|
3
3
|
namespace :chewy do
|
|
4
4
|
desc 'Destroy, recreate and import data to specified index'
|
|
5
5
|
task :reset, [:index] => :environment do |task, args|
|
|
6
|
-
Chewy::RakeHelper.
|
|
6
|
+
Chewy::RakeHelper.subscribed_task_stats do
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if args[:index].present?
|
|
9
|
+
Chewy::RakeHelper.reset_index(args[:index])
|
|
10
|
+
else
|
|
11
|
+
Chewy::RakeHelper.reset_all
|
|
12
|
+
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
namespace :reset do
|
|
16
17
|
desc 'Destroy, recreate and import data for all found indexes'
|
|
17
18
|
task all: :environment do
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
ActiveSupport::Deprecation.warn('`rake chewy:reset:all` is deprecated and will be removed soon. Use `rake chewy:reset` instead')
|
|
20
|
+
|
|
21
|
+
Chewy::RakeHelper.subscribed_task_stats do
|
|
22
|
+
Chewy::RakeHelper.reset_all
|
|
23
|
+
end
|
|
20
24
|
end
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
desc 'Updates data specified index'
|
|
24
28
|
task :update, [:index] => :environment do |task, args|
|
|
25
|
-
Chewy::RakeHelper.
|
|
29
|
+
Chewy::RakeHelper.subscribed_task_stats do
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
if args[:index].present?
|
|
32
|
+
Chewy::RakeHelper.update_index(args[:index])
|
|
33
|
+
else
|
|
34
|
+
Chewy::RakeHelper.update_all
|
|
35
|
+
end
|
|
31
36
|
end
|
|
32
37
|
end
|
|
33
38
|
|
|
34
39
|
namespace :update do
|
|
35
40
|
desc 'Updates data for all found indexes'
|
|
36
41
|
task all: :environment do
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
ActiveSupport::Deprecation.warn('`rake chewy:update:all` is deprecated and will be removed soon. Use `rake chewy:update` instead')
|
|
43
|
+
|
|
44
|
+
Chewy::RakeHelper.subscribed_task_stats do
|
|
45
|
+
Chewy::RakeHelper.update_all
|
|
46
|
+
end
|
|
39
47
|
end
|
|
40
48
|
end
|
|
41
49
|
end
|
|
@@ -11,6 +11,10 @@ describe Chewy::Fields::Base do
|
|
|
11
11
|
specify { expect(field.compose(double(value: ['hello', 'world']))).to eq({name: ['hello', 'world']}) }
|
|
12
12
|
|
|
13
13
|
specify { expect(described_class.new(:name).compose(double(name: 'hello'))).to eq({name: 'hello'}) }
|
|
14
|
+
specify { expect(described_class.new(:false_value).compose({false_value: false})).to eq({false_value: false}) }
|
|
15
|
+
specify { expect(described_class.new(:true_value).compose({true_value: true})).to eq({true_value: true}) }
|
|
16
|
+
specify { expect(described_class.new(:nil_value).compose({nil_value: nil})).to eq({nil_value: nil}) }
|
|
17
|
+
|
|
14
18
|
|
|
15
19
|
context 'nested fields' do
|
|
16
20
|
before do
|
|
@@ -62,14 +66,14 @@ describe Chewy::Fields::Base do
|
|
|
62
66
|
|
|
63
67
|
context 'hash values' do
|
|
64
68
|
let(:field) { described_class.new(:name, type: 'object') }
|
|
65
|
-
let(:object) { double(name: { key1: 'value1', key2: 'value2'
|
|
69
|
+
let(:object) { double(name: { key1: 'value1', key2: 'value2'}) }
|
|
66
70
|
|
|
67
71
|
before do
|
|
68
72
|
field.children.push(described_class.new(:key1, value: ->(h){ h[:key1] }))
|
|
69
73
|
field.children.push(described_class.new(:key2, value: ->(h){ h[:key2] }))
|
|
70
74
|
end
|
|
71
75
|
|
|
72
|
-
specify{ expect(field.compose(object)).to eq({ name: { 'key1' => 'value1', 'key2' => 'value2'
|
|
76
|
+
specify{ expect(field.compose(object)).to eq({ name: { 'key1' => 'value1', 'key2' => 'value2'} }) }
|
|
73
77
|
end
|
|
74
78
|
end
|
|
75
79
|
|
|
@@ -12,7 +12,7 @@ describe 'Time fields' do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
before { PostsIndex::Post.import(
|
|
15
|
-
double(published_at: ActiveSupport::TimeZone[-28800].parse('2014/12/18
|
|
15
|
+
double(published_at: ActiveSupport::TimeZone[-28800].parse('2014/12/18 19:00')),
|
|
16
16
|
double(published_at: ActiveSupport::TimeZone[-21600].parse('2014/12/18 20:00')),
|
|
17
17
|
double(published_at: ActiveSupport::TimeZone[-21600].parse('2014/12/17 20:00')),
|
|
18
18
|
) }
|
|
@@ -21,7 +21,7 @@ describe 'Time fields' do
|
|
|
21
21
|
let(:range) { (time - 1.minute)..(time + 1.minute) }
|
|
22
22
|
|
|
23
23
|
specify { expect(PostsIndex.total).to eq(3) }
|
|
24
|
-
specify { expect(PostsIndex.filter { published_at == o{range} }.count).to eq(
|
|
25
|
-
specify { expect(PostsIndex.filter { published_at == o{range.min.utc..range.max.utc} }.count).to eq(2) }
|
|
26
|
-
specify { expect(PostsIndex.filter { published_at == o{[range.min
|
|
24
|
+
specify { expect(PostsIndex.filter { published_at == o{range} }.count).to eq(1) }
|
|
25
|
+
specify { expect(PostsIndex.filter { published_at == o{range.min.utc..(range.max + 1.hour).utc} }.count).to eq(2) }
|
|
26
|
+
specify { expect(PostsIndex.filter { published_at == o{[range.min..range.max]} }.count).to eq(1) }
|
|
27
27
|
end
|
|
@@ -15,8 +15,8 @@ describe Chewy::Index::Actions do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
describe '.create' do
|
|
18
|
-
specify { expect(DummiesIndex.create[
|
|
19
|
-
specify { expect(DummiesIndex.create('2013')[
|
|
18
|
+
specify { expect(DummiesIndex.create['acknowledged']).to eq(true) }
|
|
19
|
+
specify { expect(DummiesIndex.create('2013')['acknowledged']).to eq(true) }
|
|
20
20
|
|
|
21
21
|
context do
|
|
22
22
|
before { DummiesIndex.create }
|
|
@@ -31,7 +31,7 @@ describe Chewy::Index::Actions do
|
|
|
31
31
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
|
32
32
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
|
33
33
|
specify { expect(DummiesIndex.create('2013')).to eq(false) }
|
|
34
|
-
specify { expect(DummiesIndex.create('2014')[
|
|
34
|
+
specify { expect(DummiesIndex.create('2014')['acknowledged']).to eq(true) }
|
|
35
35
|
|
|
36
36
|
context do
|
|
37
37
|
before { DummiesIndex.create '2014' }
|
|
@@ -49,12 +49,19 @@ describe Chewy::Index::Actions do
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
describe '.create!' do
|
|
52
|
-
specify { expect(DummiesIndex.create![
|
|
53
|
-
specify { expect(DummiesIndex.create!('2013')[
|
|
52
|
+
specify { expect(DummiesIndex.create!['acknowledged']).to eq(true) }
|
|
53
|
+
specify { expect(DummiesIndex.create!('2013')['acknowledged']).to eq(true) }
|
|
54
54
|
|
|
55
55
|
context do
|
|
56
56
|
before { DummiesIndex.create }
|
|
57
|
-
specify
|
|
57
|
+
specify do
|
|
58
|
+
skip_on_version_gte('2.0', 'format of exception changed in 2.x')
|
|
59
|
+
expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/\[\[dummies\] already exists\]/)
|
|
60
|
+
end
|
|
61
|
+
specify do
|
|
62
|
+
skip_on_version_lt('2.0', 'format of exception was changed')
|
|
63
|
+
expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies/)
|
|
64
|
+
end
|
|
58
65
|
specify { expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/) }
|
|
59
66
|
end
|
|
60
67
|
|
|
@@ -64,8 +71,15 @@ describe Chewy::Index::Actions do
|
|
|
64
71
|
specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
|
|
65
72
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
|
66
73
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
|
67
|
-
specify
|
|
68
|
-
|
|
74
|
+
specify do
|
|
75
|
+
skip_on_version_gte('2.0', 'format of exception changed in 2.x')
|
|
76
|
+
expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/\[\[dummies_2013\] already exists\]/)
|
|
77
|
+
end
|
|
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/)
|
|
81
|
+
end
|
|
82
|
+
specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
|
|
69
83
|
|
|
70
84
|
context do
|
|
71
85
|
before { DummiesIndex.create! '2014' }
|
|
@@ -88,7 +102,7 @@ describe Chewy::Index::Actions do
|
|
|
88
102
|
|
|
89
103
|
context do
|
|
90
104
|
before { DummiesIndex.create }
|
|
91
|
-
specify { expect(DummiesIndex.delete[
|
|
105
|
+
specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
|
|
92
106
|
|
|
93
107
|
context do
|
|
94
108
|
before { DummiesIndex.delete }
|
|
@@ -98,7 +112,7 @@ describe Chewy::Index::Actions do
|
|
|
98
112
|
|
|
99
113
|
context do
|
|
100
114
|
before { DummiesIndex.create '2013' }
|
|
101
|
-
specify { expect(DummiesIndex.delete('2013')[
|
|
115
|
+
specify { expect(DummiesIndex.delete('2013')['acknowledged']).to eq(true) }
|
|
102
116
|
|
|
103
117
|
context do
|
|
104
118
|
before { DummiesIndex.delete('2013') }
|
|
@@ -108,7 +122,7 @@ describe Chewy::Index::Actions do
|
|
|
108
122
|
|
|
109
123
|
context do
|
|
110
124
|
before { DummiesIndex.create '2014' }
|
|
111
|
-
specify { expect(DummiesIndex.delete[
|
|
125
|
+
specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
|
|
112
126
|
|
|
113
127
|
context do
|
|
114
128
|
before { DummiesIndex.delete }
|
|
@@ -133,7 +147,7 @@ describe Chewy::Index::Actions do
|
|
|
133
147
|
|
|
134
148
|
context do
|
|
135
149
|
before { DummiesIndex.create }
|
|
136
|
-
specify { expect(DummiesIndex.delete![
|
|
150
|
+
specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
|
|
137
151
|
|
|
138
152
|
context do
|
|
139
153
|
before { DummiesIndex.delete! }
|
|
@@ -143,7 +157,7 @@ describe Chewy::Index::Actions do
|
|
|
143
157
|
|
|
144
158
|
context do
|
|
145
159
|
before { DummiesIndex.create '2013' }
|
|
146
|
-
specify { expect(DummiesIndex.delete!('2013')[
|
|
160
|
+
specify { expect(DummiesIndex.delete!('2013')['acknowledged']).to eq(true) }
|
|
147
161
|
|
|
148
162
|
context do
|
|
149
163
|
before { DummiesIndex.delete!('2013') }
|
|
@@ -153,7 +167,7 @@ describe Chewy::Index::Actions do
|
|
|
153
167
|
|
|
154
168
|
context do
|
|
155
169
|
before { DummiesIndex.create '2014' }
|
|
156
|
-
specify { expect(DummiesIndex.delete![
|
|
170
|
+
specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
|
|
157
171
|
|
|
158
172
|
context do
|
|
159
173
|
before { DummiesIndex.delete! }
|
|
@@ -173,8 +187,8 @@ describe Chewy::Index::Actions do
|
|
|
173
187
|
end
|
|
174
188
|
|
|
175
189
|
describe '.purge' do
|
|
176
|
-
specify { expect(DummiesIndex.purge[
|
|
177
|
-
specify { expect(DummiesIndex.purge('2013')[
|
|
190
|
+
specify { expect(DummiesIndex.purge['acknowledged']).to eq(true) }
|
|
191
|
+
specify { expect(DummiesIndex.purge('2013')['acknowledged']).to eq(true) }
|
|
178
192
|
|
|
179
193
|
context do
|
|
180
194
|
before { DummiesIndex.purge }
|
|
@@ -220,8 +234,8 @@ describe Chewy::Index::Actions do
|
|
|
220
234
|
end
|
|
221
235
|
|
|
222
236
|
describe '.purge!' do
|
|
223
|
-
specify { expect(DummiesIndex.purge![
|
|
224
|
-
specify { expect(DummiesIndex.purge!('2013')[
|
|
237
|
+
specify { expect(DummiesIndex.purge!['acknowledged']).to eq(true) }
|
|
238
|
+
specify { expect(DummiesIndex.purge!('2013')['acknowledged']).to eq(true) }
|
|
225
239
|
|
|
226
240
|
context do
|
|
227
241
|
before { DummiesIndex.purge! }
|