chewy 5.0.0 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +240 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
  6. data/.github/workflows/ruby.yml +94 -0
  7. data/Appraisals +1 -17
  8. data/CHANGELOG.md +308 -356
  9. data/CODE_OF_CONDUCT.md +14 -0
  10. data/CONTRIBUTING.md +63 -0
  11. data/Gemfile +2 -0
  12. data/LICENSE.txt +1 -1
  13. data/README.md +71 -55
  14. data/chewy.gemspec +5 -5
  15. data/gemfiles/rails.5.2.activerecord.gemfile +4 -3
  16. data/gemfiles/{rails.5.0.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +4 -3
  17. data/gemfiles/{rails.5.0.mongoid.6.1.gemfile → rails.6.0.activerecord.gemfile} +4 -3
  18. data/gemfiles/{rails.5.1.activerecord.gemfile → rails.6.1.activerecord.gemfile} +6 -3
  19. data/lib/chewy.rb +1 -1
  20. data/lib/chewy/backports/duplicable.rb +1 -1
  21. data/lib/chewy/config.rb +2 -20
  22. data/lib/chewy/fields/base.rb +1 -7
  23. data/lib/chewy/fields/root.rb +2 -2
  24. data/lib/chewy/index.rb +2 -0
  25. data/lib/chewy/index/actions.rb +15 -5
  26. data/lib/chewy/index/aliases.rb +16 -5
  27. data/lib/chewy/multi_search.rb +62 -0
  28. data/lib/chewy/railtie.rb +1 -1
  29. data/lib/chewy/search.rb +2 -9
  30. data/lib/chewy/search/loader.rb +1 -1
  31. data/lib/chewy/search/pagination/will_paginate.rb +1 -1
  32. data/lib/chewy/search/parameters.rb +24 -6
  33. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  34. data/lib/chewy/search/parameters/indices.rb +123 -0
  35. data/lib/chewy/search/parameters/none.rb +1 -3
  36. data/lib/chewy/search/request.rb +101 -74
  37. data/lib/chewy/search/scrolling.rb +7 -6
  38. data/lib/chewy/stash.rb +1 -1
  39. data/lib/chewy/strategy/active_job.rb +1 -1
  40. data/lib/chewy/strategy/sidekiq.rb +1 -1
  41. data/lib/chewy/type.rb +4 -1
  42. data/lib/chewy/type/adapter/active_record.rb +1 -1
  43. data/lib/chewy/type/adapter/mongoid.rb +1 -1
  44. data/lib/chewy/type/adapter/orm.rb +7 -4
  45. data/lib/chewy/type/adapter/sequel.rb +1 -1
  46. data/lib/chewy/type/import.rb +14 -4
  47. data/lib/chewy/type/import/bulk_request.rb +4 -2
  48. data/lib/chewy/type/import/journal_builder.rb +1 -1
  49. data/lib/chewy/type/import/routine.rb +1 -1
  50. data/lib/chewy/type/mapping.rb +4 -4
  51. data/lib/chewy/type/observe.rb +3 -3
  52. data/lib/chewy/type/syncer.rb +4 -5
  53. data/lib/chewy/type/witchcraft.rb +4 -2
  54. data/lib/chewy/type/wrapper.rb +12 -2
  55. data/lib/chewy/version.rb +1 -1
  56. data/migration_guide.md +56 -0
  57. data/spec/chewy/config_spec.rb +1 -22
  58. data/spec/chewy/fields/base_spec.rb +11 -9
  59. data/spec/chewy/index/actions_spec.rb +120 -33
  60. data/spec/chewy/index/aliases_spec.rb +3 -3
  61. data/spec/chewy/index_spec.rb +16 -39
  62. data/spec/chewy/journal_spec.rb +22 -18
  63. data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
  64. data/spec/chewy/multi_search_spec.rb +85 -0
  65. data/spec/chewy/rake_helper_spec.rb +102 -87
  66. data/spec/chewy/rspec/update_index_spec.rb +47 -46
  67. data/spec/chewy/runtime_spec.rb +2 -2
  68. data/spec/chewy/search/parameters/indices_spec.rb +190 -0
  69. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  70. data/spec/chewy/search/parameters_spec.rb +21 -4
  71. data/spec/chewy/search/request_spec.rb +103 -70
  72. data/spec/chewy/search/response_spec.rb +27 -17
  73. data/spec/chewy/search/scrolling_spec.rb +27 -17
  74. data/spec/chewy/search_spec.rb +45 -41
  75. data/spec/chewy/stash_spec.rb +14 -12
  76. data/spec/chewy/strategy/active_job_spec.rb +15 -2
  77. data/spec/chewy/strategy/shoryuken_spec.rb +6 -2
  78. data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
  79. data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
  80. data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
  81. data/spec/chewy/type/import/journal_builder_spec.rb +9 -7
  82. data/spec/chewy/type/import_spec.rb +9 -0
  83. data/spec/chewy/type/mapping_spec.rb +3 -1
  84. data/spec/chewy/type/observe_spec.rb +4 -4
  85. data/spec/chewy/type/witchcraft_spec.rb +15 -0
  86. data/spec/chewy/type/wrapper_spec.rb +3 -1
  87. data/spec/chewy_spec.rb +0 -7
  88. data/spec/spec_helper.rb +4 -8
  89. data/spec/support/active_record.rb +21 -0
  90. metadata +32 -97
  91. data/.travis.yml +0 -45
  92. data/LEGACY_DSL.md +0 -497
  93. data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
  94. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  95. data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
  96. data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
  97. data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
  98. data/lib/chewy/query.rb +0 -1137
  99. data/lib/chewy/query/compose.rb +0 -68
  100. data/lib/chewy/query/criteria.rb +0 -191
  101. data/lib/chewy/query/filters.rb +0 -244
  102. data/lib/chewy/query/loading.rb +0 -110
  103. data/lib/chewy/query/nodes/and.rb +0 -25
  104. data/lib/chewy/query/nodes/base.rb +0 -17
  105. data/lib/chewy/query/nodes/bool.rb +0 -34
  106. data/lib/chewy/query/nodes/equal.rb +0 -34
  107. data/lib/chewy/query/nodes/exists.rb +0 -20
  108. data/lib/chewy/query/nodes/expr.rb +0 -28
  109. data/lib/chewy/query/nodes/field.rb +0 -110
  110. data/lib/chewy/query/nodes/has_child.rb +0 -15
  111. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  112. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  113. data/lib/chewy/query/nodes/match_all.rb +0 -11
  114. data/lib/chewy/query/nodes/missing.rb +0 -20
  115. data/lib/chewy/query/nodes/not.rb +0 -25
  116. data/lib/chewy/query/nodes/or.rb +0 -25
  117. data/lib/chewy/query/nodes/prefix.rb +0 -19
  118. data/lib/chewy/query/nodes/query.rb +0 -20
  119. data/lib/chewy/query/nodes/range.rb +0 -63
  120. data/lib/chewy/query/nodes/raw.rb +0 -15
  121. data/lib/chewy/query/nodes/regexp.rb +0 -35
  122. data/lib/chewy/query/nodes/script.rb +0 -20
  123. data/lib/chewy/query/pagination.rb +0 -25
  124. data/spec/chewy/query/criteria_spec.rb +0 -700
  125. data/spec/chewy/query/filters_spec.rb +0 -201
  126. data/spec/chewy/query/loading_spec.rb +0 -124
  127. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  128. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  129. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  130. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  131. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  132. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  133. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  134. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  135. data/spec/chewy/query/nodes/not_spec.rb +0 -14
  136. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  137. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  138. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  139. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  140. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  141. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  142. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  143. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  144. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  145. data/spec/chewy/query/pagination_spec.rb +0 -39
  146. data/spec/chewy/query_spec.rb +0 -637
  147. data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
@@ -1,201 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Query::Filters do
4
- def Bool(options) # rubocop:disable Naming/MethodName
5
- Chewy::Query::Nodes::Bool.new.tap do |bool|
6
- bool.must(*options[:must]) if options[:must].present?
7
- bool.must_not(*options[:must_not]) if options[:must_not].present?
8
- bool.should(*options[:should]) if options[:should].present?
9
- end
10
- end
11
-
12
- %w[field group and or not raw exists missing prefix regexp range equal query script].each do |method|
13
- define_method method.camelize do |*args|
14
- "Chewy::Query::Nodes::#{method.camelize}".constantize.new(*args)
15
- end
16
- end
17
-
18
- def query(&block)
19
- Chewy::Query::Filters.new(&block).__result__
20
- end
21
-
22
- context 'outer scope' do
23
- let(:email) { 'email' }
24
- specify { expect(query { email }).to be_eql Field(:email) }
25
- specify { expect(query { o { email } }).to eq('email') }
26
- end
27
-
28
- context 'field' do
29
- let(:email) { 'email' }
30
- specify { expect(query { f(:email) }).to be_eql Field(:email) }
31
- specify { expect(query { f { :email } }).to be_eql Field(:email) }
32
- specify { expect(query { f { email } }).to be_eql Field(:email) }
33
- specify { expect(query { email }).to be_eql Field(:email) }
34
- specify { expect(query { emails.first }).to be_eql Field('emails.first') }
35
- specify { expect(query { emails.first.second }).to be_eql Field('emails.first.second') }
36
- end
37
-
38
- context 'term' do
39
- specify { expect(query { email == 'email' }).to be_eql Equal(:email, 'email') }
40
- specify { expect(query { name != 'name' }).to be_eql Not(Equal(:name, 'name')) }
41
- specify { expect(query { email == %w[email1 email2] }).to be_eql Equal(:email, %w[email1 email2]) }
42
- specify { expect(query { email != %w[email1 email2] }).to be_eql Not(Equal(:email, %w[email1 email2])) }
43
- specify do
44
- expect(query { email(execution: :bool) == %w[email1 email2] })
45
- .to be_eql Equal(:email, %w[email1 email2], execution: :bool)
46
- end
47
- specify do
48
- expect(query { email(:bool) == %w[email1 email2] })
49
- .to be_eql Equal(:email, %w[email1 email2], execution: :bool)
50
- end
51
- specify do
52
- expect(query { email(:b) == %w[email1 email2] })
53
- .to be_eql Equal(:email, %w[email1 email2], execution: :bool)
54
- end
55
- end
56
-
57
- context 'bool' do
58
- specify { query { must(email == 'email') }.should be_eql Bool(must: [Equal(:email, 'email')]) }
59
- specify { query { must_not(email == 'email') }.should be_eql Bool(must_not: [Equal(:email, 'email')]) }
60
- specify { query { should(email == 'email') }.should be_eql Bool(should: [Equal(:email, 'email')]) }
61
- specify do
62
- query do
63
- must(email == 'email').should(address != 'address', age == 42)
64
- .must_not(sex == 'm').must(name == 'name')
65
- end.should be_eql Bool(
66
- must: [Equal(:email, 'email'), Equal(:name, 'name')],
67
- must_not: [Equal(:sex, 'm')],
68
- should: [Not(Equal(:address, 'address')), Equal(:age, 42)]
69
- )
70
- end
71
- end
72
-
73
- context 'exists' do
74
- specify { expect(query { email? }).to be_eql Exists(:email) }
75
- specify { expect(query { !!email? }).to be_eql Exists(:email) }
76
- specify { expect(query { emails.first? }).to be_eql Exists('emails.first') }
77
- specify { expect(query { !!emails.first? }).to be_eql Exists('emails.first') }
78
- specify { expect(query { emails != nil }).to be_eql Exists('emails') } # rubocop:disable Style/NonNilCheck
79
- specify { expect(query { emails.first != nil }).to be_eql Exists('emails.first') } # rubocop:disable Style/NonNilCheck
80
- specify { expect(query { !emails.nil? }).to be_eql Exists('emails') }
81
- specify { expect(query { !emails.first.nil? }).to be_eql Exists('emails.first') }
82
- end
83
-
84
- context 'missing' do
85
- specify { expect(query { !email }).to be_eql Missing(:email) }
86
- specify { expect(query { !email? }).to be_eql Missing(:email, null_value: true) }
87
- specify { expect(query { !emails.first }).to be_eql Missing('emails.first') }
88
- specify { expect(query { !emails.first? }).to be_eql Missing('emails.first', null_value: true) }
89
- specify { expect(query { emails == nil }).to be_eql Missing('emails', existence: false, null_value: true) } # rubocop:disable Style/NilComparison
90
- specify { expect(query { emails.first == nil }).to be_eql Missing('emails.first', existence: false, null_value: true) } # rubocop:disable Style/NilComparison
91
- specify { expect(query { emails.nil? }).to be_eql Missing('emails', existence: false, null_value: true) }
92
- specify { expect(query { emails.first.nil? }).to be_eql Missing('emails.first', existence: false, null_value: true) }
93
- end
94
-
95
- context 'range' do
96
- specify { expect(query { age > 42 }).to be_eql Range(:age, gt: 42) }
97
- specify { expect(query { age >= 42 }).to be_eql Range(:age, gt: 42, left_closed: true) }
98
- specify { expect(query { age < 42 }).to be_eql Range(:age, lt: 42) }
99
- specify { expect(query { age <= 42 }).to be_eql Range(:age, lt: 42, right_closed: true) }
100
-
101
- specify { expect(query { age == (30..42) }).to be_eql Range(:age, gt: 30, lt: 42) }
102
- specify { expect(query { age == [30..42] }).to be_eql Range(:age, gt: 30, lt: 42, left_closed: true, right_closed: true) }
103
- specify { expect(query { (age > 30) & (age < 42) }).to be_eql Range(:age, gt: 30, lt: 42) }
104
- specify { expect(query { (age > 30) & (age <= 42) }).to be_eql Range(:age, gt: 30, lt: 42, right_closed: true) }
105
- specify { expect(query { (age >= 30) & (age < 42) }).to be_eql Range(:age, gt: 30, lt: 42, left_closed: true) }
106
- specify { expect(query { (age >= 30) & (age <= 42) }).to be_eql Range(:age, gt: 30, lt: 42, right_closed: true, left_closed: true) }
107
- specify { expect(query { (age > 30) | (age < 42) }).to be_eql Or(Range(:age, gt: 30), Range(:age, lt: 42)) }
108
- end
109
-
110
- context 'prefix' do
111
- specify { expect(query { name =~ 'nam' }).to be_eql Prefix(:name, 'nam') }
112
- specify { expect(query { name !~ 'nam' }).to be_eql Not(Prefix(:name, 'nam')) }
113
- end
114
-
115
- context 'regexp' do
116
- specify { expect(query { name =~ /name/ }).to be_eql Regexp(:name, 'name') }
117
- specify { expect(query { name == /name/ }).to be_eql Regexp(:name, 'name') }
118
- specify { expect(query { name !~ /name/ }).to be_eql Not(Regexp(:name, 'name')) }
119
- specify { expect(query { name != /name/ }).to be_eql Not(Regexp(:name, 'name')) }
120
- specify { expect(query { name(:anystring, :intersection) =~ /name/ }).to be_eql Regexp(:name, 'name', flags: %w[anystring intersection]) }
121
- end
122
-
123
- context 'query' do
124
- let(:some_query) { 'some query' }
125
- specify { expect(query { q('some query') }).to be_eql Query('some query') }
126
- specify { expect(query { q { 'some query' } }).to be_eql Query('some query') }
127
- specify { expect(query { q { some_query } }).to be_eql Query('some query') }
128
- end
129
-
130
- context 'raw' do
131
- let(:raw_query) { {term: {name: 'name'}} }
132
- specify { expect(query { r(term: {name: 'name'}) }).to be_eql Raw(term: {name: 'name'}) }
133
- specify { expect(query { r { {term: {name: 'name'}} } }).to be_eql Raw(term: {name: 'name'}) }
134
- specify { expect(query { r { raw_query } }).to be_eql Raw(term: {name: 'name'}) }
135
- end
136
-
137
- context 'script' do
138
- let(:some_script) { 'some script' }
139
- specify { expect(query { s('some script') }).to be_eql Script('some script') }
140
- specify { expect(query { s('some script', param1: 42) }).to be_eql Script('some script', param1: 42) }
141
- specify { expect(query { s { 'some script' } }).to be_eql Script('some script') }
142
- specify { expect(query { s(param1: 42) { some_script } }).to be_eql Script('some script', param1: 42) }
143
- end
144
-
145
- context 'and or not' do
146
- specify do
147
- expect(query { (email == 'email') & (name == 'name') })
148
- .to be_eql And(Equal(:email, 'email'), Equal(:name, 'name'))
149
- end
150
- specify do
151
- expect(query { (email == 'email') | (name == 'name') })
152
- .to be_eql Or(Equal(:email, 'email'), Equal(:name, 'name'))
153
- end
154
- specify { expect(query { email != 'email' }).to be_eql Not(Equal(:email, 'email')) }
155
-
156
- specify do
157
- expect(query { (email == 'email') & (name == 'name') | (address != 'address') })
158
- .to be_eql Or(
159
- And(
160
- Equal(:email, 'email'),
161
- Equal(:name, 'name')
162
- ),
163
- Not(Equal(:address, 'address'))
164
- )
165
- end
166
- specify do
167
- expect(query { (email == 'email') & ((name == 'name') | (address != 'address')) })
168
- .to be_eql And(
169
- Equal(:email, 'email'),
170
- Or(
171
- Equal(:name, 'name'),
172
- Not(Equal(:address, 'address'))
173
- )
174
- )
175
- end
176
- specify do
177
- expect(query { (email == 'email') & ((name == 'name') & (address != 'address')) })
178
- .to be_eql And(
179
- Equal(:email, 'email'),
180
- Equal(:name, 'name'),
181
- Not(Equal(:address, 'address'))
182
- )
183
- end
184
- specify do
185
- expect(query { ((email == 'email') | (name == 'name')) | (address != 'address') })
186
- .to be_eql Or(
187
- Equal(:email, 'email'),
188
- Equal(:name, 'name'),
189
- Not(Equal(:address, 'address'))
190
- )
191
- end
192
- specify do
193
- expect(query { !((email == 'email') | (name == 'name')) })
194
- .to be_eql Not(Or(Equal(:email, 'email'), Equal(:name, 'name')))
195
- end
196
- specify do
197
- expect(query { !!((email == 'email') | (name == 'name')) })
198
- .to be_eql Or(Equal(:email, 'email'), Equal(:name, 'name'))
199
- end
200
- end
201
- end
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Query::Loading, :orm do
4
- before { Chewy.massacre }
5
-
6
- before do
7
- stub_model(:city)
8
- stub_model(:country)
9
- end
10
-
11
- context 'multiple types' do
12
- let(:cities) { Array.new(6) { |i| City.create!(rating: i) } }
13
- let(:countries) { Array.new(6) { |i| Country.create!(rating: i) } }
14
-
15
- before do
16
- stub_index(:places) do
17
- define_type City do
18
- field :rating, type: 'integer', value: ->(o) { o.rating }
19
- end
20
-
21
- define_type Country do
22
- field :rating, type: 'integer', value: ->(o) { o.rating }
23
- end
24
- end
25
- end
26
-
27
- let(:subject) { Chewy::Query.new(PlacesIndex) }
28
-
29
- before { PlacesIndex.import!(cities: cities, countries: countries) }
30
-
31
- describe '#load' do
32
- specify { expect(subject.order(:rating).limit(6).load.total_count).to eq(12) }
33
- specify { expect(subject.order(:rating).limit(6).load).to match_array(cities.first(3) + countries.first(3)) }
34
-
35
- context 'mongoid', :mongoid do
36
- specify do
37
- expect(subject.order(:rating).limit(6).load(city: {scope: -> { where(:rating.lt => 2) }}))
38
- .to match_array(cities.first(2) + countries.first(3) + [nil])
39
- end
40
- specify do
41
- expect(subject.limit(6).load(city: {scope: -> { where(:rating.lt => 2) }}).order(:rating))
42
- .to match_array(cities.first(2) + countries.first(3) + [nil])
43
- end
44
- specify do
45
- expect(subject.order(:rating).limit(6).load(scope: -> { where(:rating.lt => 2) }))
46
- .to match_array(cities.first(2) + countries.first(2) + [nil] * 2)
47
- end
48
- specify do
49
- expect(subject.order(:rating).limit(6).load(city: {scope: City.where(:rating.lt => 2)}))
50
- .to match_array(cities.first(2) + countries.first(3) + [nil])
51
- end
52
- end
53
-
54
- context 'active record', :active_record do
55
- specify do
56
- expect(subject.order(:rating).limit(6).load(city: {scope: -> { where('rating < 2') }}))
57
- .to match_array(cities.first(2) + countries.first(3) + [nil])
58
- end
59
- specify do
60
- expect(subject.limit(6).load(city: {scope: -> { where('rating < 2') }}).order(:rating))
61
- .to match_array(cities.first(2) + countries.first(3) + [nil])
62
- end
63
- specify do
64
- expect(subject.order(:rating).limit(6).load(scope: -> { where('rating < 2') }))
65
- .to match_array(cities.first(2) + countries.first(2) + [nil] * 2)
66
- end
67
- specify do
68
- expect(subject.order(:rating).limit(6).load(city: {scope: City.where('rating < 2')}))
69
- .to match_array(cities.first(2) + countries.first(3) + [nil])
70
- end
71
- end
72
- end
73
-
74
- describe '#preload' do
75
- context 'mongoid', :mongoid do
76
- specify do
77
- expect(subject.order(:rating).limit(6).preload(scope: -> { where(:rating.lt => 2) })
78
- .map(&:_object)).to match_array(cities.first(2) + countries.first(2) + [nil] * 2)
79
- end
80
- specify do
81
- expect(subject.limit(6).preload(scope: -> { where(:rating.lt => 2) }).order(:rating)
82
- .map(&:_object)).to match_array(cities.first(2) + countries.first(2) + [nil] * 2)
83
- end
84
-
85
- specify do
86
- expect(subject.order(:rating).limit(6).preload(only: :city, scope: -> { where(:rating.lt => 2) })
87
- .map(&:_object)).to match_array(cities.first(2) + [nil] * 4)
88
- end
89
- specify do
90
- expect(subject.order(:rating).limit(6).preload(except: [:city], scope: -> { where(:rating.lt => 2) })
91
- .map(&:_object)).to match_array(countries.first(2) + [nil] * 4)
92
- end
93
- specify do
94
- expect(subject.order(:rating).limit(6).preload(only: [:city], except: :city, scope: -> { where(:rating.lt => 2) })
95
- .map(&:_object)).to match_array([nil] * 6)
96
- end
97
- end
98
-
99
- context 'active record', :active_record do
100
- specify do
101
- expect(subject.order(:rating).limit(6).preload(scope: -> { where('rating < 2') })
102
- .map(&:_object)).to match_array(cities.first(2) + countries.first(2) + [nil] * 2)
103
- end
104
- specify do
105
- expect(subject.limit(6).preload(scope: -> { where('rating < 2') }).order(:rating)
106
- .map(&:_object)).to match_array(cities.first(2) + countries.first(2) + [nil] * 2)
107
- end
108
-
109
- specify do
110
- expect(subject.order(:rating).limit(6).preload(only: :city, scope: -> { where('rating < 2') })
111
- .map(&:_object)).to match_array(cities.first(2) + [nil] * 4)
112
- end
113
- specify do
114
- expect(subject.order(:rating).limit(6).preload(except: [:city], scope: -> { where('rating < 2') })
115
- .map(&:_object)).to match_array(countries.first(2) + [nil] * 4)
116
- end
117
- specify do
118
- expect(subject.order(:rating).limit(6).preload(only: [:city], except: :city, scope: -> { where('rating < 2') })
119
- .map(&:_object)).to match_array([nil] * 6)
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Query::Nodes::And do
4
- describe '#__render__' do
5
- def render(&block)
6
- Chewy::Query::Filters.new(&block).__render__
7
- end
8
-
9
- specify { expect(render { name? & (email == 'email') }).to eq(and: [{exists: {field: 'name'}}, {term: {'email' => 'email'}}]) }
10
- specify { expect(render { ~(name? & (email == 'email')) }).to eq(and: {filters: [{exists: {field: 'name'}}, {term: {'email' => 'email'}}], _cache: true}) }
11
- end
12
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Query::Nodes::Bool do
4
- describe '#__render__' do
5
- def render(&block)
6
- Chewy::Query::Filters.new(&block).__render__
7
- end
8
-
9
- specify { expect(render { must(name == 'name', email == 'email') }).to eq(bool: {must: [{term: {'name' => 'name'}}, {term: {'email' => 'email'}}]}) }
10
- specify { expect(render { must(name == 'name').must_not(email == 'email') }).to eq(bool: {must: [{term: {'name' => 'name'}}], must_not: [{term: {'email' => 'email'}}]}) }
11
- specify { expect(render { must(name == 'name').should(email == 'email') }).to eq(bool: {must: [{term: {'name' => 'name'}}], should: [{term: {'email' => 'email'}}]}) }
12
- specify { expect(render { ~must(name == 'name').should(email == 'email') }).to eq(bool: {must: [{term: {'name' => 'name'}}], should: [{term: {'email' => 'email'}}], _cache: true}) }
13
- end
14
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Query::Nodes::Equal do
4
- describe '#__render__' do
5
- def render(&block)
6
- Chewy::Query::Filters.new(&block).__render__
7
- end
8
-
9
- specify { expect(render { name == 'name' }).to eq(term: {'name' => 'name'}) }
10
- specify { expect(render { name != 'name' }).to eq(not: {term: {'name' => 'name'}}) }
11
- specify { expect(render { name == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2]}) }
12
- specify { expect(render { name != %w[name1 name2] }).to eq(not: {terms: {'name' => %w[name1 name2]}}) }
13
-
14
- specify { expect(render { name(:bool) == 'name' }).to eq(term: {'name' => 'name'}) }
15
- specify { expect(render { name(:borogoves) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2]}) }
16
-
17
- specify { expect(render { name(:|) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :or}) }
18
- specify { expect(render { name(:or) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :or}) }
19
- specify { expect(render { name(:&) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :and}) }
20
- specify { expect(render { name(:and) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :and}) }
21
- specify { expect(render { name(:b) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :bool}) }
22
- specify { expect(render { name(:bool) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :bool}) }
23
- specify { expect(render { name(:f) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :fielddata}) }
24
- specify { expect(render { name(:fielddata) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :fielddata}) }
25
-
26
- specify { expect(render { ~name == 'name' }).to eq(term: {'name' => 'name', _cache: true}) }
27
- specify { expect(render { ~(name == 'name') }).to eq(term: {'name' => 'name', _cache: true}) }
28
- specify { expect(render { ~name != 'name' }).to eq(not: {term: {'name' => 'name', _cache: true}}) }
29
- specify { expect(render { ~name(:|) == %w[name1 name2] }).to eq(terms: {'name' => %w[name1 name2], execution: :or, _cache: true}) }
30
- specify { expect(render { ~name != %w[name1 name2] }).to eq(not: {terms: {'name' => %w[name1 name2], _cache: true}}) }
31
- end
32
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Query::Nodes::Exists do
4
- describe '#__render__' do
5
- def render(&block)
6
- Chewy::Query::Filters.new(&block).__render__
7
- end
8
-
9
- specify { expect(render { name? }).to eq(exists: {field: 'name'}) }
10
-
11
- specify { expect(render { !!name? }).to eq(exists: {field: 'name'}) }
12
- specify { expect(render { !!name }).to eq(exists: {field: 'name'}) }
13
- specify { expect(render { name != nil }).to eq(exists: {field: 'name'}) } # rubocop:disable Style/NonNilCheck
14
- specify { expect(render { !name.nil? }).to eq(exists: {field: 'name'}) }
15
-
16
- specify { expect(render { ~name? }).to eq(exists: {field: 'name'}) }
17
- end
18
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Query::Nodes::HasChild do
4
- describe '#__render__' do
5
- def render(&block)
6
- Chewy::Query::Filters.new(&block).__render__
7
- end
8
-
9
- specify { expect(render { has_child('child') }).to eq(has_child: {type: 'child'}) }
10
-
11
- specify do
12
- expect(render { has_child('child').filter(term: {name: 'name'}) })
13
- .to eq(has_child: {type: 'child', filter: {term: {name: 'name'}}})
14
- end
15
- specify do
16
- expect(render { has_child('child').filter { name == 'name' } })
17
- .to eq(has_child: {type: 'child', filter: {term: {'name' => 'name'}}})
18
- end
19
- specify do
20
- expect(render { has_child('child').filter(term: {name: 'name'}).filter { age < 42 } })
21
- .to eq(has_child: {type: 'child', filter: {and: [{term: {name: 'name'}}, range: {'age' => {lt: 42}}]}})
22
- end
23
- specify do
24
- expect(render { has_child('child').filter(term: {name: 'name'}).filter { age < 42 }.filter_mode(:or) })
25
- .to eq(has_child: {type: 'child', filter: {or: [{term: {name: 'name'}}, range: {'age' => {lt: 42}}]}})
26
- end
27
-
28
- specify do
29
- expect(render { has_child('child').query(match: {name: 'name'}) })
30
- .to eq(has_child: {type: 'child', query: {match: {name: 'name'}}})
31
- end
32
- specify do
33
- expect(render { has_child('child').query(match: {name: 'name'}).query(match: {surname: 'surname'}) })
34
- .to eq(has_child: {type: 'child', query: {bool: {must: [{match: {name: 'name'}}, {match: {surname: 'surname'}}]}}})
35
- end
36
- specify do
37
- expect(render { has_child('child').query(match: {name: 'name'}).query(match: {surname: 'surname'}).query_mode(:should) })
38
- .to eq(has_child: {type: 'child', query: {bool: {should: [{match: {name: 'name'}}, {match: {surname: 'surname'}}]}}})
39
- end
40
-
41
- specify do
42
- expect(render { has_child('child').filter { name == 'name' }.query(match: {name: 'name'}) })
43
- .to eq(has_child: {type: 'child', query: {filtered: {query: {match: {name: 'name'}}, filter: {term: {'name' => 'name'}}}}})
44
- end
45
- specify do
46
- expect(render { has_child('child').filter { name == 'name' }.query(match: {name: 'name'}).filter { age < 42 } })
47
- .to eq(has_child: {type: 'child', query: {filtered: {query: {match: {name: 'name'}}, filter: {and: [{term: {'name' => 'name'}}, range: {'age' => {lt: 42}}]}}}})
48
- end
49
-
50
- context do
51
- let(:name) { 'Name' }
52
-
53
- specify do
54
- expect(render { has_child('child').filter { name == o { name } } })
55
- .to eq(has_child: {type: 'child', filter: {term: {'name' => 'Name'}}})
56
- end
57
- end
58
- end
59
- end