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
@@ -13,8 +13,8 @@ describe Chewy::Repository do
13
13
 
14
14
  context do
15
15
  before { subject.analyzer(:name, option: :foo) }
16
- specify { expect(subject.analyzer(:name)).to eq({option: :foo}) }
17
- specify { expect(subject.analyzers).to eq({name: {option: :foo}}) }
16
+ specify { expect(subject.analyzer(:name)).to eq(option: :foo) }
17
+ specify { expect(subject.analyzers).to eq(name: { option: :foo }) }
18
18
  end
19
19
  end
20
20
 
@@ -23,8 +23,8 @@ describe Chewy::Repository do
23
23
 
24
24
  context do
25
25
  before { subject.tokenizer(:name, option: :foo) }
26
- specify { expect(subject.tokenizer(:name)).to eq({option: :foo}) }
27
- specify { expect(subject.tokenizers).to eq({name: {option: :foo}}) }
26
+ specify { expect(subject.tokenizer(:name)).to eq(option: :foo) }
27
+ specify { expect(subject.tokenizers).to eq(name: { option: :foo }) }
28
28
  end
29
29
  end
30
30
 
@@ -33,8 +33,8 @@ describe Chewy::Repository do
33
33
 
34
34
  context do
35
35
  before { subject.filter(:name, option: :foo) }
36
- specify { expect(subject.filter(:name)).to eq({option: :foo}) }
37
- specify { expect(subject.filters).to eq({name: {option: :foo}}) }
36
+ specify { expect(subject.filter(:name)).to eq(option: :foo) }
37
+ specify { expect(subject.filters).to eq(name: { option: :foo }) }
38
38
  end
39
39
  end
40
40
 
@@ -43,8 +43,8 @@ describe Chewy::Repository do
43
43
 
44
44
  context do
45
45
  before { subject.char_filter(:name, option: :foo) }
46
- specify { expect(subject.char_filter(:name)).to eq({option: :foo}) }
47
- specify { expect(subject.char_filters).to eq({name: {option: :foo}}) }
46
+ specify { expect(subject.char_filter(:name)).to eq(option: :foo) }
47
+ specify { expect(subject.char_filters).to eq(name: { option: :foo }) }
48
48
  end
49
49
  end
50
50
  end
@@ -6,22 +6,25 @@ describe :update_index do
6
6
  before do
7
7
  stub_index(:dummies) do
8
8
  define_type :dummy do
9
- root value: ->(o){{}}
9
+ root value: ->(_o) { {} }
10
10
  end
11
11
  end
12
12
  end
13
13
 
14
- specify { expect { }.not_to update_index(DummiesIndex::Dummy) }
14
+ specify { expect {}.not_to update_index(DummiesIndex::Dummy) }
15
15
  specify { expect { DummiesIndex::Dummy.bulk body: [] }.not_to update_index(DummiesIndex::Dummy) }
16
16
 
17
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex::Dummy) }
18
- .to fail_with(/Expected index .* not to be updated, but it was with/) }
17
+ specify do
18
+ expect { expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42 } }] }.not_to update_index(DummiesIndex::Dummy) }
19
+ .to fail_with(/Expected index .* not to be updated, but it was with/)
20
+ end
19
21
 
20
22
  context do
21
23
  let(:expectation) do
22
- expect { expect {
23
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}, {index: {_id: 41}}, {index: {_id: 42}}]
24
- }.not_to update_index(DummiesIndex::Dummy) }
24
+ expect do
25
+ expect do
26
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42 } }, { index: { _id: 41 } }, { index: { _id: 42 } }]
27
+ end.not_to update_index(DummiesIndex::Dummy) end
25
28
  end
26
29
 
27
30
  specify { expectation.to fail_matching 'document id `42` (2 times)' }
@@ -29,62 +32,107 @@ describe :update_index do
29
32
  end
30
33
 
31
34
  context '#only' do
