chewy 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +34 -0
  3. data/.rubocop_todo.yml +44 -0
  4. data/.travis.yml +20 -60
  5. data/Appraisals +15 -40
  6. data/CHANGELOG.md +42 -0
  7. data/Gemfile +1 -0
  8. data/Guardfile +5 -5
  9. data/README.md +155 -6
  10. data/Rakefile +11 -1
  11. data/chewy.gemspec +5 -7
  12. data/gemfiles/rails.3.2.activerecord.gemfile +1 -0
  13. data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -0
  14. data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +1 -0
  15. data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
  16. data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
  17. data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
  18. data/gemfiles/{rails.4.2.mongoid.4.0.0.gemfile → rails.4.2.mongoid.4.0.gemfile} +2 -1
  19. data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile} +2 -1
  20. data/gemfiles/{rails.4.2.mongoid.4.0.0.will_paginate.gemfile → rails.4.2.mongoid.4.0.will_paginate.gemfile} +2 -1
  21. data/gemfiles/{rails.4.2.mongoid.5.1.0.gemfile → rails.4.2.mongoid.5.1.gemfile} +2 -1
  22. data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile} +2 -1
  23. data/gemfiles/{rails.4.2.mongoid.5.1.0.will_paginate.gemfile → rails.4.2.mongoid.5.1.will_paginate.gemfile} +2 -1
  24. data/gemfiles/{rails.4.0.activerecord.gemfile → rails.5.0.activerecord.gemfile} +4 -2
  25. data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile} +4 -2
  26. data/gemfiles/{rails.4.0.mongoid.4.0.0.will_paginate.gemfile → rails.5.0.activerecord.will_paginate.gemfile} +4 -2
  27. data/gemfiles/{sequel.4.31.gemfile → sequel.4.38.gemfile} +3 -2
  28. data/lib/chewy.rb +24 -16
  29. data/lib/chewy/backports/deep_dup.rb +1 -1
  30. data/lib/chewy/backports/duplicable.rb +1 -0
  31. data/lib/chewy/config.rb +13 -7
  32. data/lib/chewy/errors.rb +4 -4
  33. data/lib/chewy/fields/base.rb +19 -14
  34. data/lib/chewy/fields/root.rb +11 -9
  35. data/lib/chewy/index.rb +38 -25
  36. data/lib/chewy/index/actions.rb +17 -17
  37. data/lib/chewy/index/settings.rb +3 -4
  38. data/lib/chewy/journal.rb +107 -0
  39. data/lib/chewy/journal/apply.rb +31 -0
  40. data/lib/chewy/journal/clean.rb +24 -0
  41. data/lib/chewy/journal/entry.rb +83 -0
  42. data/lib/chewy/journal/query.rb +87 -0
  43. data/lib/chewy/log_subscriber.rb +8 -8
  44. data/lib/chewy/minitest.rb +1 -0
  45. data/lib/chewy/minitest/helpers.rb +77 -0
  46. data/lib/chewy/minitest/search_index_receiver.rb +80 -0
  47. data/lib/chewy/query.rb +116 -60
  48. data/lib/chewy/query/compose.rb +5 -6
  49. data/lib/chewy/query/criteria.rb +26 -16
  50. data/lib/chewy/query/filters.rb +9 -9
  51. data/lib/chewy/query/loading.rb +2 -2
  52. data/lib/chewy/query/nodes/and.rb +3 -3
  53. data/lib/chewy/query/nodes/base.rb +1 -1
  54. data/lib/chewy/query/nodes/bool.rb +6 -4
  55. data/lib/chewy/query/nodes/equal.rb +6 -6
  56. data/lib/chewy/query/nodes/exists.rb +2 -2
  57. data/lib/chewy/query/nodes/expr.rb +2 -2
  58. data/lib/chewy/query/nodes/field.rb +35 -31
  59. data/lib/chewy/query/nodes/has_child.rb +1 -0
  60. data/lib/chewy/query/nodes/has_parent.rb +1 -0
  61. data/lib/chewy/query/nodes/has_relation.rb +11 -13
  62. data/lib/chewy/query/nodes/match_all.rb +1 -1
  63. data/lib/chewy/query/nodes/missing.rb +2 -2
  64. data/lib/chewy/query/nodes/not.rb +3 -3
  65. data/lib/chewy/query/nodes/or.rb +3 -3
  66. data/lib/chewy/query/nodes/prefix.rb +4 -3
  67. data/lib/chewy/query/nodes/query.rb +3 -3
  68. data/lib/chewy/query/nodes/range.rb +11 -11
  69. data/lib/chewy/query/nodes/raw.rb +1 -1
  70. data/lib/chewy/query/nodes/regexp.rb +15 -11
  71. data/lib/chewy/query/nodes/script.rb +6 -6
  72. data/lib/chewy/query/pagination/will_paginate.rb +2 -2
  73. data/lib/chewy/railtie.rb +3 -3
  74. data/lib/chewy/rake_helper.rb +51 -30
  75. data/lib/chewy/repository.rb +2 -2
  76. data/lib/chewy/rspec.rb +1 -1
  77. data/lib/chewy/rspec/update_index.rb +46 -47
  78. data/lib/chewy/runtime/version.rb +4 -4
  79. data/lib/chewy/search.rb +7 -5
  80. data/lib/chewy/strategy.rb +10 -8
  81. data/lib/chewy/strategy/atomic.rb +2 -2
  82. data/lib/chewy/strategy/base.rb +4 -4
  83. data/lib/chewy/strategy/bypass.rb +1 -2
  84. data/lib/chewy/strategy/sidekiq.rb +2 -0
  85. data/lib/chewy/strategy/urgent.rb +1 -1
  86. data/lib/chewy/type.rb +51 -45
  87. data/lib/chewy/type/adapter/active_record.rb +23 -12
  88. data/lib/chewy/type/adapter/base.rb +4 -4
  89. data/lib/chewy/type/adapter/mongoid.rb +6 -6
  90. data/lib/chewy/type/adapter/object.rb +15 -12
  91. data/lib/chewy/type/adapter/orm.rb +24 -15
  92. data/lib/chewy/type/adapter/sequel.rb +11 -7
  93. data/lib/chewy/type/crutch.rb +4 -3
  94. data/lib/chewy/type/import.rb +51 -32
  95. data/lib/chewy/type/mapping.rb +17 -17
  96. data/lib/chewy/type/observe.rb +9 -7
  97. data/lib/chewy/type/witchcraft.rb +62 -23
  98. data/lib/chewy/type/wrapper.rb +20 -14
  99. data/lib/chewy/version.rb +1 -1
  100. data/lib/generators/chewy/install_generator.rb +3 -3
  101. data/lib/tasks/chewy.rake +28 -23
  102. data/spec/chewy/config_spec.rb +33 -12
  103. data/spec/chewy/fields/base_spec.rb +143 -154
  104. data/spec/chewy/fields/root_spec.rb +22 -20
  105. data/spec/chewy/fields/time_fields_spec.rb +11 -9
  106. data/spec/chewy/index/actions_spec.rb +27 -4
  107. data/spec/chewy/index/aliases_spec.rb +2 -2
  108. data/spec/chewy/index/settings_spec.rb +72 -50
  109. data/spec/chewy/index_spec.rb +95 -43
  110. data/spec/chewy/journal/apply_spec.rb +120 -0
  111. data/spec/chewy/journal/entry_spec.rb +237 -0
  112. data/spec/chewy/journal_spec.rb +173 -0
  113. data/spec/chewy/minitest/helpers_spec.rb +90 -0
  114. data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
  115. data/spec/chewy/query/criteria_spec.rb +504 -237
  116. data/spec/chewy/query/filters_spec.rb +94 -66
  117. data/spec/chewy/query/loading_spec.rb +76 -40
  118. data/spec/chewy/query/nodes/and_spec.rb +3 -7
  119. data/spec/chewy/query/nodes/bool_spec.rb +5 -13
  120. data/spec/chewy/query/nodes/equal_spec.rb +20 -20
  121. data/spec/chewy/query/nodes/exists_spec.rb +7 -7
  122. data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
  123. data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
  124. data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
  125. data/spec/chewy/query/nodes/missing_spec.rb +6 -5
  126. data/spec/chewy/query/nodes/not_spec.rb +3 -7
  127. data/spec/chewy/query/nodes/or_spec.rb +3 -7
  128. data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
  129. data/spec/chewy/query/nodes/query_spec.rb +3 -3
  130. data/spec/chewy/query/nodes/range_spec.rb +19 -19
  131. data/spec/chewy/query/nodes/raw_spec.rb +2 -2
  132. data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
  133. data/spec/chewy/query/nodes/script_spec.rb +5 -5
  134. data/spec/chewy/query/pagination/kaminari_spec.rb +2 -2
  135. data/spec/chewy/query/pagination/will_paginage_spec.rb +6 -7
  136. data/spec/chewy/query/pagination_spec.rb +2 -3
  137. data/spec/chewy/query_spec.rb +208 -145
  138. data/spec/chewy/repository_spec.rb +8 -8
  139. data/spec/chewy/rspec/update_index_spec.rb +180 -111
  140. data/spec/chewy/search_spec.rb +8 -8
  141. data/spec/chewy/strategy/active_job_spec.rb +2 -2
  142. data/spec/chewy/strategy/atomic_spec.rb +4 -1
  143. data/spec/chewy/strategy/resque_spec.rb +2 -2
  144. data/spec/chewy/strategy/sidekiq_spec.rb +2 -2
  145. data/spec/chewy/type/actions_spec.rb +1 -1
  146. data/spec/chewy/type/adapter/active_record_spec.rb +255 -149
  147. data/spec/chewy/type/adapter/mongoid_spec.rb +169 -108
  148. data/spec/chewy/type/adapter/object_spec.rb +56 -40
  149. data/spec/chewy/type/adapter/sequel_spec.rb +248 -163
  150. data/spec/chewy/type/import_spec.rb +78 -47
  151. data/spec/chewy/type/mapping_spec.rb +6 -6
  152. data/spec/chewy/type/observe_spec.rb +20 -14
  153. data/spec/chewy/type/witchcraft_spec.rb +89 -43
  154. data/spec/chewy/type_spec.rb +4 -3
  155. data/spec/chewy_spec.rb +10 -8
  156. data/spec/spec_helper.rb +3 -0
  157. data/spec/support/active_record.rb +1 -1
  158. data/spec/support/class_helpers.rb +10 -11
  159. data/spec/support/mongoid.rb +2 -2
  160. data/spec/support/sequel.rb +1 -1
  161. metadata +65 -35
  162. data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
  163. data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
  164. data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
  165. data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
  166. data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
  167. data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
  168. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  169. data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
  170. data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
  171. data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
  172. data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
  173. data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
  174. data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
  175. data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
  176. data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
  177. data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
  178. data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
  179. data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
