chewy 5.1.0 → 7.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -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 +73 -0
  7. data/.rubocop.yml +13 -8
  8. data/.rubocop_todo.yml +110 -22
  9. data/CHANGELOG.md +449 -347
  10. data/CODE_OF_CONDUCT.md +14 -0
  11. data/CONTRIBUTING.md +63 -0
  12. data/Gemfile +3 -7
  13. data/Guardfile +3 -1
  14. data/LICENSE.txt +1 -1
  15. data/README.md +423 -311
  16. data/chewy.gemspec +8 -10
  17. data/gemfiles/rails.5.2.activerecord.gemfile +9 -14
  18. data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
  19. data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
  20. data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
  21. data/lib/chewy/config.rb +42 -60
  22. data/lib/chewy/errors.rb +4 -10
  23. data/lib/chewy/fields/base.rb +80 -20
  24. data/lib/chewy/fields/root.rb +7 -17
  25. data/lib/chewy/index/actions.rb +62 -35
  26. data/lib/chewy/{type → index}/adapter/active_record.rb +18 -4
  27. data/lib/chewy/{type → index}/adapter/base.rb +2 -3
  28. data/lib/chewy/{type → index}/adapter/object.rb +28 -32
  29. data/lib/chewy/{type → index}/adapter/orm.rb +26 -24
  30. data/lib/chewy/index/aliases.rb +14 -5
  31. data/lib/chewy/{type → index}/crutch.rb +5 -5
  32. data/lib/chewy/index/import/bulk_builder.rb +311 -0
  33. data/lib/chewy/{type → index}/import/bulk_request.rb +6 -7
  34. data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
  35. data/lib/chewy/{type → index}/import/routine.rb +17 -16
  36. data/lib/chewy/{type → index}/import.rb +51 -33
  37. data/lib/chewy/{type → index}/mapping.rb +32 -37
  38. data/lib/chewy/index/observe/active_record_methods.rb +87 -0
  39. data/lib/chewy/index/observe/callback.rb +34 -0
  40. data/lib/chewy/index/observe.rb +17 -0
  41. data/lib/chewy/index/specification.rb +1 -0
  42. data/lib/chewy/{type → index}/syncer.rb +61 -62
  43. data/lib/chewy/{type → index}/witchcraft.rb +15 -9
  44. data/lib/chewy/{type → index}/wrapper.rb +13 -3
  45. data/lib/chewy/index.rb +46 -96
  46. data/lib/chewy/journal.rb +25 -14
  47. data/lib/chewy/minitest/helpers.rb +86 -13
  48. data/lib/chewy/minitest/search_index_receiver.rb +22 -26
  49. data/lib/chewy/multi_search.rb +62 -0
  50. data/lib/chewy/railtie.rb +6 -20
  51. data/lib/chewy/rake_helper.rb +136 -108
  52. data/lib/chewy/rspec/build_query.rb +12 -0
  53. data/lib/chewy/rspec/helpers.rb +55 -0
  54. data/lib/chewy/rspec/update_index.rb +55 -44
  55. data/lib/chewy/rspec.rb +2 -0
  56. data/lib/chewy/runtime.rb +1 -1
  57. data/lib/chewy/search/loader.rb +19 -41
  58. data/lib/chewy/search/parameters/collapse.rb +16 -0
  59. data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
  60. data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
  61. data/lib/chewy/search/parameters/indices.rb +12 -57
  62. data/lib/chewy/search/parameters/none.rb +1 -3
  63. data/lib/chewy/search/parameters/order.rb +6 -19
  64. data/lib/chewy/search/parameters/source.rb +5 -1
  65. data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
  66. data/lib/chewy/search/parameters.rb +7 -4
  67. data/lib/chewy/search/query_proxy.rb +9 -2
  68. data/lib/chewy/search/request.rb +180 -154
  69. data/lib/chewy/search/response.rb +5 -5
  70. data/lib/chewy/search/scoping.rb +7 -8
  71. data/lib/chewy/search/scrolling.rb +16 -13
  72. data/lib/chewy/search.rb +7 -22
  73. data/lib/chewy/stash.rb +19 -30
  74. data/lib/chewy/strategy/active_job.rb +2 -2
  75. data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
  76. data/lib/chewy/strategy/base.rb +10 -0
  77. data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
  78. data/lib/chewy/strategy/sidekiq.rb +3 -2
  79. data/lib/chewy/strategy.rb +5 -19
  80. data/lib/chewy/version.rb +1 -1
  81. data/lib/chewy.rb +36 -80
  82. data/lib/generators/chewy/install_generator.rb +1 -1
  83. data/lib/tasks/chewy.rake +26 -32
  84. data/migration_guide.md +56 -0
  85. data/spec/chewy/config_spec.rb +15 -61
  86. data/spec/chewy/fields/base_spec.rb +432 -145
  87. data/spec/chewy/fields/root_spec.rb +20 -28
  88. data/spec/chewy/fields/time_fields_spec.rb +5 -5
  89. data/spec/chewy/index/actions_spec.rb +388 -55
  90. data/spec/chewy/{type → index}/adapter/active_record_spec.rb +110 -44
  91. data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
  92. data/spec/chewy/index/aliases_spec.rb +3 -3
  93. data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
  94. data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -12
  95. data/spec/chewy/{type → index}/import/journal_builder_spec.rb +14 -22
  96. data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
  97. data/spec/chewy/{type → index}/import_spec.rb +149 -96
  98. data/spec/chewy/index/mapping_spec.rb +135 -0
  99. data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
  100. data/spec/chewy/index/observe/callback_spec.rb +139 -0
  101. data/spec/chewy/index/observe_spec.rb +143 -0
  102. data/spec/chewy/index/settings_spec.rb +3 -1
  103. data/spec/chewy/index/specification_spec.rb +20 -30
  104. data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
  105. data/spec/chewy/{type → index}/witchcraft_spec.rb +34 -21
  106. data/spec/chewy/index/wrapper_spec.rb +100 -0
  107. data/spec/chewy/index_spec.rb +69 -137
  108. data/spec/chewy/journal_spec.rb +46 -91
  109. data/spec/chewy/minitest/helpers_spec.rb +122 -14
  110. data/spec/chewy/minitest/search_index_receiver_spec.rb +24 -26
  111. data/spec/chewy/multi_search_spec.rb +84 -0
  112. data/spec/chewy/rake_helper_spec.rb +293 -101
  113. data/spec/chewy/rspec/build_query_spec.rb +34 -0
  114. data/spec/chewy/rspec/helpers_spec.rb +61 -0
  115. data/spec/chewy/rspec/update_index_spec.rb +106 -102
  116. data/spec/chewy/runtime_spec.rb +2 -2
  117. data/spec/chewy/search/loader_spec.rb +19 -53
  118. data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
  119. data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
  120. data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
  121. data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
  122. data/spec/chewy/search/parameters/indices_spec.rb +26 -118
  123. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  124. data/spec/chewy/search/parameters/order_spec.rb +18 -11
  125. data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
  126. data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
  127. data/spec/chewy/search/parameters/source_spec.rb +8 -2
  128. data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
  129. data/spec/chewy/search/parameters_spec.rb +23 -7
  130. data/spec/chewy/search/query_proxy_spec.rb +68 -17
  131. data/spec/chewy/search/request_spec.rb +344 -149
  132. data/spec/chewy/search/response_spec.rb +35 -25
  133. data/spec/chewy/search/scrolling_spec.rb +28 -26
  134. data/spec/chewy/search_spec.rb +69 -59
  135. data/spec/chewy/stash_spec.rb +16 -26
  136. data/spec/chewy/strategy/active_job_spec.rb +23 -10
  137. data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
  138. data/spec/chewy/strategy/atomic_spec.rb +9 -10
  139. data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
  140. data/spec/chewy/strategy/sidekiq_spec.rb +14 -10
  141. data/spec/chewy/strategy_spec.rb +19 -15
  142. data/spec/chewy_spec.rb +17 -110
  143. data/spec/spec_helper.rb +6 -29
  144. data/spec/support/active_record.rb +43 -5
  145. metadata +102 -198
  146. data/.travis.yml +0 -45
  147. data/Appraisals +0 -81
  148. data/LEGACY_DSL.md +0 -497
  149. data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
  150. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  151. data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
  152. data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
  153. data/gemfiles/rails.5.0.activerecord.gemfile +0 -16
  154. data/gemfiles/rails.5.0.mongoid.6.1.gemfile +0 -16
  155. data/gemfiles/rails.5.1.activerecord.gemfile +0 -16
  156. data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
  157. data/gemfiles/sequel.4.45.gemfile +0 -11
  158. data/lib/chewy/backports/deep_dup.rb +0 -46
  159. data/lib/chewy/backports/duplicable.rb +0 -91
  160. data/lib/chewy/query/compose.rb +0 -68
  161. data/lib/chewy/query/criteria.rb +0 -191
  162. data/lib/chewy/query/filters.rb +0 -244
  163. data/lib/chewy/query/loading.rb +0 -110
  164. data/lib/chewy/query/nodes/and.rb +0 -25
  165. data/lib/chewy/query/nodes/base.rb +0 -17
  166. data/lib/chewy/query/nodes/bool.rb +0 -34
  167. data/lib/chewy/query/nodes/equal.rb +0 -34
  168. data/lib/chewy/query/nodes/exists.rb +0 -20
  169. data/lib/chewy/query/nodes/expr.rb +0 -28
  170. data/lib/chewy/query/nodes/field.rb +0 -110
  171. data/lib/chewy/query/nodes/has_child.rb +0 -15
  172. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  173. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  174. data/lib/chewy/query/nodes/match_all.rb +0 -11
  175. data/lib/chewy/query/nodes/missing.rb +0 -20
  176. data/lib/chewy/query/nodes/not.rb +0 -25
  177. data/lib/chewy/query/nodes/or.rb +0 -25
  178. data/lib/chewy/query/nodes/prefix.rb +0 -19
  179. data/lib/chewy/query/nodes/query.rb +0 -20
  180. data/lib/chewy/query/nodes/range.rb +0 -63
  181. data/lib/chewy/query/nodes/raw.rb +0 -15
  182. data/lib/chewy/query/nodes/regexp.rb +0 -35
  183. data/lib/chewy/query/nodes/script.rb +0 -20
  184. data/lib/chewy/query/pagination.rb +0 -25
  185. data/lib/chewy/query.rb +0 -1142
  186. data/lib/chewy/search/pagination/will_paginate.rb +0 -43
  187. data/lib/chewy/search/parameters/types.rb +0 -20
  188. data/lib/chewy/strategy/resque.rb +0 -27
  189. data/lib/chewy/strategy/shoryuken.rb +0 -40
  190. data/lib/chewy/type/actions.rb +0 -43
  191. data/lib/chewy/type/adapter/mongoid.rb +0 -67
  192. data/lib/chewy/type/adapter/sequel.rb +0 -93
  193. data/lib/chewy/type/import/bulk_builder.rb +0 -122
  194. data/lib/chewy/type/observe.rb +0 -82
  195. data/lib/chewy/type.rb +0 -117
  196. data/lib/sequel/plugins/chewy_observe.rb +0 -63
  197. data/spec/chewy/query/criteria_spec.rb +0 -700
  198. data/spec/chewy/query/filters_spec.rb +0 -201
  199. data/spec/chewy/query/loading_spec.rb +0 -124
  200. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  201. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  202. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  203. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  204. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  205. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  206. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  207. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  208. data/spec/chewy/query/nodes/not_spec.rb +0 -14
  209. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  210. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  211. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  212. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  213. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  214. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  215. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  216. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  217. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  218. data/spec/chewy/query/pagination_spec.rb +0 -39
  219. data/spec/chewy/query_spec.rb +0 -637
  220. data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
  221. data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
  222. data/spec/chewy/search/parameters/types_spec.rb +0 -5
  223. data/spec/chewy/strategy/resque_spec.rb +0 -46
  224. data/spec/chewy/strategy/shoryuken_spec.rb +0 -66
  225. data/spec/chewy/type/actions_spec.rb +0 -50
  226. data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
  227. data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
  228. data/spec/chewy/type/import/bulk_builder_spec.rb +0 -279
  229. data/spec/chewy/type/mapping_spec.rb +0 -173
  230. data/spec/chewy/type/observe_spec.rb +0 -137
  231. data/spec/chewy/type/wrapper_spec.rb +0 -98
  232. data/spec/chewy/type_spec.rb +0 -55
  233. data/spec/support/mongoid.rb +0 -93
  234. data/spec/support/sequel.rb +0 -80
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chewy::Search::Parameters::IgnoreUnavailable do
4
+ subject { described_class.new(true) }
5
+
6
+ describe '#initialize' do
7
+ specify { expect(subject.value).to eq(true) }
8
+ specify { expect(described_class.new.value).to eq(nil) }
9
+ specify { expect(described_class.new(42).value).to eq(true) }
10
+ specify { expect(described_class.new(false).value).to eq(false) }
11
+ end
12
+
13
+ describe '#replace!' do
14
+ specify { expect { subject.replace!(false) }.to change { subject.value }.from(true).to(false) }
15
+ specify { expect { subject.replace!(nil) }.to change { subject.value }.from(true).to(nil) }
16
+ end
17
+
18
+ describe '#update!' do
19
+ specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(true) }
20
+ specify { expect { subject.update!(false) }.to change { subject.value }.from(true).to(false) }
21
+ specify { expect { subject.update!(true) }.not_to change { subject.value }.from(true) }
22
+
23
+ context do
24
+ subject { described_class.new(false) }
25
+
26
+ specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(false) }
27
+ specify { expect { subject.update!(false) }.not_to change { subject.value }.from(false) }
28
+ specify { expect { subject.update!(true) }.to change { subject.value }.from(false).to(true) }
29
+ end
30
+
31
+ context do
32
+ subject { described_class.new }
33
+
34
+ specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(nil) }
35
+ specify { expect { subject.update!(false) }.to change { subject.value }.from(nil).to(false) }
36
+ specify { expect { subject.update!(true) }.to change { subject.value }.from(nil).to(true) }
37
+ end
38
+ end
39
+
40
+ describe '#merge!' do
41
+ specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(true) }
42
+ specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(true).to(false) }
43
+ specify { expect { subject.merge!(described_class.new(true)) }.not_to change { subject.value }.from(true) }
44
+
45
+ context do
46
+ subject { described_class.new(false) }
47
+
48
+ specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(false) }
49
+ specify { expect { subject.merge!(described_class.new(false)) }.not_to change { subject.value }.from(false) }
50
+ specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(false).to(true) }
51
+ end
52
+
53
+ context do
54
+ subject { described_class.new }
55
+
56
+ specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(nil) }
57
+ specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(nil).to(false) }
58
+ specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(nil).to(true) }
59
+ end
60
+ end
61
+
62
+ describe '#render' do
63
+ specify { expect(described_class.new.render).to be_nil }
64
+ specify { expect(described_class.new(false).render).to eq(ignore_unavailable: false) }
65
+ specify { expect(subject.render).to eq(ignore_unavailable: true) }
66
+ end
67
+ end
@@ -2,38 +2,33 @@ require 'spec_helper'
2
2
 