32
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
33
- .to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only }
34
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
35
- .to update_index(DummiesIndex::Dummy).and_reindex(41).only }
36
- .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also' }
37
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
38
- .to update_index(DummiesIndex::Dummy).and_reindex(41, times: 2).only }
39
- .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also' }
40
-
41
- specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
42
- .to update_index(DummiesIndex::Dummy).and_delete(41, 42).only }
43
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
44
- .to update_index(DummiesIndex::Dummy).and_delete(41).only }
45
- .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also' }
46
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
47
- .to update_index(DummiesIndex::Dummy).and_delete(41, times: 2).only }
48
- .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also' }
49
-
50
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
51
- .to update_index(DummiesIndex::Dummy).and_reindex(42).only }
52
- .to fail_matching 'to update documents ["42"] only, but ["41"] was deleted also' }
53
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}, index: {_id: 43, data: {}}}, {delete: {_id: 41}}] }
54
- .to update_index(DummiesIndex::Dummy).and_reindex(42).only }
55
- .to fail_matching 'to update documents ["42"] only, but ["43"] was updated and ["41"] was deleted also' }
56
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
57
- .to update_index(DummiesIndex::Dummy).and_delete(41).only }
58
- .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated also' }
59
- specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}, delete: {_id: 43}}] }
60
- .to update_index(DummiesIndex::Dummy).and_delete(41).only }
61
- .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated and ["43"] was deleted also' }
35
+ specify do
36
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 41, data: {} } }] }
37
+ .to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only
38
+ end
39
+ specify do
40
+ expect do
41
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 41, data: {} } }] }
42
+ .to update_index(DummiesIndex::Dummy).and_reindex(41).only
43
+ end
44
+ .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
45
+ end
46
+ specify do
47
+ expect do
48
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 41, data: {} } }] }
49
+ .to update_index(DummiesIndex::Dummy).and_reindex(41, times: 2).only
50
+ end
51
+ .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
52
+ end
53
+
54
+ specify do
55
+ expect { DummiesIndex::Dummy.bulk body: [{ delete: { _id: 42 } }, { delete: { _id: 41 } }] }
56
+ .to update_index(DummiesIndex::Dummy).and_delete(41, 42).only
57
+ end
58
+ specify do
59
+ expect do
60
+ expect { DummiesIndex::Dummy.bulk body: [{ delete: { _id: 42 } }, { delete: { _id: 41 } }] }
61
+ .to update_index(DummiesIndex::Dummy).and_delete(41).only
62
+ end
63
+ .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
64
+ end
65
+ specify do
66
+ expect do
67
+ expect { DummiesIndex::Dummy.bulk body: [{ delete: { _id: 42 } }, { delete: { _id: 41 } }] }
68
+ .to update_index(DummiesIndex::Dummy).and_delete(41, times: 2).only
69
+ end
70
+ .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
71
+ end
72
+
73
+ specify do
74
+ expect do
75
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { delete: { _id: 41 } }] }
76
+ .to update_index(DummiesIndex::Dummy).and_reindex(42).only
77
+ end
78
+ .to fail_matching 'to update documents ["42"] only, but ["41"] was deleted also'
79
+ end
80
+ specify do
81
+ expect do
82
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }, { delete: { _id: 41 } }] }
83
+ .to update_index(DummiesIndex::Dummy).and_reindex(42).only
84
+ end
85
+ .to fail_matching 'to update documents ["42"] only, but ["43"] was updated and ["41"] was deleted also'
86
+ end
87
+ specify do
88
+ expect do
89
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { delete: { _id: 41 } }] }
90
+ .to update_index(DummiesIndex::Dummy).and_delete(41).only
91
+ end
92
+ .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated also'
93
+ end
94
+ specify do
95
+ expect do
96
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { delete: { _id: 41 } }, { delete: { _id: 43 } }] }
97
+ .to update_index(DummiesIndex::Dummy).and_delete(41).only
98
+ end
99
+ .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated and ["43"] was deleted also'
100
+ end
62
101
  end
63
102
 
64
103
  context '#and_reindex' do
65
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex::Dummy) }
66
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}] }
67
- .to update_index(DummiesIndex::Dummy).and_reindex(42) }
68
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
69
- .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42)) }
70
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
71
- .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42), double(id: 43)) }
72
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
73
- .to update_index(DummiesIndex::Dummy).and_reindex([double(id: 42), 43]) }
104
+ specify { expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42 } }] }.to update_index(DummiesIndex::Dummy) }
105
+ specify do
106
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }] }
107
+ .to update_index(DummiesIndex::Dummy).and_reindex(42)
108
+ end
109
+ specify do
110
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }] }
111
+ .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42))
112
+ end
113
+ specify do
114
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }] }
115
+ .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42), double(id: 43))
116
+ end
117
+ specify do
118
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }] }
119
+ .to update_index(DummiesIndex::Dummy).and_reindex([double(id: 42), 43])
120
+ end
74
121
 
