chewy 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +20 -60
- data/Appraisals +15 -40
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -0
- data/Guardfile +5 -5
- data/README.md +155 -6
- data/Rakefile +11 -1
- data/chewy.gemspec +5 -7
- data/gemfiles/rails.3.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/{rails.4.2.mongoid.4.0.0.gemfile → rails.4.2.mongoid.4.0.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.will_paginate.gemfile → rails.4.2.mongoid.4.0.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.gemfile → rails.4.2.mongoid.5.1.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.will_paginate.gemfile → rails.4.2.mongoid.5.1.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.5.0.activerecord.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.will_paginate.gemfile → rails.5.0.activerecord.will_paginate.gemfile} +4 -2
- data/gemfiles/{sequel.4.31.gemfile → sequel.4.38.gemfile} +3 -2
- data/lib/chewy.rb +24 -16
- data/lib/chewy/backports/deep_dup.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -0
- data/lib/chewy/config.rb +13 -7
- data/lib/chewy/errors.rb +4 -4
- data/lib/chewy/fields/base.rb +19 -14
- data/lib/chewy/fields/root.rb +11 -9
- data/lib/chewy/index.rb +38 -25
- data/lib/chewy/index/actions.rb +17 -17
- data/lib/chewy/index/settings.rb +3 -4
- data/lib/chewy/journal.rb +107 -0
- data/lib/chewy/journal/apply.rb +31 -0
- data/lib/chewy/journal/clean.rb +24 -0
- data/lib/chewy/journal/entry.rb +83 -0
- data/lib/chewy/journal/query.rb +87 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/minitest/helpers.rb +77 -0
- data/lib/chewy/minitest/search_index_receiver.rb +80 -0
- data/lib/chewy/query.rb +116 -60
- data/lib/chewy/query/compose.rb +5 -6
- data/lib/chewy/query/criteria.rb +26 -16
- data/lib/chewy/query/filters.rb +9 -9
- data/lib/chewy/query/loading.rb +2 -2
- data/lib/chewy/query/nodes/and.rb +3 -3
- data/lib/chewy/query/nodes/base.rb +1 -1
- data/lib/chewy/query/nodes/bool.rb +6 -4
- data/lib/chewy/query/nodes/equal.rb +6 -6
- data/lib/chewy/query/nodes/exists.rb +2 -2
- data/lib/chewy/query/nodes/expr.rb +2 -2
- data/lib/chewy/query/nodes/field.rb +35 -31
- data/lib/chewy/query/nodes/has_child.rb +1 -0
- data/lib/chewy/query/nodes/has_parent.rb +1 -0
- data/lib/chewy/query/nodes/has_relation.rb +11 -13
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +2 -2
- data/lib/chewy/query/nodes/not.rb +3 -3
- data/lib/chewy/query/nodes/or.rb +3 -3
- data/lib/chewy/query/nodes/prefix.rb +4 -3
- data/lib/chewy/query/nodes/query.rb +3 -3
- data/lib/chewy/query/nodes/range.rb +11 -11
- data/lib/chewy/query/nodes/raw.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +15 -11
- data/lib/chewy/query/nodes/script.rb +6 -6
- data/lib/chewy/query/pagination/will_paginate.rb +2 -2
- data/lib/chewy/railtie.rb +3 -3
- data/lib/chewy/rake_helper.rb +51 -30
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec.rb +1 -1
- data/lib/chewy/rspec/update_index.rb +46 -47
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/search.rb +7 -5
- data/lib/chewy/strategy.rb +10 -8
- data/lib/chewy/strategy/atomic.rb +2 -2
- data/lib/chewy/strategy/base.rb +4 -4
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/sidekiq.rb +2 -0
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/type.rb +51 -45
- data/lib/chewy/type/adapter/active_record.rb +23 -12
- data/lib/chewy/type/adapter/base.rb +4 -4
- data/lib/chewy/type/adapter/mongoid.rb +6 -6
- data/lib/chewy/type/adapter/object.rb +15 -12
- data/lib/chewy/type/adapter/orm.rb +24 -15
- data/lib/chewy/type/adapter/sequel.rb +11 -7
- data/lib/chewy/type/crutch.rb +4 -3
- data/lib/chewy/type/import.rb +51 -32
- data/lib/chewy/type/mapping.rb +17 -17
- data/lib/chewy/type/observe.rb +9 -7
- data/lib/chewy/type/witchcraft.rb +62 -23
- data/lib/chewy/type/wrapper.rb +20 -14
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +28 -23
- data/spec/chewy/config_spec.rb +33 -12
- data/spec/chewy/fields/base_spec.rb +143 -154
- data/spec/chewy/fields/root_spec.rb +22 -20
- data/spec/chewy/fields/time_fields_spec.rb +11 -9
- data/spec/chewy/index/actions_spec.rb +27 -4
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +72 -50
- data/spec/chewy/index_spec.rb +95 -43
- data/spec/chewy/journal/apply_spec.rb +120 -0
- data/spec/chewy/journal/entry_spec.rb +237 -0
- data/spec/chewy/journal_spec.rb +173 -0
- data/spec/chewy/minitest/helpers_spec.rb +90 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
- data/spec/chewy/query/criteria_spec.rb +504 -237
- data/spec/chewy/query/filters_spec.rb +94 -66
- data/spec/chewy/query/loading_spec.rb +76 -40
- data/spec/chewy/query/nodes/and_spec.rb +3 -7
- data/spec/chewy/query/nodes/bool_spec.rb +5 -13
- data/spec/chewy/query/nodes/equal_spec.rb +20 -20
- data/spec/chewy/query/nodes/exists_spec.rb +7 -7
- data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
- data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
- data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
- data/spec/chewy/query/nodes/missing_spec.rb +6 -5
- data/spec/chewy/query/nodes/not_spec.rb +3 -7
- data/spec/chewy/query/nodes/or_spec.rb +3 -7
- data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
- data/spec/chewy/query/nodes/query_spec.rb +3 -3
- data/spec/chewy/query/nodes/range_spec.rb +19 -19
- data/spec/chewy/query/nodes/raw_spec.rb +2 -2
- data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
- data/spec/chewy/query/nodes/script_spec.rb +5 -5
- data/spec/chewy/query/pagination/kaminari_spec.rb +2 -2
- data/spec/chewy/query/pagination/will_paginage_spec.rb +6 -7
- data/spec/chewy/query/pagination_spec.rb +2 -3
- data/spec/chewy/query_spec.rb +208 -145
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/update_index_spec.rb +180 -111
- data/spec/chewy/search_spec.rb +8 -8
- data/spec/chewy/strategy/active_job_spec.rb +2 -2
- data/spec/chewy/strategy/atomic_spec.rb +4 -1
- data/spec/chewy/strategy/resque_spec.rb +2 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +2 -2
- data/spec/chewy/type/actions_spec.rb +1 -1
- data/spec/chewy/type/adapter/active_record_spec.rb +255 -149
- data/spec/chewy/type/adapter/mongoid_spec.rb +169 -108
- data/spec/chewy/type/adapter/object_spec.rb +56 -40
- data/spec/chewy/type/adapter/sequel_spec.rb +248 -163
- data/spec/chewy/type/import_spec.rb +78 -47
- data/spec/chewy/type/mapping_spec.rb +6 -6
- data/spec/chewy/type/observe_spec.rb +20 -14
- data/spec/chewy/type/witchcraft_spec.rb +89 -43
- data/spec/chewy/type_spec.rb +4 -3
- data/spec/chewy_spec.rb +10 -8
- data/spec/spec_helper.rb +3 -0
- data/spec/support/active_record.rb +1 -1
- data/spec/support/class_helpers.rb +10 -11
- data/spec/support/mongoid.rb +2 -2
- data/spec/support/sequel.rb +1 -1
- metadata +65 -35
- data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
@@ -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(
|
17
|
-
specify { expect(subject.analyzers).to eq(
|
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(
|
27
|
-
specify { expect(subject.tokenizers).to eq(
|
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(
|
37
|
-
specify { expect(subject.filters).to eq(
|
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(
|
47
|
-
specify { expect(subject.char_filters).to eq(
|
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: ->(
|
9
|
+
root value: ->(_o) { {} }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
specify { expect {
|
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
|
18
|
-
.
|
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
|
23
|
-
|
24
|
-
|
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
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
specify
|
44
|
-
|
45
|
-
.
|
46
|
-
|
47
|
-
|
48
|
-
.to fail_matching 'to
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
specify
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
80
|
-
|
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
|
86
|
-
|
87
|
-
|
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
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
101
|
-
expect
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
123
|
-
|
124
|
-
|
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
|
127
|
-
|
128
|
-
|
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
|
131
|
-
expect
|
132
|
-
|
133
|
-
|
134
|
-
|
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:
|
138
|
-
[{a:
|
139
|
-
[{a:
|
140
|
-
[{a: {b:
|
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
|
144
|
-
|
145
|
-
|
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:
|
150
|
-
[{a:
|
151
|
-
[{a:
|
152
|
-
[{a: 1}, {a:
|
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
|
156
|
-
expect
|
157
|
-
|
158
|
-
|
159
|
-
|
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
|
165
|
-
|
166
|
-
|
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
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
specify
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
189
|
-
|
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
|
199
|
-
|
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' }
|
data/spec/chewy/search_spec.rb
CHANGED
@@ -71,8 +71,8 @@ describe Chewy::Search do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
let!(:cities) { 3
|
75
|
-
let!(:countries) { 3
|
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],
|
51
|
-
Chewy::Strategy::ActiveJob::Worker.new.perform(
|
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
|