3
3
  describe Chewy::Search::Parameters::Indices do
4
4
  before do
5
- stub_index(:first) do
6
- define_type :one
7
- define_type :two
8
- end
9
-
10
- stub_index(:second) do
11
- define_type :three
12
- end
5
+ stub_index(:first)
6
+ stub_index(:second)
7
+ stub_index(:third)
13
8
  end
14
9
 
15
- subject { described_class.new(indices: FirstIndex, types: SecondIndex::Three) }
10
+ subject { described_class.new(indices: [FirstIndex, SecondIndex]) }
16
11
 
17
12
  describe '#initialize' do
18
- specify { expect(described_class.new.value).to eq(indices: [], types: []) }
19
- specify { expect(described_class.new(nil).value).to eq(indices: [], types: []) }
20
- specify { expect(described_class.new(foo: :whatever).value).to eq(indices: [], types: []) }
21
- specify { expect(subject.value).to eq(indices: [FirstIndex], types: [SecondIndex::Three]) }
13
+ specify { expect(described_class.new.value).to eq(indices: []) }
14
+ specify { expect(described_class.new(nil).value).to eq(indices: []) }
15
+ specify { expect(described_class.new(foo: :whatever).value).to eq(indices: []) }
16
+ specify { expect(subject.value).to eq(indices: [FirstIndex, SecondIndex]) }
22
17
  end