75
122
  specify do
76
- expect {
77
- expect {
78
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
79
- }.to update_index(DummiesIndex::Dummy).and_reindex([44, 43])
80
- }.to fail_matching 'Expected document with id `44` to be reindexed, but it was not'
123
+ expect do
124
+ expect do
125
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }]
126
+ end.to update_index(DummiesIndex::Dummy).and_reindex([44, 43])
127
+ end.to fail_matching 'Expected document with id `44` to be reindexed, but it was not'
81
128
  end
82
129
 
83
130
  context do
84
131
  let(:expectation) do
85
- expect { expect {
86
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
87
- }.to update_index(DummiesIndex::Dummy).and_reindex(44, double(id: 47)) }
132
+ expect do
133
+ expect do
134
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }]
135
+ end.to update_index(DummiesIndex::Dummy).and_reindex(44, double(id: 47)) end
88
136
  end
89
137
 
90
138
  specify { expectation.to fail_matching('Expected document with id `44` to be reindexed, but it was not') }
@@ -92,23 +140,26 @@ describe :update_index do
92
140
  end
93
141
 
94
142
  context ':times' do
95
- specify { expect {
96
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
97
- DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
98
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, 44, times: 1).and_reindex(43, times: 2) }
143
+ specify do
144
+ expect do
145
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }]
146
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 43, data: {} } }, { index: { _id: 44, data: {} } }]
147
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, 44, times: 1).and_reindex(43, times: 2) end
99
148
 
100
- specify { expect {
101
- expect {
102
- DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
103
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3)
104
- }.to fail_matching('Expected document with id `42` to be reindexed, but it was not') }
149
+ specify do
150
+ expect do
151
+ expect do
152
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 43, data: { a: '1' } } }]
153
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3)
154
+ end.to fail_matching('Expected document with id `42` to be reindexed, but it was not') end
105
155
 
106
156
  context do
107
157
  let(:expectation) do
108
- expect { expect {
109
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
110
- DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
111
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3).and_reindex(44, 43, times: 4) }
158
+ expect do
159
+ expect do
160
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 43, data: {} } }]
161
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 43, data: {} } }, { index: { _id: 44, data: {} } }]
162
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3).and_reindex(44, 43, times: 4) end
112
163
  end
113
164
 
114
165
  specify { expectation.to fail_matching 'Expected document with id `44` to be reindexed' }
@@ -119,51 +170,57 @@ describe :update_index do
119
170
  end
120
171
 
121
172
  context ':with' do
122
- specify { expect {
123
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
124
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: 2}) }
173
+ specify do
174
+ expect do
175
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: { a: '1' } } }, { index: { _id: 42, data: { 'a' => 2 } } }]
176
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: { a: 2 }) end
125
177
 
126
- specify { expect {
127
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'b' => 2}}}]
128
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: '1', b: 2}) }
178
+ specify do
179
+ expect do
180
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: { a: '1' } } }, { index: { _id: 42, data: { 'b' => 2 } } }]
181
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: { a: '1', b: 2 }) end
129
182
 
130
- specify { expect {
131
- expect {
132
- DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
133
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: 1})
134
- }.to fail_matching('Expected document with id `42` to be reindexed, but it was not') }
183
+ specify do
184
+ expect do
185
+ expect do
186
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 43, data: { a: '1' } } }]
187
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: { a: 1 })
188
+ end.to fail_matching('Expected document with id `42` to be reindexed, but it was not') end
135
189
 
136
190
  [
137
- [{a: ['one', 'two']}, {a: ['one', 'two']}],
138
- [{a: ['one', 'two']}, {a: ['two', 'one']}],
139
- [{a: ['one', 'one', 'two']}, {a: ['one', 'two', 'one']}],
140
- [{a: {b: ['one', 'one', 'two']}}, {a: {b: ['one', 'two', 'one']}}],
141
- [{a: 1, b: 1}, {a: 1}]
191
+ [{ a: %w(one two) }, { a: %w(one two) }],
192
+ [{ a: %w(one two) }, { a: %w(two one) }],
193
+ [{ a: %w(one one two) }, { a: %w(one two one) }],
194
+ [{ a: { b: %w(one one two) } }, { a: { b: %w(one two one) } }],
195
+ [{ a: 1, b: 1 }, { a: 1 }]
142
196
  ].each do |(data, with)|
