chewy 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +20 -60
- data/Appraisals +15 -40
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -0
- data/Guardfile +5 -5
- data/README.md +155 -6
- data/Rakefile +11 -1
- data/chewy.gemspec +5 -7
- data/gemfiles/rails.3.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/{rails.4.2.mongoid.4.0.0.gemfile → rails.4.2.mongoid.4.0.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.will_paginate.gemfile → rails.4.2.mongoid.4.0.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.gemfile → rails.4.2.mongoid.5.1.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.will_paginate.gemfile → rails.4.2.mongoid.5.1.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.5.0.activerecord.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.will_paginate.gemfile → rails.5.0.activerecord.will_paginate.gemfile} +4 -2
- data/gemfiles/{sequel.4.31.gemfile → sequel.4.38.gemfile} +3 -2
- data/lib/chewy.rb +24 -16
- data/lib/chewy/backports/deep_dup.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -0
- data/lib/chewy/config.rb +13 -7
- data/lib/chewy/errors.rb +4 -4
- data/lib/chewy/fields/base.rb +19 -14
- data/lib/chewy/fields/root.rb +11 -9
- data/lib/chewy/index.rb +38 -25
- data/lib/chewy/index/actions.rb +17 -17
- data/lib/chewy/index/settings.rb +3 -4
- data/lib/chewy/journal.rb +107 -0
- data/lib/chewy/journal/apply.rb +31 -0
- data/lib/chewy/journal/clean.rb +24 -0
- data/lib/chewy/journal/entry.rb +83 -0
- data/lib/chewy/journal/query.rb +87 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/minitest/helpers.rb +77 -0
- data/lib/chewy/minitest/search_index_receiver.rb +80 -0
- data/lib/chewy/query.rb +116 -60
- data/lib/chewy/query/compose.rb +5 -6
- data/lib/chewy/query/criteria.rb +26 -16
- data/lib/chewy/query/filters.rb +9 -9
- data/lib/chewy/query/loading.rb +2 -2
- data/lib/chewy/query/nodes/and.rb +3 -3
- data/lib/chewy/query/nodes/base.rb +1 -1
- data/lib/chewy/query/nodes/bool.rb +6 -4
- data/lib/chewy/query/nodes/equal.rb +6 -6
- data/lib/chewy/query/nodes/exists.rb +2 -2
- data/lib/chewy/query/nodes/expr.rb +2 -2
- data/lib/chewy/query/nodes/field.rb +35 -31
- data/lib/chewy/query/nodes/has_child.rb +1 -0
- data/lib/chewy/query/nodes/has_parent.rb +1 -0
- data/lib/chewy/query/nodes/has_relation.rb +11 -13
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +2 -2
- data/lib/chewy/query/nodes/not.rb +3 -3
- data/lib/chewy/query/nodes/or.rb +3 -3
- data/lib/chewy/query/nodes/prefix.rb +4 -3
- data/lib/chewy/query/nodes/query.rb +3 -3
- data/lib/chewy/query/nodes/range.rb +11 -11
- data/lib/chewy/query/nodes/raw.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +15 -11
- data/lib/chewy/query/nodes/script.rb +6 -6
- data/lib/chewy/query/pagination/will_paginate.rb +2 -2
- data/lib/chewy/railtie.rb +3 -3
- data/lib/chewy/rake_helper.rb +51 -30
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec.rb +1 -1
- data/lib/chewy/rspec/update_index.rb +46 -47
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/search.rb +7 -5
- data/lib/chewy/strategy.rb +10 -8
- data/lib/chewy/strategy/atomic.rb +2 -2
- data/lib/chewy/strategy/base.rb +4 -4
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/sidekiq.rb +2 -0
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/type.rb +51 -45
- data/lib/chewy/type/adapter/active_record.rb +23 -12
- data/lib/chewy/type/adapter/base.rb +4 -4
- data/lib/chewy/type/adapter/mongoid.rb +6 -6
- data/lib/chewy/type/adapter/object.rb +15 -12
- data/lib/chewy/type/adapter/orm.rb +24 -15
- data/lib/chewy/type/adapter/sequel.rb +11 -7
- data/lib/chewy/type/crutch.rb +4 -3
- data/lib/chewy/type/import.rb +51 -32
- data/lib/chewy/type/mapping.rb +17 -17
- data/lib/chewy/type/observe.rb +9 -7
- data/lib/chewy/type/witchcraft.rb +62 -23
- data/lib/chewy/type/wrapper.rb +20 -14
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +28 -23
- data/spec/chewy/config_spec.rb +33 -12
- data/spec/chewy/fields/base_spec.rb +143 -154
- data/spec/chewy/fields/root_spec.rb +22 -20
- data/spec/chewy/fields/time_fields_spec.rb +11 -9
- data/spec/chewy/index/actions_spec.rb +27 -4
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +72 -50
- data/spec/chewy/index_spec.rb +95 -43
- data/spec/chewy/journal/apply_spec.rb +120 -0
- data/spec/chewy/journal/entry_spec.rb +237 -0
- data/spec/chewy/journal_spec.rb +173 -0
- data/spec/chewy/minitest/helpers_spec.rb +90 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
- data/spec/chewy/query/criteria_spec.rb +504 -237
- data/spec/chewy/query/filters_spec.rb +94 -66
- data/spec/chewy/query/loading_spec.rb +76 -40
- data/spec/chewy/query/nodes/and_spec.rb +3 -7
- data/spec/chewy/query/nodes/bool_spec.rb +5 -13
- data/spec/chewy/query/nodes/equal_spec.rb +20 -20
- data/spec/chewy/query/nodes/exists_spec.rb +7 -7
- data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
- data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
- data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
- data/spec/chewy/query/nodes/missing_spec.rb +6 -5
- data/spec/chewy/query/nodes/not_spec.rb +3 -7
- data/spec/chewy/query/nodes/or_spec.rb +3 -7
- data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
- data/spec/chewy/query/nodes/query_spec.rb +3 -3
- data/spec/chewy/query/nodes/range_spec.rb +19 -19
- data/spec/chewy/query/nodes/raw_spec.rb +2 -2
- data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
- data/spec/chewy/query/nodes/script_spec.rb +5 -5
- data/spec/chewy/query/pagination/kaminari_spec.rb +2 -2
- data/spec/chewy/query/pagination/will_paginage_spec.rb +6 -7
- data/spec/chewy/query/pagination_spec.rb +2 -3
- data/spec/chewy/query_spec.rb +208 -145
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/update_index_spec.rb +180 -111
- data/spec/chewy/search_spec.rb +8 -8
- data/spec/chewy/strategy/active_job_spec.rb +2 -2
- data/spec/chewy/strategy/atomic_spec.rb +4 -1
- data/spec/chewy/strategy/resque_spec.rb +2 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +2 -2
- data/spec/chewy/type/actions_spec.rb +1 -1
- data/spec/chewy/type/adapter/active_record_spec.rb +255 -149
- data/spec/chewy/type/adapter/mongoid_spec.rb +169 -108
- data/spec/chewy/type/adapter/object_spec.rb +56 -40
- data/spec/chewy/type/adapter/sequel_spec.rb +248 -163
- data/spec/chewy/type/import_spec.rb +78 -47
- data/spec/chewy/type/mapping_spec.rb +6 -6
- data/spec/chewy/type/observe_spec.rb +20 -14
- data/spec/chewy/type/witchcraft_spec.rb +89 -43
- data/spec/chewy/type_spec.rb +4 -3
- data/spec/chewy_spec.rb +10 -8
- data/spec/spec_helper.rb +3 -0
- data/spec/support/active_record.rb +1 -1
- data/spec/support/class_helpers.rb +10 -11
- data/spec/support/mongoid.rb +2 -2
- data/spec/support/sequel.rb +1 -1
- metadata +65 -35
- 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.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.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/spec/chewy/config_spec.rb
CHANGED
@@ -12,28 +12,49 @@ describe Chewy::Config do
|
|
12
12
|
its(:root_strategy) { should == :base }
|
13
13
|
its(:request_strategy) { should == :atomic }
|
14
14
|
its(:use_after_commit_callbacks) { should == true }
|
15
|
+
its(:indices_path) { should == 'app/chewy' }
|
15
16
|
|
16
17
|
describe '#transport_logger=' do
|
17
18
|
let(:logger) { Logger.new('/dev/null') }
|
18
19
|
after { subject.transport_logger = nil }
|
19
20
|
|
20
|
-
specify
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
specify
|
25
|
-
|
21
|
+
specify do
|
22
|
+
expect { subject.transport_logger = logger }
|
23
|
+
.to change { Chewy.client.transport.logger }.to(logger)
|
24
|
+
end
|
25
|
+
specify do
|
26
|
+
expect { subject.transport_logger = logger }
|
27
|
+
.to change { subject.transport_logger }.to(logger)
|
28
|
+
end
|
29
|
+
specify do
|
30
|
+
expect { subject.transport_logger = logger }
|
31
|
+
.to change { subject.configuration[:logger] }.from(nil).to(logger)
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
describe '#transport_tracer=' do
|
29
36
|
let(:tracer) { Logger.new('/dev/null') }
|
30
37
|
after { subject.transport_tracer = nil }
|
31
38
|
|
32
|
-
specify
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
specify
|
37
|
-
|
39
|
+
specify do
|
40
|
+
expect { subject.transport_tracer = tracer }
|
41
|
+
.to change { Chewy.client.transport.tracer }.to(tracer)
|
42
|
+
end
|
43
|
+
specify do
|
44
|
+
expect { subject.transport_tracer = tracer }
|
45
|
+
.to change { subject.transport_tracer }.to(tracer)
|
46
|
+
end
|
47
|
+
specify do
|
48
|
+
expect { subject.transport_tracer = tracer }
|
49
|
+
.to change { subject.configuration[:tracer] }.from(nil).to(tracer)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#configuration' do
|
54
|
+
before { subject.settings = { indices_path: 'app/custom_indices_path' } }
|
55
|
+
|
56
|
+
specify do
|
57
|
+
expect(subject.configuration).to include(indices_path: 'app/custom_indices_path')
|
58
|
+
end
|
38
59
|
end
|
39
60
|
end
|
@@ -5,37 +5,40 @@ describe Chewy::Fields::Base do
|
|
5
5
|
specify { expect(described_class.new('name', type: 'integer').options[:type]).to eq('integer') }
|
6
6
|
|
7
7
|
describe '#compose' do
|
8
|
-
let(:field) { described_class.new(:name, value: ->(o){ o.value }) }
|
8
|
+
let(:field) { described_class.new(:name, value: ->(o) { o.value }) }
|
9
9
|
|
10
|
-
specify { expect(field.compose(double(value: 'hello'))).to eq(
|
11
|
-
specify { expect(field.compose(double(value:
|
12
|
-
|
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}) }
|
10
|
+
specify { expect(field.compose(double(value: 'hello'))).to eq(name: 'hello') }
|
11
|
+
specify { expect(field.compose(double(value: %w(hello world)))).to eq(name: %w(hello world)) }
|
17
12
|
|
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) }
|
18
17
|
|
19
18
|
context 'nested fields' do
|
20
19
|
before do
|
21
|
-
field.children.push(described_class.new(:subname1, value: ->(o){ o.subvalue1 }))
|
22
|
-
field.children.push(described_class.new(:subname2, value: ->{ subvalue2 }))
|
20
|
+
field.children.push(described_class.new(:subname1, value: ->(o) { o.subvalue1 }))
|
21
|
+
field.children.push(described_class.new(:subname2, value: -> { subvalue2 }))
|
23
22
|
field.children.push(described_class.new(:subname3))
|
24
23
|
end
|
25
24
|
|
26
|
-
specify
|
27
|
-
.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
specify do
|
26
|
+
expect(field.compose(double(value: double(subvalue1: 'hello', subvalue2: 'value', subname3: 'world'))))
|
27
|
+
.to eq(name: { subname1: 'hello', subname2: 'value', subname3: 'world' })
|
28
|
+
end
|
29
|
+
specify do
|
30
|
+
expect(field.compose(double(value: [
|
31
|
+
double(subvalue1: 'hello1', subvalue2: 'value1', subname3: 'world1'),
|
32
|
+
double(subvalue1: 'hello2', subvalue2: 'value2', subname3: 'world2')
|
33
|
+
]))).to eq(name: [
|
34
|
+
{ subname1: 'hello1', subname2: 'value1', subname3: 'world1' },
|
35
|
+
{ subname1: 'hello2', subname2: 'value2', subname3: 'world2' }
|
36
|
+
])
|
37
|
+
end
|
35
38
|
end
|
36
39
|
|
37
40
|
context 'parent objects' do
|
38
|
-
let!(:country) { described_class.new(:name, value: ->(country){ country.cities }) }
|
41
|
+
let!(:country) { described_class.new(:name, value: ->(country) { country.cities }) }
|
39
42
|
let!(:city) { described_class.new(:name, value: ->(city, country) { city.districts.map { |district| [district, country.name] } }) }
|
40
43
|
let!(:district) { described_class.new(:name, value: ->(district, city, country) { [district, city.name, country.name] }) }
|
41
44
|
|
@@ -44,14 +47,16 @@ describe Chewy::Fields::Base do
|
|
44
47
|
city.children.push(district)
|
45
48
|
end
|
46
49
|
|
47
|
-
specify
|
48
|
-
double(name: '
|
49
|
-
|
50
|
-
|
51
|
-
{
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
specify do
|
51
|
+
expect(country.compose(double(name: 'Thailand', cities: [
|
52
|
+
double(name: 'Bangkok', districts: %w(First Second))
|
53
|
+
]))).to eq(name: [
|
54
|
+
{ name: [
|
55
|
+
{ name: [%w(First Thailand), 'Bangkok', 'Thailand'] },
|
56
|
+
{ name: [%w(Second Thailand), 'Bangkok', 'Thailand'] }
|
57
|
+
] }
|
58
|
+
])
|
59
|
+
end
|
55
60
|
end
|
56
61
|
|
57
62
|
context 'implicit values' do
|
@@ -61,46 +66,50 @@ describe Chewy::Fields::Base do
|
|
61
66
|
field.children.push(described_class.new(:untouched))
|
62
67
|
end
|
63
68
|
|
64
|
-
specify { expect(field.compose(double(name: 'Alex'))).to eq(
|
69
|
+
specify { expect(field.compose(double(name: 'Alex'))).to eq(name: 'Alex') }
|
65
70
|
end
|
66
71
|
|
67
72
|
context 'hash values' do
|
68
73
|
let(:field) { described_class.new(:name, type: 'object') }
|
69
|
-
let(:object) { double(name: { key1: 'value1', key2: 'value2'}) }
|
74
|
+
let(:object) { double(name: { key1: 'value1', key2: 'value2' }) }
|
70
75
|
|
71
76
|
before do
|
72
|
-
field.children.push(described_class.new(:key1, value: ->(h){ h[:key1] }))
|
73
|
-
field.children.push(described_class.new(:key2, value: ->(h){ h[:key2] }))
|
77
|
+
field.children.push(described_class.new(:key1, value: ->(h) { h[:key1] }))
|
78
|
+
field.children.push(described_class.new(:key2, value: ->(h) { h[:key2] }))
|
74
79
|
end
|
75
80
|
|
76
|
-
specify{ expect(field.compose(object)).to eq(
|
81
|
+
specify { expect(field.compose(object)).to eq(name: { key1: 'value1', key2: 'value2' }) }
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
80
85
|
describe '#mappings_hash' do
|
81
86
|
let(:field) { described_class.new(:name, type: :object) }
|
82
|
-
let(:fields1) { 2
|
83
|
-
let(:fields2) { 2
|
87
|
+
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}", type: "string#{i + 1}") } }
|
88
|
+
let(:fields2) { Array.new(2) { |i| described_class.new("name#{i + 3}", type: "string#{i + 3}") } }
|
84
89
|
before do
|
85
90
|
fields1.each { |m| field.children.push(m) }
|
86
91
|
fields2.each { |m| fields1[0].children.push(m) }
|
87
92
|
end
|
88
93
|
|
89
|
-
specify
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
specify do
|
95
|
+
expect(field.mappings_hash).to eq(name: { type: :object, properties: {
|
96
|
+
name1: { type: 'string1', fields: {
|
97
|
+
name3: { type: 'string3' }, name4: { type: 'string4' }
|
98
|
+
} }, name2: { type: 'string2' }
|
99
|
+
} })
|
100
|
+
end
|
94
101
|
|
95
102
|
context do
|
96
103
|
let(:field) { described_class.new(:name, type: :string) }
|
97
|
-
let(:fields1) { 2
|
104
|
+
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}") } }
|
98
105
|
|
99
|
-
specify
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
106
|
+
specify do
|
107
|
+
expect(field.mappings_hash).to eq(name: { type: :string, fields: {
|
108
|
+
name1: { type: 'object', properties: {
|
109
|
+
name3: { type: 'string3' }, name4: { type: 'string4' }
|
110
|
+
} }, name2: { type: 'string' }
|
111
|
+
} })
|
112
|
+
end
|
104
113
|
end
|
105
114
|
end
|
106
115
|
|
@@ -122,48 +131,48 @@ describe Chewy::Fields::Base do
|
|
122
131
|
end
|
123
132
|
|
124
133
|
specify do
|
125
|
-
expect(EventsIndex::Event.mappings_hash).to eq(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
135
|
+
properties: {
|
136
|
+
id: { type: 'string' },
|
137
|
+
category: {
|
138
|
+
type: 'object',
|
139
|
+
properties: {
|
140
|
+
id: { type: 'string' },
|
141
|
+
licenses: {
|
142
|
+
type: 'object',
|
143
|
+
properties: {
|
144
|
+
id: { type: 'string' },
|
145
|
+
name: { type: 'string' }
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
})
|
137
152
|
end
|
138
153
|
|
139
154
|
specify do
|
140
155
|
expect(EventsIndex::Event.root_object.compose(
|
141
|
-
|
142
|
-
)).to eq({
|
143
|
-
event: { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}}}
|
144
|
-
})
|
156
|
+
id: 1, category: { id: 2, licenses: { id: 3, name: 'Name' } }
|
157
|
+
)).to eq('event' => { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => { 'id' => 3, 'name' => 'Name' } } })
|
145
158
|
end
|
146
159
|
|
147
160
|
specify do
|
148
161
|
expect(EventsIndex::Event.root_object.compose(id: 1, category: [
|
149
162
|
{ id: 2, 'licenses' => { id: 3, name: 'Name1' } },
|
150
|
-
{ id: 4, licenses: nil}
|
151
|
-
])).to eq({
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
] }
|
156
|
-
})
|
163
|
+
{ id: 4, licenses: nil }
|
164
|
+
])).to eq('event' => { 'id' => 1, 'category' => [
|
165
|
+
{ 'id' => 2, 'licenses' => { 'id' => 3, 'name' => 'Name1' } },
|
166
|
+
{ 'id' => 4, 'licenses' => nil.as_json }
|
167
|
+
] })
|
157
168
|
end
|
158
169
|
|
159
170
|
specify do
|
160
171
|
expect(EventsIndex::Event.root_object.compose('id' => 1, category: { id: 2, licenses: [
|
161
172
|
{ id: 3, name: 'Name1' }, { id: 4, name: 'Name2' }
|
162
|
-
] })).to eq({
|
163
|
-
|
164
|
-
|
165
|
-
] } }
|
166
|
-
})
|
173
|
+
] })).to eq('event' => { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => [
|
174
|
+
{ 'id' => 3, 'name' => 'Name1' }, { 'id' => 4, 'name' => 'Name2' }
|
175
|
+
] } })
|
167
176
|
end
|
168
177
|
|
169
178
|
specify do
|
@@ -172,44 +181,36 @@ describe Chewy::Fields::Base do
|
|
172
181
|
{ id: 3, 'name' => 'Name1' }, { id: 4, name: 'Name2' }
|
173
182
|
] },
|
174
183
|
{ id: 5, licenses: [] }
|
175
|
-
])).to eq({
|
176
|
-
|
177
|
-
{ 'id' =>
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
] }
|
182
|
-
})
|
184
|
+
])).to eq('event' => { 'id' => 1, 'category' => [
|
185
|
+
{ 'id' => 2, 'licenses' => [
|
186
|
+
{ 'id' => 3, 'name' => 'Name1' }, { 'id' => 4, 'name' => 'Name2' }
|
187
|
+
] },
|
188
|
+
{ 'id' => 5, 'licenses' => [] }
|
189
|
+
] })
|
183
190
|
end
|
184
191
|
|
185
192
|
specify do
|
186
193
|
expect(EventsIndex::Event.root_object.compose(
|
187
|
-
|
188
|
-
)).to eq({
|
189
|
-
event: { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}}}
|
190
|
-
})
|
194
|
+
double(id: 1, category: double(id: 2, licenses: double(id: 3, name: 'Name')))
|
195
|
+
)).to eq('event' => { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => { 'id' => 3, 'name' => 'Name' } } })
|
191
196
|
end
|
192
197
|
|
193
198
|
specify do
|
194
199
|
expect(EventsIndex::Event.root_object.compose(double(id: 1, category: [
|
195
200
|
double(id: 2, licenses: double(id: 3, name: 'Name1')),
|
196
201
|
double(id: 4, licenses: nil)
|
197
|
-
]))).to eq({
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
] }
|
202
|
-
})
|
202
|
+
]))).to eq('event' => { 'id' => 1, 'category' => [
|
203
|
+
{ 'id' => 2, 'licenses' => { 'id' => 3, 'name' => 'Name1' } },
|
204
|
+
{ 'id' => 4, 'licenses' => nil.as_json }
|
205
|
+
] })
|
203
206
|
end
|
204
207
|
|
205
208
|
specify do
|
206
209
|
expect(EventsIndex::Event.root_object.compose(double(id: 1, category: double(id: 2, licenses: [
|
207
210
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
208
|
-
])))).to eq({
|
209
|
-
|
210
|
-
|
211
|
-
] } }
|
212
|
-
})
|
211
|
+
])))).to eq('event' => { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => [
|
212
|
+
{ 'id' => 3, 'name' => 'Name1' }, { 'id' => 4, 'name' => 'Name2' }
|
213
|
+
] } })
|
213
214
|
end
|
214
215
|
|
215
216
|
specify do
|
@@ -218,14 +219,12 @@ describe Chewy::Fields::Base do
|
|
218
219
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
219
220
|
]),
|
220
221
|
double(id: 5, licenses: [])
|
221
|
-
]))).to eq({
|
222
|
-
|
223
|
-
{ 'id' =>
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
] }
|
228
|
-
})
|
222
|
+
]))).to eq('event' => { 'id' => 1, 'category' => [
|
223
|
+
{ 'id' => 2, 'licenses' => [
|
224
|
+
{ 'id' => 3, 'name' => 'Name1' }, { 'id' => 4, 'name' => 'Name2' }
|
225
|
+
] },
|
226
|
+
{ 'id' => 5, 'licenses' => [] }
|
227
|
+
] })
|
229
228
|
end
|
230
229
|
end
|
231
230
|
|
@@ -234,9 +233,9 @@ describe Chewy::Fields::Base do
|
|
234
233
|
stub_index(:events) do
|
235
234
|
define_type :event do
|
236
235
|
field :id
|
237
|
-
field :category, value: ->{ categories } do
|
236
|
+
field :category, value: -> { categories } do
|
238
237
|
field :id
|
239
|
-
field :licenses, value: ->{ license } do
|
238
|
+
field :licenses, value: -> { license } do
|
240
239
|
field :id
|
241
240
|
field :name
|
242
241
|
end
|
@@ -247,10 +246,8 @@ describe Chewy::Fields::Base do
|
|
247
246
|
|
248
247
|
specify do
|
249
248
|
expect(EventsIndex::Event.root_object.compose(
|
250
|
-
|
251
|
-
)).to eq({
|
252
|
-
event: { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}}}
|
253
|
-
})
|
249
|
+
double(id: 1, categories: double(id: 2, license: double(id: 3, name: 'Name')))
|
250
|
+
)).to eq('event' => { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => { 'id' => 3, 'name' => 'Name' } } })
|
254
251
|
end
|
255
252
|
end
|
256
253
|
|
@@ -268,48 +265,44 @@ describe Chewy::Fields::Base do
|
|
268
265
|
end
|
269
266
|
|
270
267
|
specify do
|
271
|
-
expect(EventsIndex::Event.mappings_hash).to eq(
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
268
|
+
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
269
|
+
properties: {
|
270
|
+
id: { type: 'string' },
|
271
|
+
name: {
|
272
|
+
type: 'string',
|
273
|
+
fields: {
|
274
|
+
raw: { analyzer: 'my_own', type: 'string' }
|
275
|
+
}
|
276
|
+
},
|
277
|
+
category: { type: 'object' }
|
278
|
+
}
|
279
|
+
})
|
283
280
|
end
|
284
281
|
|
285
282
|
specify do
|
286
283
|
expect(EventsIndex::Event.root_object.compose(
|
287
|
-
|
288
|
-
)).to eq({
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
}
|
294
|
-
})
|
284
|
+
double(id: 1, name: 'Jonny', category: double(id: 2, as_json: { 'name' => 'Borogoves' }))
|
285
|
+
)).to eq('event' => {
|
286
|
+
'id' => 1,
|
287
|
+
'name' => 'Jonny',
|
288
|
+
'category' => { 'name' => 'Borogoves' }
|
289
|
+
})
|
295
290
|
end
|
296
291
|
|
297
292
|
specify do
|
298
293
|
expect(EventsIndex::Event.root_object.compose(
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
)).to eq({
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
}
|
312
|
-
})
|
294
|
+
double(id: 1, name: 'Jonny', category: [
|
295
|
+
double(id: 2, as_json: { 'name' => 'Borogoves1' }),
|
296
|
+
double(id: 3, as_json: { 'name' => 'Borogoves2' })
|
297
|
+
])
|
298
|
+
)).to eq('event' => {
|
299
|
+
'id' => 1,
|
300
|
+
'name' => 'Jonny',
|
301
|
+
'category' => [
|
302
|
+
{ 'name' => 'Borogoves1' },
|
303
|
+
{ 'name' => 'Borogoves2' }
|
304
|
+
]
|
305
|
+
})
|
313
306
|
end
|
314
307
|
end
|
315
308
|
|
@@ -358,11 +351,9 @@ describe Chewy::Fields::Base do
|
|
358
351
|
end
|
359
352
|
|
360
353
|
specify do
|
361
|
-
expect(CountriesIndex::Country.root_object.compose(country_with_cities)).to eq({
|
362
|
-
|
363
|
-
|
364
|
-
] }
|
365
|
-
})
|
354
|
+
expect(CountriesIndex::Country.root_object.compose(country_with_cities)).to eq('country' => { 'id' => 1, 'cities' => [
|
355
|
+
{ 'id' => 1, 'name' => 'City1' }, { 'id' => 2, 'name' => 'City2' }
|
356
|
+
] })
|
366
357
|
end
|
367
358
|
|
368
359
|
context 'nested object' do
|
@@ -380,10 +371,8 @@ describe Chewy::Fields::Base do
|
|
380
371
|
|
381
372
|
specify do
|
382
373
|
expect(CitiesIndex::City.root_object.compose(
|
383
|
-
|
384
|
-
)).to eq({
|
385
|
-
city: { 'id' => 1, 'country' => { 'id' => 1, 'name' => 'Country' } }
|
386
|
-
})
|
374
|
+
City.create!(id: 1, country: Country.create!(id: 1, name: 'Country'))
|
375
|
+
)).to eq('city' => { 'id' => 1, 'country' => { 'id' => 1, 'name' => 'Country' } })
|
387
376
|
end
|
388
377
|
end
|
389
378
|
end
|