23
18
 
24
19
  describe '#replace!' do
25
20
  specify do
26
21
  expect { subject.replace!(nil) }
27
22
  .to change { subject.value }
28
- .from(indices: [FirstIndex], types: [SecondIndex::Three])
29
- .to(indices: [], types: [])
23
+ .from(indices: [FirstIndex, SecondIndex])
24
+ .to(indices: [])
30
25
  end
31
26
 
32
27
  specify do
33
- expect { subject.replace!(indices: SecondIndex, types: FirstIndex::One) }
28
+ expect { subject.replace!(indices: SecondIndex) }
34
29
  .to change { subject.value }
35
- .from(indices: [FirstIndex], types: [SecondIndex::Three])
36
- .to(indices: [SecondIndex], types: [FirstIndex::One])
30
+ .from(indices: [FirstIndex, SecondIndex])
31
+ .to(indices: [SecondIndex])
37
32
  end
38
33
  end
39
34
 
@@ -44,10 +39,10 @@ describe Chewy::Search::Parameters::Indices do
44
39
  end
45
40
 
46
41
  specify do
47
- expect { subject.update!(indices: SecondIndex, types: [FirstIndex::One, SecondIndex::Three]) }
42
+ expect { subject.update!(indices: ThirdIndex) }
48
43
  .to change { subject.value }