143
- specify { expect {
144
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
145
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with) }
197
+ specify do
198
+ expect do
199
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: data } }]
200
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with) end
146
201
  end
147
202
 
148
203
  [
149
- [{a: ['one', 'two']}, {a: ['one', 'one', 'two']}],
150
- [{a: ['one', 'one', 'two']}, {a: ['one', 'two']}],
151
- [{a: ['one', 'two']}, {a: 1}],
152
- [{a: 1}, {a: ['one', 'two']}],
153
- [{a: 1}, {a: 1, b: 1}]
204
+ [{ a: %w(one two) }, { a: %w(one one two) }],
205
+ [{ a: %w(one one two) }, { a: %w(one two) }],
206
+ [{ a: %w(one two) }, { a: 1 }],
207
+ [{ a: 1 }, { a: %w(one two) }],
208
+ [{ a: 1 }, { a: 1, b: 1 }]
154
209
  ].each do |(data, with)|
155
- specify { expect {
156
- expect {
157
- DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
158
- }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with)
159
- }.to fail_matching('Expected document with id `42` to be reindexed') }
210
+ specify do
211
+ expect do
212
+ expect do
213
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: data } }]
214
+ end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with)
215
+ end.to fail_matching('Expected document with id `42` to be reindexed') end
160
216
  end
161
217
 
162
218
  context do
163
219
  let(:expectation) do
164
- expect { expect {
165
- DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
166
- }.to update_index(DummiesIndex::Dummy).and_reindex(43, times: 2, with: {a: 2}) }
220
+ expect do
221
+ expect do
222
+ DummiesIndex::Dummy.bulk body: [{ index: { _id: 43, data: { a: '1' } } }, { index: { _id: 42, data: { 'a' => 2 } } }]
223
+ end.to update_index(DummiesIndex::Dummy).and_reindex(43, times: 2, with: { a: 2 }) end
167
224
  end
168
225
 
169
226
  specify { expectation.to fail_matching 'Expected document with id `43` to be reindexed' }
@@ -174,19 +231,29 @@ describe :update_index do
174
231
  end
175
232
 
176
233
  context '#and_delete' do
177
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
178
- .to update_index(DummiesIndex::Dummy).and_reindex(42).and_delete(double(id: 43)) }
179
- specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
180
- .to update_index(DummiesIndex::Dummy).and_delete(42).and_delete(double(id: 43)) }
181
- specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
182
- .to update_index(DummiesIndex::Dummy).and_delete(42, double(id: 43)) }
183
- specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
184
- .to update_index(DummiesIndex::Dummy).and_delete([43, double(id: 42)]) }
234
+ specify do
235
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { delete: { _id: 43 } }] }
236
+ .to update_index(DummiesIndex::Dummy).and_reindex(42).and_delete(double(id: 43))
237
+ end
238
+ specify do
239
+ expect { DummiesIndex::Dummy.bulk body: [{ delete: { _id: 42 } }, { delete: { _id: 43 } }] }
240
+ .to update_index(DummiesIndex::Dummy).and_delete(42).and_delete(double(id: 43))
241
+ end
242
+ specify do
243
+ expect { DummiesIndex::Dummy.bulk body: [{ delete: { _id: 42 } }, { delete: { _id: 43 } }] }
244
+ .to update_index(DummiesIndex::Dummy).and_delete(42, double(id: 43))
245
+ end
246
+ specify do
247
+ expect { DummiesIndex::Dummy.bulk body: [{ delete: { _id: 42 } }, { delete: { _id: 43 } }] }
248
+ .to update_index(DummiesIndex::Dummy).and_delete([43, double(id: 42)])
249
+ end
185
250
 
186
251
  context do
187
252
  let(:expectation) do
188
- expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
189
- .to update_index(DummiesIndex::Dummy).and_reindex(43).and_delete(double(id: 42)) }
253
+ expect do
254
+ expect { DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { delete: { _id: 43 } }] }
255
+ .to update_index(DummiesIndex::Dummy).and_reindex(43).and_delete(double(id: 42))
256
+ end
190
257
  end
191
258
 