@@ -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 { expect { subject.transport_logger = logger }
21
- .to change { Chewy.client.transport.logger }.to(logger) }
22
- specify { expect { subject.transport_logger = logger }
23
- .to change { subject.transport_logger }.to(logger) }
24
- specify { expect { subject.transport_logger = logger }
25
- .to change { subject.configuration[:logger] }.from(nil).to(logger) }
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 { expect { subject.transport_tracer = tracer }
33
- .to change { Chewy.client.transport.tracer }.to(tracer) }
34
- specify { expect { subject.transport_tracer = tracer }
35
- .to change { subject.transport_tracer }.to(tracer) }
36
- specify { expect { subject.transport_tracer = tracer }
37
- .to change { subject.configuration[:tracer] }.from(nil).to(tracer) }
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({name: 'hello'}) }
11
- specify { expect(field.compose(double(value: ['hello', 'world']))).to eq({name: ['hello', 'world']}) }
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 { expect(field.compose(double(value: double(subvalue1: 'hello', subvalue2: 'value', subname3: 'world'))))
27
- .to eq({name: {'subname1' => 'hello', 'subname2' => 'value', 'subname3' => 'world'}}) }
28
- specify { expect(field.compose(double(value: [
29
- double(subvalue1: 'hello1', subvalue2: 'value1', subname3: 'world1'),
30
- double(subvalue1: 'hello2', subvalue2: 'value2', subname3: 'world2')
31
- ]))).to eq({name: [
32
- {'subname1' => 'hello1', 'subname2' => 'value1', 'subname3' => 'world1'},
33
- {'subname1' => 'hello2', 'subname2' => 'value2', 'subname3' => 'world2'}
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 { expect(country.compose(double(name: 'Thailand', cities: [
48
- double(name: 'Bangkok', districts: ['First', 'Second'])
49
- ]))).to eq(name: [
50
- { 'name' => [
51
- { 'name' => [['First', 'Thailand'], 'Bangkok', 'Thailand'] },
52
- { 'name' => [['Second', 'Thailand'], 'Bangkok', 'Thailand'] }
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({name: 'Alex'}) }
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({ name: { 'key1' => 'value1', 'key2' => 'value2'} }) }
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.times.map { |i| described_class.new("name#{i+1}", type: "string#{i+1}") } }
83
- let(:fields2) { 2.times.map { |i| described_class.new("name#{i+3}", type: "string#{i+3}") } }
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 { expect(field.mappings_hash).to eq({name: {type: :object, properties: {
90
- name1: {type: 'string1', fields: {
91
- name3: {type: 'string3'}, name4: {type: 'string4'}
92
- }}, name2: {type: 'string2'}
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.times.map { |i| described_class.new("name#{i+1}") } }
104
+ let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}") } }
98
105
 
99
- specify { expect(field.mappings_hash).to eq({name: {type: :string, fields: {
100
- name1: {type: 'object', properties: {
101
- name3: {type: 'string3'}, name4: {type: 'string4'}
102
- }}, name2: {type: 'string'}
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({ event: {
126
- properties: {
127
- id: { type: 'string' },
128
- category: {
129
- type: 'object',
130
- properties: {
131
- id: { type: 'string' },
132
- licenses: {
133
- type: 'object',
134
- properties: {
135
- id: { type: 'string' },
136
- name: { type: 'string' } } } } } } } })
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
- id: 1, category: { id: 2, licenses: { id: 3, name: 'Name' } }
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
- event: { 'id' => 1, 'category' => [
153
- { 'id' => 2, 'licenses' => { 'id' => 3, 'name' => 'Name1' } },
154
- {'id' => 4, 'licenses' => nil.as_json }
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
- event: { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => [
164
- {'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
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
- event: { 'id' => 1, 'category' => [
177
- { 'id' => 2, 'licenses' => [
178
- { 'id' => 3, 'name' => 'Name1' }, { 'id' => 4, 'name' => 'Name2' }
179
- ] },
180
- {'id' => 5, 'licenses' => [] }
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
- double(id: 1, category: double(id: 2, licenses: double(id: 3, name: 'Name')))
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
- event: { 'id' => 1, 'category' => [
199
- { 'id' => 2, 'licenses' => { 'id' => 3, 'name' => 'Name1' } },
200
- {'id' => 4, 'licenses' => nil.as_json }
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
- event: { 'id' => 1, 'category' => { 'id' => 2, 'licenses' => [
210
- {'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
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
- event: { 'id' => 1, 'category' => [
223
- { 'id' => 2, 'licenses' => [
224
- { 'id' => 3, 'name' => 'Name1' }, { 'id' => 4, 'name' => 'Name2' }
225
- ] },
226
- {'id' => 5, 'licenses' => [] }
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
- double(id: 1, categories: double(id: 2, license: double(id: 3, name: 'Name')))
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({ event: {
272
- properties: {
273
- id: { type: 'string' },
274
- name: {
275
- type: 'string',
276
- fields: {
277
- raw: { analyzer: 'my_own', type: 'string' }
278
- }
279
- },
280
- category: { type: 'object' }
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
- double(id: 1, name: 'Jonny', category: double(id: 2, as_json: {name: 'Borogoves'}))
288
- )).to eq({
289
- event: {
290
- 'id' => 1,
291
- 'name' => 'Jonny',
292
- 'category' => { 'name' => 'Borogoves' }
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
- double(id: 1, name: 'Jonny', category: [
300
- double(id: 2, as_json: { name: 'Borogoves1' }),
301
- double(id: 3, as_json: { name: 'Borogoves2' })
302
- ])
303
- )).to eq({
304
- event: {
305
- 'id' => 1,
306
- 'name' => 'Jonny',
307
- 'category' => [
308
- { 'name' => 'Borogoves1' },
309
- { 'name' => 'Borogoves2' }
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
- country: { 'id' => 1, 'cities' => [
363
- { 'id' => 1, 'name' => 'City1' }, { 'id' => 2, 'name' => 'City2' }
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
- City.create!(id: 1, country: Country.create!(id: 1, name: 'Country'))
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