49
- .from(indices: [FirstIndex], types: [SecondIndex::Three])
50
- .to(indices: [FirstIndex, SecondIndex], types: [SecondIndex::Three, FirstIndex::One])
44
+ .from(indices: [FirstIndex, SecondIndex])
45
+ .to(indices: [FirstIndex, SecondIndex, ThirdIndex])
51
46
  end
52
47
  end
53
48
 
@@ -58,10 +53,8 @@ describe Chewy::Search::Parameters::Indices do
58
53
  end
59
54
 
60
55
  specify do
61
- expect { subject.merge!(described_class.new(indices: SecondIndex, types: [FirstIndex::One, SecondIndex::Three])) }
62
- .to change { subject.value }
63
- .from(indices: [FirstIndex], types: [SecondIndex::Three])
64
- .to(indices: [FirstIndex, SecondIndex], types: [SecondIndex::Three, FirstIndex::One])
56
+ expect { subject.merge!(described_class.new(indices: SecondIndex)) }
57
+ .not_to change { subject.value }
65
58
  end
66
59
  end
67
60
 
@@ -70,7 +63,7 @@ describe Chewy::Search::Parameters::Indices do
70
63
  specify do
71
64
  expect(described_class.new(
72
65
  indices: FirstIndex
73
- ).render).to eq(index: %w[first], type: %w[one two])
66
+ ).render).to eq(index: %w[first])
74
67
  end
75
68
  specify do
76
69
  expect(described_class.new(
@@ -79,113 +72,28 @@ describe Chewy::Search::Parameters::Indices do
79
72
  end
80
73
  specify do
81
74
  expect(described_class.new(
82
- types: FirstIndex::One
83
- ).render).to eq(index: %w[first], type: %w[one])
84
- end
85
- specify do
86
- expect(described_class.new(
87
- types: :whatever
88
- ).render).to eq({})
89
- end
90
- specify do
91
- expect(described_class.new(
92
- indices: FirstIndex, types: SecondIndex::Three
93
- ).render).to eq(index: %w[first second], type: %w[one three two])
94
- end
95
- specify do
96
- expect(described_class.new(
97
- indices: FirstIndex, types: :one
98
- ).render).to eq(index: %w[first], type: %w[one])
99
- end
100
- specify do
101
- expect(described_class.new(
102
- indices: FirstIndex, types: :whatever
103
- ).render).to eq(index: %w[first], type: %w[one two])
104
- end
105
- specify do
106
- expect(described_class.new(
107
- indices: FirstIndex, types: %i[one whatever]
108
- ).render).to eq(index: %w[first], type: %w[one])
109
- end
110
- specify do
111
- expect(described_class.new(
112
- indices: :whatever, types: SecondIndex::Three
113
- ).render).to eq(index: %w[second whatever], type: %w[three])
114
- end
115
- specify do
116
- expect(described_class.new(
117
- indices: :whatever, types: [SecondIndex::Three, :whatever]
118
- ).render).to eq(index: %w[second whatever], type: %w[three whatever])
119
- end
120
- specify do
121
- expect(described_class.new(
122
- indices: [FirstIndex, :whatever], types: FirstIndex::One
123
- ).render).to eq(index: %w[first whatever], type: %w[one])
124
- end
125
- specify do
126
- expect(described_class.new(
127
- indices: FirstIndex, types: [FirstIndex::One, :whatever]
128
- ).render).to eq(index: %w[first], type: %w[one])
129
- end
130
- specify do
131
- expect(described_class.new(
132
- indices: FirstIndex, types: [SecondIndex::Three, :whatever]
133
- ).render).to eq(index: %w[first second], type: %w[one three two])
134
- end
135
- specify do
136
- expect(described_class.new(
137
- indices: [FirstIndex, :whatever], types: [FirstIndex::One, :whatever]
138
- ).render).to eq(index: %w[first whatever], type: %w[one whatever])
139
- end
140
- specify do
141
- expect(described_class.new(
142
- indices: [FirstIndex, :whatever], types: [SecondIndex::Three, FirstIndex::One]
143
- ).render).to eq(index: %w[first second whatever], type: %w[one three])
75
+ indices: [FirstIndex, :whatever]
76
+ ).render).to eq(index: %w[first whatever])
144
77
  end
145
78
  end
146
79
 
147
80
  describe '#==' do
148
81
  specify { expect(described_class.new).to eq(described_class.new) }
149
82
  specify do
150
- expect(described_class.new(indices: SecondIndex, types: [SecondIndex::Three, :whatever]))
151
- .to eq(described_class.new(indices: SecondIndex, types: :whatever))
152
- end
153
- specify do
154
- expect(described_class.new(indices: :first, types: %w[one two]))
83
+ expect(described_class.new(indices: :first))
155
84
  .to eq(described_class.new(indices: FirstIndex))