192
259
  specify { expectation.to fail_matching 'Expected document with id `43` to be reindexed, but it was not' }
@@ -195,8 +262,10 @@ describe :update_index do
195
262
 
196
263
  context do
197
264
  let(:expectation) do
198
- expect { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42, data: {}}}, {delete: {_id: 42}}] }
199
- .to update_index(DummiesIndex::Dummy).and_delete(44, times: 2).and_delete(double(id: 42), times: 3) }
265
+ expect do
266
+ expect { DummiesIndex::Dummy.bulk body: [{ delete: { _id: 42, data: {} } }, { delete: { _id: 42 } }] }
267
+ .to update_index(DummiesIndex::Dummy).and_delete(44, times: 2).and_delete(double(id: 42), times: 3)
268
+ end
200
269
  end
201
270
 
202
271
  specify { expectation.to fail_matching 'Expected document with id `44` to be deleted, but it was not' }
@@ -71,8 +71,8 @@ describe Chewy::Search do
71
71
  end
72
72
  end
73
73
 
74
- let!(:cities) { 3.times.map { |i| City.create! rating: i + 1, name: "Name#{i+1}" } }
75
- let!(:countries) { 3.times.map { |i| Country.create! rating: i + 1, name: "Name#{i+4}" } }
74
+ let!(:cities) { Array.new(3) { |i| City.create! rating: i + 1, name: "Name#{i + 1}" } }
75
+ let!(:countries) { Array.new(3) { |i| Country.create! rating: i + 1, name: "Name#{i + 4}" } }
76
76
 
77
77
  before { PlacesIndex.import! city: cities, country: countries }
78
78
 
@@ -83,12 +83,12 @@ describe Chewy::Search do
83
83
  specify { expect(PlacesIndex.order(:name).by_rating(1).map(&:rating)).to eq([1, 1]) }
84
84
  specify { expect(PlacesIndex.order(:name).by_rating(1).map(&:class)).to match_array([PlacesIndex::City, PlacesIndex::Country]) }
85
85
 
86
- specify { expect(PlacesIndex::City.by_rating {2}.map(&:rating)).to eq([2]) }
87
- specify { expect(PlacesIndex::City.by_rating {2}.map(&:class)).to eq([PlacesIndex::City]) }
88
- specify { expect(PlacesIndex::City.by_rating {2}.by_name(2).map(&:rating)).to eq([2]) }
89
- specify { expect(PlacesIndex::City.by_rating {2}.by_name(2).map(&:class)).to eq([PlacesIndex::City]) }
90
- specify { expect(PlacesIndex::City.order(:name).by_rating {2}.map(&:rating)).to eq([2]) }
91
- specify { expect(PlacesIndex::City.order(:name).by_rating {2}.map(&:class)).to eq([PlacesIndex::City]) }
86
+ specify { expect(PlacesIndex::City.by_rating { 2 }.map(&:rating)).to eq([2]) }
87
+ specify { expect(PlacesIndex::City.by_rating { 2 }.map(&:class)).to eq([PlacesIndex::City]) }
88
+ specify { expect(PlacesIndex::City.by_rating { 2 }.by_name(2).map(&:rating)).to eq([2]) }
89
+ specify { expect(PlacesIndex::City.by_rating { 2 }.by_name(2).map(&:class)).to eq([PlacesIndex::City]) }
90
+ specify { expect(PlacesIndex::City.order(:name).by_rating { 2 }.map(&:rating)).to eq([2]) }
91
+ specify { expect(PlacesIndex::City.order(:name).by_rating { 2 }.map(&:class)).to eq([PlacesIndex::City]) }
92
92
 
93
93
  specify { expect(PlacesIndex::Country.by_rating(3).map(&:rating)).to eq([3]) }
94
94
  specify { expect(PlacesIndex::Country.by_rating(3).map(&:class)).to eq([PlacesIndex::Country]) }
@@ -47,8 +47,8 @@ if defined?(::ActiveJob)
47
47
  end
48
48
 
49
49
  specify do
50
- expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], {suffix: '201601'})
51
- Chewy::Strategy::ActiveJob::Worker.new.perform("CitiesIndex::City", [city.id, other_city.id], suffix: '201601')
50
+ expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
51
+ Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex::City', [city.id, other_city.id], suffix: '201601')
52
52
  end
53
53
  end
54
54
  end