156
85
  end
157
86
  specify do
158
- expect(described_class.new(indices: FirstIndex, types: SecondIndex::Three))
159
- .not_to eq(described_class.new(indices: FirstIndex))
87
+ expect(described_class.new(indices: FirstIndex))
88
+ .to eq(described_class.new(indices: FirstIndex))
160
89
  end
161
90
  end
162
91
 
163
92
  describe '#indices' do
164
93
  specify do
165
94
  expect(described_class.new(
166
- indices: [FirstIndex, :whatever],
167
- types: [SecondIndex::Three, :whatever]
168
- ).indices).to contain_exactly(FirstIndex, SecondIndex)
169
- end
170
- end
171
-
172
- describe '#types' do
173
- specify do
174
- expect(described_class.new(
175
- indices: [FirstIndex, :whatever],
176
- types: [SecondIndex::Three, :whatever]
177
- ).types).to contain_exactly(
178
- FirstIndex::One, FirstIndex::Two, SecondIndex::Three
179
- )
180
- end
181
-
182
- specify do
183
- expect(described_class.new(
184
- indices: [FirstIndex, :whatever],
185
- types: [FirstIndex::One, SecondIndex::Three, :whatever]
186
- ).types).to contain_exactly(
187
- FirstIndex::One, SecondIndex::Three
188
- )
95
+ indices: [FirstIndex, :whatever]
96
+ ).indices).to contain_exactly(FirstIndex)
189
97
  end
190
98
  end
191
99
  end
@@ -1,5 +1,5 @@
1
1
  require 'chewy/search/parameters/bool_storage_examples'
2
2
 
3
3
  describe Chewy::Search::Parameters::None do
4
- it_behaves_like :bool_storage, query: {bool: {filter: {bool: {must_not: {match_all: {}}}}}}
4
+ it_behaves_like :bool_storage, query: {match_none: {}}
5
5
  end
@@ -4,26 +4,29 @@ describe Chewy::Search::Parameters::Order do
4
4
  subject { described_class.new(%i[foo bar]) }
5
5
 
6
6
  describe '#initialize' do
7
- specify { expect(described_class.new.value).to eq({}) }
8
- specify { expect(described_class.new(nil).value).to eq({}) }
9
- specify { expect(described_class.new('').value).to eq({}) }
10
- specify { expect(described_class.new(42).value).to eq('42' => nil) }
11
- specify { expect(described_class.new([42, 43]).value).to eq('42' => nil, '43' => nil) }
12
- specify { expect(described_class.new(a: 1).value).to eq('a' => 1) }
13
- specify { expect(described_class.new(['', 43, a: 1]).value).to eq('a' => 1, '43' => nil) }
7
+ specify { expect(described_class.new.value).to eq([]) }
8
+ specify { expect(described_class.new(nil).value).to eq([]) }
9
+ specify { expect(described_class.new('').value).to eq([]) }
10
+ specify { expect(described_class.new(42).value).to eq(['42']) }
11
+ specify { expect(described_class.new([42, 43]).value).to eq(%w[42 43]) }
12
+ specify { expect(described_class.new([42, 42]).value).to eq(%w[42 42]) }
13
+ specify { expect(described_class.new([42, [43, 44]]).value).to eq(%w[42 43 44]) }
14
+ specify { expect(described_class.new(a: 1).value).to eq([{'a' => 1}]) }
15
+ specify { expect(described_class.new(['a', {a: 1}, {a: 2}]).value).to eq(['a', {'a' => 1}, {'a' => 2}]) }
16
+ specify { expect(described_class.new(['', 43, {a: 1}]).value).to eq(['43', {'a' => 1}]) }
14
17
  end
15
18
 
16
19
  describe '#replace!' do
17
20
  specify do
18
21
  expect { subject.replace!(foo: {}) }
19
22
  .to change { subject.value }
20
- .from('foo' => nil, 'bar' => nil).to('foo' => {})
23
+ .from(%w[foo bar]).to([{'foo' => {}}])
21
24
  end
22
25
 
23
26
  specify do
24
27
  expect { subject.replace!(nil) }
25
28
  .to change { subject.value }
26
- .from('foo' => nil, 'bar' => nil).to({})
29
+ .from(%w[foo bar]).to([])
27
30
  end
28
31
  end
29
32
 
@@ -31,7 +34,7 @@ describe Chewy::Search::Parameters::Order do
31
34
  specify do
32
35
  expect { subject.update!(foo: {}) }
33
36
  .to change { subject.value }
34
- .from('foo' => nil, 'bar' => nil).to('foo' => {}, 'bar' => nil)
37
+ .from(%w[foo bar]).to(['foo', 'bar', {'foo' => {}}])
35
38
  end
36
39
 
37
40
  specify { expect { subject.update!(nil) }.not_to change { subject.value } }
@@ -41,7 +44,7 @@ describe Chewy::Search::Parameters::Order do
41
44
  specify do
42
45
  expect { subject.merge!(described_class.new(foo: {})) }
43
46
  .to change { subject.value }
44
- .from('foo' => nil, 'bar' => nil).to('foo' => {}, 'bar' => nil)
47
+ .from(%w[foo bar]).to(['foo', 'bar', {'foo' => {}}])
45
48
  end
46
49
 
47
50
  specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value } }
@@ -51,6 +54,7 @@ describe Chewy::Search::Parameters::Order do
51
54
  specify { expect(described_class.new.render).to be_nil }
52
55
  specify { expect(described_class.new(:foo).render).to eq(sort: ['foo']) }
53
56
  specify { expect(described_class.new([:foo, {bar: 42}, :baz]).render).to eq(sort: ['foo', {'bar' => 42}, 'baz']) }
57
+ specify { expect(described_class.new([:foo, {bar: 42}, {bar: 43}, :baz]).render).to eq(sort: ['foo', {'bar' => 42}, {'bar' => 43}, 'baz']) }
54
58
  end
55
59
 
56
60
  describe '#==' do
@@ -59,7 +63,10 @@ describe Chewy::Search::Parameters::Order do
59
63
  specify { expect(described_class.new(:foo)).not_to eq(described_class.new(:bar)) }
60
64
  specify { expect(described_class.new(%i[foo bar])).to eq(described_class.new(%i[foo bar])) }
61
65
  specify { expect(described_class.new(%i[foo bar])).not_to eq(described_class.new(%i[bar foo])) }
66
+ specify { expect(described_class.new(%i[foo foo])).not_to eq(described_class.new(%i[foo])) }
62
67
  specify { expect(described_class.new(foo: {a: 42})).to eq(described_class.new(foo: {a: 42})) }
63
68
  specify { expect(described_class.new(foo: {a: 42})).not_to eq(described_class.new(foo: {b: 42})) }
69
+ specify { expect(described_class.new(['foo', {'foo' => 42}])).not_to eq(described_class.new([{'foo' => 42}, 'foo'])) }
70
+ specify { expect(described_class.new([{'foo' => 42}, {'foo' => 43}])).not_to eq(described_class.new([{'foo' => 43}, {'foo' => 42}])) }
64
71
  end
65
72
  end
@@ -4,19 +4,46 @@ shared_examples :query_storage do |param_name|
4
4
  subject { described_class.new(must: {foo: 'bar'}, should: {moo: 'baz'}) }
5
5
 
6
6
  describe '#initialize' do
7
- specify { expect(described_class.new.value.to_h).to eq(must: [], should: [], must_not: [], minimum_should_match: nil) }
8
- specify { expect(described_class.new(nil).value.to_h).to eq(must: [], should: [], must_not: [], minimum_should_match: nil) }
9
- specify { expect(described_class.new(foobar: {}).value.to_h).to eq(must: [{foobar: {}}], should: [], must_not: [], minimum_should_match: nil) }
10
- specify { expect(described_class.new(must: {}, should: {}, must_not: {}).value.to_h).to eq(must: [], should: [], must_not: [], minimum_should_match: nil) }
7
+ specify do
8
+ expect(described_class.new.value.to_h)
9
+ .to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
10
+ end
11
+ specify do
12
+ expect(described_class.new(nil).value.to_h)
13
+ .to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
14
+ end
15
+ specify do
16
+ expect(described_class.new(foobar: {}).value.to_h)
17
+ .to eq(must: [{foobar: {}}], should: [], must_not: [], minimum_should_match: nil)
18
+ end
19
+ specify do
20
+ expect(described_class.new(must: {}, should: {}, must_not: {}).value.to_h)
21
+ .to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
22
+ end
11
23
  specify do
12
24
  expect(described_class.new(must: {foo: 'bar'}, should: {foo: 'bar'}, foobar: {}).value.to_h)
13
25
  .to eq(must: [{foo: 'bar'}], should: [{foo: 'bar'}], must_not: [], minimum_should_match: nil)
14
26
  end
15
- specify { expect(subject.value.to_h).to eq(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil) }
16
- specify { expect(described_class.new(proc { match foo: 'bar' }).value.to_h).to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil) }
17
- specify { expect(described_class.new(must: proc { match foo: 'bar' }).value.to_h).to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil) }
18
- specify { expect(described_class.new(minimum_should_match: 3).value.to_h).to eq(must: [], should: [], must_not: [], minimum_should_match: 3) }
19
- specify { expect(described_class.new(must: {foo: 'bar'}, minimum_should_match: 3).value.to_h).to eq(must: [{foo: 'bar'}], should: [], must_not: [], minimum_should_match: 3) }
27
+ specify do
28
+ expect(subject.value.to_h)
29
+ .to eq(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
30
+ end
31
+ specify do
32
+ expect(described_class.new(proc { match foo: 'bar' }).value.to_h)
33
+ .to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil)
34
+ end
35
+ specify do
36
+ expect(described_class.new(must: proc { match foo: 'bar' }).value.to_h)
37
+ .to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil)
38
+ end
39
+ specify do
40
+ expect(described_class.new(minimum_should_match: 3).value.to_h)
41
+ .to eq(must: [], should: [], must_not: [], minimum_should_match: 3)
42
+ end
43
+ specify do
44
+ expect(described_class.new(must: {foo: 'bar'}, minimum_should_match: 3).value.to_h)
45
+ .to eq(must: [{foo: 'bar'}], should: [], must_not: [], minimum_should_match: 3)
46
+ end
20
47
  specify do
21
48
  expect(described_class.new(must: [proc { match foo: 'bar' }, {moo: 'baz'}]).value.to_h)
22
49
  .to eq(must: [{match: {foo: 'bar'}}, {moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
@@ -73,14 +100,16 @@ shared_examples :query_storage do |param_name|
73
100
  expect { subject.and(moo: 'baz') }
74
101
  .to change { subject.value.to_h }
75
102
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
76
- .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, {moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
103
+ .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
104
+ {moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
77
105
  end
78
106
 
79
107
  specify do
80
108
  expect { subject.and([{moo: 'baz'}, {doo: 'scooby'}]) }
81
109
  .to change { subject.value.to_h }
82
110
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
83
- .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], should: [], must_not: [], minimum_should_match: nil)
111
+ .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
112
+ bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], should: [], must_not: [], minimum_should_match: nil)
84
113
  end
85
114
 
86
115
  specify do
@@ -93,7 +122,8 @@ shared_examples :query_storage do |param_name|
93
122
  expect { subject.and(should: {foo: 'bar'}) }
94
123
  .to change { subject.value.to_h }
95
124
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
96
- .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, {bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
125
+ .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
126
+ {bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
97
127
  end
98
128
 
99
129
  context do
@@ -113,14 +143,16 @@ shared_examples :query_storage do |param_name|
113
143
  expect { subject.or(moo: 'baz') }
114
144
  .to change { subject.value.to_h }
115
145
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
116
- .to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, {moo: 'baz'}], must_not: [], minimum_should_match: nil)
146
+ .to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
147
+ {moo: 'baz'}], must_not: [], minimum_should_match: nil)
117
148
  end
118
149
 
119
150
  specify do
120
151
  expect { subject.or([{moo: 'baz'}, {doo: 'scooby'}]) }
121
152
  .to change { subject.value.to_h }
122
153
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
123
- .to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], must_not: [], minimum_should_match: nil)
154
+ .to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
155
+ bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], must_not: [], minimum_should_match: nil)
124
156
  end
125
157
 
126
158
  specify do
@@ -133,7 +165,8 @@ shared_examples :query_storage do |param_name|
133
165
  expect { subject.or(should: {foo: 'bar'}) }
134
166
  .to change { subject.value.to_h }
135
167
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
136
- .to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, {bool: {should: {foo: 'bar'}}}], must_not: [], minimum_should_match: nil)
168
+ .to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
169
+ {bool: {should: {foo: 'bar'}}}], must_not: [], minimum_should_match: nil)
137
170
  end
138
171
 
139
172
  context do
@@ -160,7 +193,12 @@ shared_examples :query_storage do |param_name|
160
193
  expect { subject.not([{moo: 'baz'}, {doo: 'scooby'}]) }
161
194
  .to change { subject.value.to_h }
162
195
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
163
- .to(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [{bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}}], minimum_should_match: nil)
196
+ .to(
197
+ must: [{foo: 'bar'}],
198
+ should: [{moo: 'baz'}],
199
+ must_not: [{bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}}],
200
+ minimum_should_match: nil
201
+ )
164
202
  end
165
203
 
166
204
  specify do
@@ -173,7 +211,11 @@ shared_examples :query_storage do |param_name|
173
211
  expect { subject.not(should: {foo: 'bar'}) }
174
212
  .to change { subject.value.to_h }
175
213
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
176
- .to(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [{bool: {should: {foo: 'bar'}}}], minimum_should_match: nil)
214
+ .to(
215
+ must: [{foo: 'bar'}], should: [{moo: 'baz'}],
216
+ must_not: [{bool: {should: {foo: 'bar'}}}],
217
+ minimum_should_match: nil
218
+ )
177
219
  end
178
220
 
179
221
  context do
@@ -223,7 +265,8 @@ shared_examples :query_storage do |param_name|
223
265
  expect { subject.update!(must: proc { match foo: 'bar' }) }
224
266
  .to change { subject.value.to_h }
225
267
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
226
- .to(must: [{foo: 'bar'}, {match: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
268
+ .to(must: [{foo: 'bar'},
269
+ {match: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
227
270
  end
228
271
 
229
272
  specify do
@@ -237,7 +280,8 @@ shared_examples :query_storage do |param_name|
237
280
  expect { subject.update!(foobar: {foo: 'bar'}) }
238
281
  .to change { subject.value.to_h }
239
282
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
240
- .to(must: [{foo: 'bar'}, {foobar: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
283
+ .to(must: [{foo: 'bar'},
284
+ {foobar: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
241
285
  end
242
286
 
243
287
  specify do
@@ -279,7 +323,8 @@ shared_examples :query_storage do |param_name|
279
323
  expect { subject.merge!(described_class.new(moo: 'baz')) }
280
324
  .to change { subject.value.to_h }
281
325
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
282
- .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, {moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
326
+ .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
327
+ {moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
283
328
  end
284
329
 
285
330
  specify do
@@ -292,7 +337,8 @@ shared_examples :query_storage do |param_name|
292
337
  expect { subject.merge!(described_class.new(should: {foo: 'bar'})) }
293
338
  .to change { subject.value.to_h }
294
339
  .from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
295
- .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}}, {bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
340
+ .to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
341
+ {bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
296
342
  end
297
343
 
298
344
  context do
@@ -20,7 +20,10 @@ describe Chewy::Search::Parameters::SearchAfter do
20
20
  end
21
21
 
22
22
  describe '#merge!' do
23
- specify { expect { subject.merge!(described_class.new(:baz)) }.to change { subject.value }.from([:foo, 42]).to([:baz]) }
23
+ specify do
24
+ expect { subject.merge!(described_class.new(:baz)) }
25
+ .to change { subject.value }.from([:foo, 42]).to([:baz])
26
+ end
24
27
  specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from([:foo, 42]) }
25
28
  end
26
29
 
@@ -12,8 +12,14 @@ describe Chewy::Search::Parameters::Source do
12
12
  specify { expect(described_class.new(true).value).to eq(includes: [], excludes: [], enabled: true) }
13
13
  specify { expect(described_class.new(a: 1).value).to eq(includes: [], excludes: [], enabled: true) }
14
14
  specify { expect(described_class.new(includes: :foo).value).to eq(includes: %w[foo], excludes: [], enabled: true) }
15
- specify { expect(described_class.new(includes: :foo, excludes: 42).value).to eq(includes: %w[foo], excludes: %w[42], enabled: true) }
16
- specify { expect(described_class.new(includes: :foo, excludes: 42, enabled: false).value).to eq(includes: %w[foo], excludes: %w[42], enabled: true) }
15
+ specify do
16
+ expect(described_class.new(includes: :foo, excludes: 42).value)
17
+ .to eq(includes: %w[foo], excludes: %w[42], enabled: true)
18
+ end
19
+ specify do
20
+ expect(described_class.new(includes: :foo, excludes: 42, enabled: false).value)
21
+ .to eq(includes: %w[foo], excludes: %w[42], enabled: true)
22
+ end
17
23
  end
18
24
 
19
25
  describe '#replace!' do
@@ -0,0 +1,5 @@
1
+ require 'chewy/search/parameters/bool_storage_examples'
2
+
3
+ describe Chewy::Search::Parameters::TrackTotalHits do
4
+ it_behaves_like :bool_storage, :track_total_hits
5
+ end
@@ -13,7 +13,7 @@ describe Chewy::Search::Parameters do
13
13
 
14
14
  specify { expect(subject.storages[:limit]).to equal(limit) }
15
15
  specify { expect(subject.storages[:limit].value).to eq(3) }
16
- specify { expect(subject.storages[:order].value).to eq('foo' => nil) }
16
+ specify { expect(subject.storages[:order].value).to eq(['foo']) }
17
17
 
18
18
  specify { expect { described_class.new(offset: limit) }.to raise_error(TypeError) }
19
19
  end
@@ -55,7 +55,10 @@ describe Chewy::Search::Parameters do
55
55
  subject { described_class.new(limit: 10, offset: 20, order: :foo) }
56
56
 
57
57
  specify { expect { subject.only!([:limit]) }.to change { subject.clone }.to(described_class.new(limit: 10)) }
58
- specify { expect { subject.only!(%i[offset order]) }.to change { subject.clone }.to(described_class.new(offset: 20, order: :foo)) }
58
+ specify do
59
+ expect { subject.only!(%i[offset order]) }
60
+ .to change { subject.clone }.to(described_class.new(offset: 20, order: :foo))
61
+ end
59
62
  specify { expect { subject.only!(%i[limit something]) }.to raise_error NameError }
60
63
  specify { expect { subject.only!([]) }.to raise_error ArgumentError }
61
64
  end
@@ -63,8 +66,14 @@ describe Chewy::Search::Parameters do
63
66
  describe '#except!' do
64
67
  subject { described_class.new(limit: 10, offset: 20, order: :foo) }
65
68
 
66
- specify { expect { subject.except!([:limit]) }.to change { subject.clone }.to(described_class.new(offset: 20, order: :foo)) }
67
- specify { expect { subject.except!(%i[offset order]) }.to change { subject.clone }.to(described_class.new(limit: 10)) }
69
+ specify do
70
+ expect { subject.except!([:limit]) }
71
+ .to change { subject.clone }.to(described_class.new(offset: 20, order: :foo))
72
+ end
73
+ specify do
74
+ expect { subject.except!(%i[offset order]) }
75
+ .to change { subject.clone }.to(described_class.new(limit: 10))
76
+ end
68
77
  specify { expect { subject.except!(%i[limit something]) }.to raise_error NameError }
69
78
  specify { expect { subject.except!([]) }.to raise_error ArgumentError }
70
79
  end
@@ -72,18 +81,20 @@ describe Chewy::Search::Parameters do
72
81
  describe '#merge!' do
73
82
  let(:first) { described_class.new(offset: 10, order: 'foo') }
74
83
  let(:second) { described_class.new(limit: 20, offset: 20, order: 'bar') }
84
+ let(:first_clone) { first.clone }
85
+ let(:second_clone) { second.clone }
75
86
 
76
87
  specify do
77
88
  expect { first.merge!(second) }.to change { first.clone }
78
89
  .to(described_class.new(limit: 20, offset: 20, order: %w[foo bar]))
79
90
  end
80
- specify { expect { first.merge!(second) }.not_to change { second.clone } }
91
+ specify { expect { first.merge!(second) }.not_to change { second_clone } }
81
92
 
82
93
  specify do
83
94
  expect { second.merge!(first) }.to change { second.clone }
84
95
  .to(described_class.new(limit: 20, offset: 10, order: %w[bar foo]))
85
96
  end
86
- specify { expect { second.merge!(first) }.not_to change { first.clone } }
97
+ specify { expect { second.merge!(first) }.not_to change { first_clone } }
87
98
 
88
99
  context 'spawns new storages for the merge' do
89
100
  let(:names) { %i[limit offset order] }
@@ -117,6 +128,11 @@ describe Chewy::Search::Parameters do
117
128
  specify { expect(subject.render).to eq(body: {}, allow_partial_search_results: true) }
118
129
  end
119
130
 
131
+ context do
132
+ subject { described_class.new(ignore_unavailable: true) }
133
+ specify { expect(subject.render).to eq(body: {}, ignore_unavailable: true) }
134
+ end
135
+
120
136
  context do
121
137
  subject { described_class.new(query: {foo: 'bar'}, filter: {moo: 'baz'}) }
122
138
  specify { expect(subject.render).to eq(body: {query: {bool: {must: {foo: 'bar'}, filter: {moo: 'baz'}}}}) }
@@ -139,7 +155,7 @@ describe Chewy::Search::Parameters do
139
155
 
140
156
  context do
141
157
  subject { described_class.new(filter: {moo: 'baz'}, none: true) }
142
- specify { expect(subject.render).to eq(body: {query: {bool: {filter: {bool: {must_not: {match_all: {}}}}}}}) }
158
+ specify { expect(subject.render).to eq(body: {query: {match_none: {}}}) }
143
159
  end
144
160
  end
145
161
  end