chewy 7.1.0 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +58 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -7
- data/Guardfile +3 -1
- data/README.md +282 -245
- data/chewy.gemspec +3 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
- data/lib/chewy.rb +21 -75
- data/lib/chewy/config.rb +40 -40
- data/lib/chewy/errors.rb +0 -12
- data/lib/chewy/fields/base.rb +11 -1
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +46 -87
- data/lib/chewy/index/actions.rb +51 -32
- data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
- data/lib/chewy/{type → index}/crutch.rb +5 -5
- data/lib/chewy/{type → index}/import.rb +36 -27
- data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
- data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
- data/lib/chewy/{type → index}/import/routine.rb +15 -14
- data/lib/chewy/{type → index}/mapping.rb +26 -31
- data/lib/chewy/{type → index}/observe.rb +9 -19
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +60 -57
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/journal.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +9 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/railtie.rb +4 -2
- data/lib/chewy/rake_helper.rb +82 -107
- data/lib/chewy/rspec/update_index.rb +47 -43
- data/lib/chewy/search.rb +4 -17
- data/lib/chewy/search/loader.rb +18 -30
- data/lib/chewy/search/parameters.rb +4 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +82 -86
- data/lib/chewy/search/response.rb +4 -4
- data/lib/chewy/search/scoping.rb +6 -7
- data/lib/chewy/search/scrolling.rb +11 -11
- data/lib/chewy/stash.rb +14 -22
- data/lib/chewy/strategy.rb +3 -19
- data/lib/chewy/strategy/sidekiq.rb +1 -0
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +10 -22
- data/migration_guide.md +14 -0
- data/spec/chewy/config_spec.rb +14 -39
- data/spec/chewy/fields/base_spec.rb +412 -148
- data/spec/chewy/fields/root_spec.rb +16 -24
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +270 -24
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
- data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
- data/spec/chewy/{type → index}/import_spec.rb +102 -98
- data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
- data/spec/chewy/index/observe_spec.rb +116 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +7 -17
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +59 -102
- data/spec/chewy/journal_spec.rb +9 -22
- data/spec/chewy/minitest/helpers_spec.rb +13 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +145 -55
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/search/loader_spec.rb +19 -37
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/indices_spec.rb +2 -8
- data/spec/chewy/search/parameters/order_spec.rb +1 -1
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters_spec.rb +12 -3
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +222 -74
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +7 -9
- data/spec/chewy/search_spec.rb +32 -35
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +14 -100
- data/spec/spec_helper.rb +2 -21
- data/spec/support/active_record.rb +15 -5
- metadata +44 -103
- data/.circleci/config.yml +0 -214
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type.rb +0 -120
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
@@ -18,54 +18,52 @@ describe :minitest_helper do
|
|
18
18
|
|
19
19
|
before do
|
20
20
|
stub_index(:dummies) do
|
21
|
-
|
22
|
-
root value: ->(_o) { {} }
|
23
|
-
end
|
21
|
+
root value: ->(_o) { {} }
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
25
|
context 'assert_indexes' do
|
28
26
|
specify 'doesn\'t fail when index updates correctly' do
|
29
27
|
expect do
|
30
|
-
assert_indexes DummiesIndex
|
31
|
-
DummiesIndex
|
28
|
+
assert_indexes DummiesIndex do
|
29
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
32
30
|
end
|
33
31
|
end.to_not raise_error
|
34
32
|
end
|
35
33
|
|
36
34
|
specify 'fails when index doesn\'t update' do
|
37
35
|
expect do
|
38
|
-
assert_indexes DummiesIndex
|
36
|
+
assert_indexes DummiesIndex do
|
39
37
|
end
|
40
38
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
41
39
|
end
|
42
40
|
|
43
41
|
specify 'SearchIndexReceiver catches the indexes' do
|
44
|
-
receiver = assert_indexes DummiesIndex
|
45
|
-
DummiesIndex
|
42
|
+
receiver = assert_indexes DummiesIndex do
|
43
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
46
44
|
end
|
47
45
|
|
48
46
|
expect(receiver).to be_a(SearchIndexReceiver)
|
49
47
|
|
50
48
|
expect(
|
51
|
-
receiver.indexes_for(DummiesIndex
|
49
|
+
receiver.indexes_for(DummiesIndex)
|
52
50
|
.map { |index| index[:_id] }
|
53
51
|
).to match_array([41, 42])
|
54
52
|
end
|
55
53
|
|
56
54
|
specify 'Real index is bypassed when asserting' do
|
57
|
-
expect(DummiesIndex
|
55
|
+
expect(DummiesIndex).not_to receive(:bulk)
|
58
56
|
|
59
|
-
assert_indexes DummiesIndex
|
60
|
-
DummiesIndex
|
57
|
+
assert_indexes DummiesIndex do
|
58
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
64
62
|
specify 'Real index is allowed when asserting' do
|
65
|
-
expect(DummiesIndex
|
63
|
+
expect(DummiesIndex).to receive(:bulk)
|
66
64
|
|
67
|
-
assert_indexes DummiesIndex
|
68
|
-
DummiesIndex
|
65
|
+
assert_indexes DummiesIndex, bypass_actual_index: false do
|
66
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
69
67
|
end
|
70
68
|
end
|
71
69
|
end
|
@@ -26,97 +26,93 @@ describe :search_index_receiver do
|
|
26
26
|
|
27
27
|
before do
|
28
28
|
stub_index(:dummies) do
|
29
|
-
|
30
|
-
root value: ->(_o) { {} }
|
31
|
-
end
|
29
|
+
root value: ->(_o) { {} }
|
32
30
|
end
|
33
31
|
|
34
32
|
stub_index(:dummies2) do
|
35
|
-
|
36
|
-
root value: ->(_o) { {} }
|
37
|
-
end
|
33
|
+
root value: ->(_o) { {} }
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
37
|
context 'catch' do
|
42
38
|
specify 'archives more than one type' do
|
43
|
-
receiver.catch search_request(2), DummiesIndex
|
44
|
-
receiver.catch search_request(3), Dummies2Index
|
45
|
-
expect(receiver.indexes.keys).to match_array([DummiesIndex
|
39
|
+
receiver.catch search_request(2), DummiesIndex
|
40
|
+
receiver.catch search_request(3), Dummies2Index
|
41
|
+
expect(receiver.indexes.keys).to match_array([DummiesIndex, Dummies2Index])
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
49
45
|
context 'indexes_for' do
|
50
46
|
before do
|
51
|
-
receiver.catch search_request(2), DummiesIndex
|
52
|
-
receiver.catch search_request(3), Dummies2Index
|
47
|
+
receiver.catch search_request(2), DummiesIndex
|
48
|
+
receiver.catch search_request(3), Dummies2Index
|
53
49
|
end
|
54
50
|
|
55
51
|
specify 'returns indexes for a specific type' do
|
56
|
-
expect(parse_request(receiver.indexes_for(DummiesIndex
|
52
|
+
expect(parse_request(receiver.indexes_for(DummiesIndex))).to match_array([1, 2])
|
57
53
|
end
|
58
54
|
|
59
55
|
specify 'returns only indexes for all types' do
|
60
56
|
index_responses = receiver.indexes
|
61
|
-
expect(index_responses.keys).to match_array([DummiesIndex
|
57
|
+
expect(index_responses.keys).to match_array([DummiesIndex, Dummies2Index])
|
62
58
|
expect(parse_request(index_responses.values.flatten)).to match_array([1, 2, 1, 2, 3])
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
66
62
|
context 'deletes_for' do
|
67
63
|
before do
|
68
|
-
receiver.catch search_request(2, verb: :delete), DummiesIndex
|
69
|
-
receiver.catch search_request(3, verb: :delete), Dummies2Index
|
64
|
+
receiver.catch search_request(2, verb: :delete), DummiesIndex
|
65
|
+
receiver.catch search_request(3, verb: :delete), Dummies2Index
|
70
66
|
end
|
71
67
|
|
72
68
|
specify 'returns deletes for a specific type' do
|
73
|
-
expect(receiver.deletes_for(Dummies2Index
|
69
|
+
expect(receiver.deletes_for(Dummies2Index)).to match_array([1, 2, 3])
|
74
70
|
end
|
75
71
|
|
76
72
|
specify 'returns only deletes for all types' do
|
77
73
|
deletes = receiver.deletes
|
78
|
-
expect(deletes.keys).to match_array([DummiesIndex
|
74
|
+
expect(deletes.keys).to match_array([DummiesIndex, Dummies2Index])
|
79
75
|
expect(deletes.values.flatten).to match_array([1, 2, 1, 2, 3])
|
80
76
|
end
|
81
77
|
end
|
82
78
|
|
83
79
|
context 'indexed?' do
|
84
80
|
before do
|
85
|
-
receiver.catch search_request(1), DummiesIndex
|
81
|
+
receiver.catch search_request(1), DummiesIndex
|
86
82
|
end
|
87
83
|
|
88
84
|
specify 'validates that an object was indexed' do
|
89
85
|
dummy = OpenStruct.new(id: 1)
|
90
|
-
expect(receiver.indexed?(dummy, DummiesIndex
|
86
|
+
expect(receiver.indexed?(dummy, DummiesIndex)).to be(true)
|
91
87
|
end
|
92
88
|
|
93
89
|
specify 'doesn\'t validate than unindexed objects were indexed' do
|
94
90
|
dummy = OpenStruct.new(id: 2)
|
95
|
-
expect(receiver.indexed?(dummy, DummiesIndex
|
91
|
+
expect(receiver.indexed?(dummy, DummiesIndex)).to be(false)
|
96
92
|
end
|
97
93
|
end
|
98
94
|
|
99
95
|
context 'deleted?' do
|
100
96
|
before do
|
101
|
-
receiver.catch search_request(1, verb: :delete), DummiesIndex
|
97
|
+
receiver.catch search_request(1, verb: :delete), DummiesIndex
|
102
98
|
end
|
103
99
|
|
104
100
|
specify 'validates than an object was deleted' do
|
105
101
|
dummy = OpenStruct.new(id: 1)
|
106
|
-
expect(receiver.deleted?(dummy, DummiesIndex
|
102
|
+
expect(receiver.deleted?(dummy, DummiesIndex)).to be(true)
|
107
103
|
end
|
108
104
|
|
109
105
|
specify 'doesn\'t validate than undeleted objects were deleted' do
|
110
106
|
dummy = OpenStruct.new(id: 2)
|
111
|
-
expect(receiver.deleted?(dummy, DummiesIndex
|
107
|
+
expect(receiver.deleted?(dummy, DummiesIndex)).to be(false)
|
112
108
|
end
|
113
109
|
end
|
114
110
|
|
115
111
|
context 'updated_indexes' do
|
116
112
|
specify 'provides a list of indices updated' do
|
117
|
-
receiver.catch search_request(2, verb: :delete), DummiesIndex
|
118
|
-
receiver.catch search_request(3, verb: :delete), Dummies2Index
|
119
|
-
expect(receiver.updated_indexes).to match_array([DummiesIndex
|
113
|
+
receiver.catch search_request(2, verb: :delete), DummiesIndex
|
114
|
+
receiver.catch search_request(3, verb: :delete), Dummies2Index
|
115
|
+
expect(receiver.updated_indexes).to match_array([DummiesIndex, Dummies2Index])
|
120
116
|
end
|
121
117
|
end
|
122
118
|
end
|
@@ -13,10 +13,9 @@ describe Chewy::MultiSearch do
|
|
13
13
|
aggs(country: {terms: {field: :country_id}})
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
index_scope City
|
17
|
+
field :name, type: 'keyword'
|
18
|
+
field :country_id, type: 'keyword'
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
@@ -78,7 +77,7 @@ describe Chewy::MultiSearch do
|
|
78
77
|
is_expected.to have(2).responses
|
79
78
|
expect(responses[0]).to be_a(Chewy::Search::Response)
|
80
79
|
expect(responses[1]).to be_a(Chewy::Search::Response)
|
81
|
-
expect(responses[1].wrappers).to all(be_a CitiesIndex
|
80
|
+
expect(responses[1].wrappers).to all(be_a CitiesIndex)
|
82
81
|
end
|
83
82
|
end
|
84
83
|
end
|
@@ -8,13 +8,12 @@ describe Chewy::RakeHelper, :orm do
|
|
8
8
|
stub_model(:country)
|
9
9
|
|
10
10
|
stub_index(:cities) do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
11
|
+
index_scope City
|
12
|
+
field :name
|
13
|
+
field :updated_at, type: 'date'
|
15
14
|
end
|
16
15
|
stub_index(:countries) do
|
17
|
-
|
16
|
+
index_scope Country
|
18
17
|
end
|
19
18
|
stub_index(:users)
|
20
19
|
|
@@ -52,17 +51,18 @@ describe Chewy::RakeHelper, :orm do
|
|
52
51
|
.to update_index(CitiesIndex)
|
53
52
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
54
53
|
\\AResetting CitiesIndex
|
55
|
-
Imported CitiesIndex
|
56
|
-
Applying journal to \\[CitiesIndex
|
57
|
-
Imported CitiesIndex
|
58
|
-
Imported Chewy::Stash::Specification
|
54
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
55
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
56
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
57
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
59
58
|
Resetting CountriesIndex
|
60
|
-
Imported CountriesIndex
|
61
|
-
Applying journal to \\[CountriesIndex
|
62
|
-
Imported CountriesIndex
|
63
|
-
Imported Chewy::Stash::Specification
|
59
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
60
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
61
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
62
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
64
63
|
Resetting UsersIndex
|
65
|
-
Imported
|
64
|
+
Imported UsersIndex in 1s, stats:\s
|
65
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
66
66
|
Total: \\d+s\\Z
|
67
67
|
OUTPUT
|
68
68
|
end
|
@@ -73,10 +73,10 @@ Total: \\d+s\\Z
|
|
73
73
|
.to update_index(CitiesIndex)
|
74
74
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
75
75
|
\\AResetting CitiesIndex
|
76
|
-
Imported CitiesIndex
|
77
|
-
Applying journal to \\[CitiesIndex
|
78
|
-
Imported CitiesIndex
|
79
|
-
Imported Chewy::Stash::Specification
|
76
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
77
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
78
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
79
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
80
80
|
Total: \\d+s\\Z
|
81
81
|
OUTPUT
|
82
82
|
end
|
@@ -87,7 +87,8 @@ Total: \\d+s\\Z
|
|
87
87
|
.not_to update_index(CitiesIndex)
|
88
88
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
89
89
|
\\AResetting UsersIndex
|
90
|
-
Imported
|
90
|
+
Imported UsersIndex in 1s, stats:\s
|
91
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
91
92
|
Total: \\d+s\\Z
|
92
93
|
OUTPUT
|
93
94
|
end
|
@@ -100,13 +101,14 @@ Total: \\d+s\\Z
|
|
100
101
|
.to update_index(CitiesIndex)
|
101
102
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
102
103
|
\\AResetting CitiesIndex
|
103
|
-
Imported CitiesIndex
|
104
|
-
Imported Chewy::Stash::Specification
|
104
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
105
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
105
106
|
Resetting CountriesIndex
|
106
|
-
Imported CountriesIndex
|
107
|
-
Imported Chewy::Stash::Specification
|
107
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
108
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
108
109
|
Resetting UsersIndex
|
109
|
-
Imported
|
110
|
+
Imported UsersIndex in 1s, stats:\s
|
111
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
110
112
|
Total: \\d+s\\Z
|
111
113
|
OUTPUT
|
112
114
|
end
|
@@ -125,7 +127,8 @@ Total: \\d+s\\Z
|
|
125
127
|
\\ASkipping CitiesIndex, the specification didn't change
|
126
128
|
Skipping CountriesIndex, the specification didn't change
|
127
129
|
Resetting UsersIndex
|
128
|
-
Imported
|
130
|
+
Imported UsersIndex in 1s, stats:\s
|
131
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
129
132
|
Total: \\d+s\\Z
|
130
133
|
OUTPUT
|
131
134
|
end
|
@@ -136,7 +139,8 @@ Total: \\d+s\\Z
|
|
136
139
|
.not_to update_index(CitiesIndex)
|
137
140
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
138
141
|
\\AResetting UsersIndex
|
139
|
-
Imported
|
142
|
+
Imported UsersIndex in 1s, stats:\s
|
143
|
+
Imported Chewy::Stash::Specification in \\d+s, stats: index 1
|
140
144
|
Total: \\d+s\\Z
|
141
145
|
OUTPUT
|
142
146
|
end
|
@@ -165,6 +169,7 @@ Total: \\d+s\\Z
|
|
165
169
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
166
170
|
\\ASkipping CitiesIndex, it does not exists \\(use rake chewy:reset\\[cities\\] to create and update it\\)
|
167
171
|
Skipping CountriesIndex, it does not exists \\(use rake chewy:reset\\[countries\\] to create and update it\\)
|
172
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
168
173
|
Total: \\d+s\\Z
|
169
174
|
OUTPUT
|
170
175
|
end
|
@@ -181,9 +186,10 @@ Total: \\d+s\\Z
|
|
181
186
|
.to update_index(CitiesIndex)
|
182
187
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
183
188
|
\\AUpdating CitiesIndex
|
184
|
-
Imported CitiesIndex
|
189
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
185
190
|
Updating CountriesIndex
|
186
|
-
Imported CountriesIndex
|
191
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
192
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
187
193
|
Total: \\d+s\\Z
|
188
194
|
OUTPUT
|
189
195
|
end
|
@@ -194,7 +200,7 @@ Total: \\d+s\\Z
|
|
194
200
|
.not_to update_index(CitiesIndex)
|
195
201
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
196
202
|
\\AUpdating CountriesIndex
|
197
|
-
Imported CountriesIndex
|
203
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
198
204
|
Total: \\d+s\\Z
|
199
205
|
OUTPUT
|
200
206
|
end
|
@@ -205,7 +211,8 @@ Total: \\d+s\\Z
|
|
205
211
|
.to update_index(CitiesIndex)
|
206
212
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
207
213
|
\\AUpdating CitiesIndex
|
208
|
-
Imported CitiesIndex
|
214
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
215
|
+
Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
|
209
216
|
Total: \\d+s\\Z
|
210
217
|
OUTPUT
|
211
218
|
end
|
@@ -218,15 +225,19 @@ Total: \\d+s\\Z
|
|
218
225
|
expect { described_class.sync(output: output) }
|
219
226
|
.to update_index(CitiesIndex)
|
220
227
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
221
|
-
\\ASynchronizing CitiesIndex
|
222
|
-
Imported CitiesIndex
|
228
|
+
\\ASynchronizing CitiesIndex
|
229
|
+
Imported CitiesIndex in \\d+s, stats: index 3
|
223
230
|
Missing documents: \\[[^\\]]+\\]
|
224
231
|
Took \\d+s
|
225
|
-
Synchronizing CountriesIndex
|
226
|
-
CountriesIndex
|
227
|
-
Imported CountriesIndex
|
232
|
+
Synchronizing CountriesIndex
|
233
|
+
CountriesIndex doesn't support outdated synchronization
|
234
|
+
Imported CountriesIndex in \\d+s, stats: index 2
|
228
235
|
Missing documents: \\[[^\\]]+\\]
|
229
236
|
Took \\d+s
|
237
|
+
Synchronizing UsersIndex
|
238
|
+
UsersIndex doesn't support outdated synchronization
|
239
|
+
Skipping UsersIndex, up to date
|
240
|
+
Took \\d+s
|
230
241
|
Total: \\d+s\\Z
|
231
242
|
OUTPUT
|
232
243
|
end
|
@@ -236,7 +247,6 @@ Total: \\d+s\\Z
|
|
236
247
|
CitiesIndex.import(cities.first(2))
|
237
248
|
CountriesIndex.import
|
238
249
|
|
239
|
-
sleep(1) if ActiveSupport::VERSION::STRING < '4.1.0'
|
240
250
|
cities.first.update(name: 'Name5')
|
241
251
|
end
|
242
252
|
|
@@ -245,14 +255,18 @@ Total: \\d+s\\Z
|
|
245
255
|
expect { described_class.sync(output: output) }
|
246
256
|
.to update_index(CitiesIndex)
|
247
257
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
248
|
-
\\ASynchronizing CitiesIndex
|
249
|
-
Imported CitiesIndex
|
258
|
+
\\ASynchronizing CitiesIndex
|
259
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
250
260
|
Missing documents: \\["#{cities.last.id}"\\]
|
251
261
|
Outdated documents: \\["#{cities.first.id}"\\]
|
252
262
|
Took \\d+s
|
253
|
-
Synchronizing CountriesIndex
|
254
|
-
CountriesIndex
|
255
|
-
Skipping CountriesIndex
|
263
|
+
Synchronizing CountriesIndex
|
264
|
+
CountriesIndex doesn't support outdated synchronization
|
265
|
+
Skipping CountriesIndex, up to date
|
266
|
+
Took \\d+s
|
267
|
+
Synchronizing UsersIndex
|
268
|
+
UsersIndex doesn't support outdated synchronization
|
269
|
+
Skipping UsersIndex, up to date
|
256
270
|
Took \\d+s
|
257
271
|
Total: \\d+s\\Z
|
258
272
|
OUTPUT
|
@@ -263,8 +277,8 @@ Total: \\d+s\\Z
|
|
263
277
|
expect { described_class.sync(only: CitiesIndex, output: output) }
|
264
278
|
.to update_index(CitiesIndex)
|
265
279
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
266
|
-
\\ASynchronizing CitiesIndex
|
267
|
-
Imported CitiesIndex
|
280
|
+
\\ASynchronizing CitiesIndex
|
281
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
268
282
|
Missing documents: \\["#{cities.last.id}"\\]
|
269
283
|
Outdated documents: \\["#{cities.first.id}"\\]
|
270
284
|
Took \\d+s
|
@@ -277,9 +291,13 @@ Total: \\d+s\\Z
|
|
277
291
|
expect { described_class.sync(except: ['cities'], output: output) }
|
278
292
|
.not_to update_index(CitiesIndex)
|
279
293
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
280
|
-
\\ASynchronizing CountriesIndex
|
281
|
-
CountriesIndex
|
282
|
-
Skipping CountriesIndex
|
294
|
+
\\ASynchronizing CountriesIndex
|
295
|
+
CountriesIndex doesn't support outdated synchronization
|
296
|
+
Skipping CountriesIndex, up to date
|
297
|
+
Took \\d+s
|
298
|
+
Synchronizing UsersIndex
|
299
|
+
UsersIndex doesn't support outdated synchronization
|
300
|
+
Skipping UsersIndex, up to date
|
283
301
|
Took \\d+s
|
284
302
|
Total: \\d+s\\Z
|
285
303
|
OUTPUT
|
@@ -308,9 +326,9 @@ Total: \\d+s\\Z
|
|
308
326
|
.to update_index(CitiesIndex)
|
309
327
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
310
328
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
311
|
-
Applying journal to \\[CitiesIndex
|
312
|
-
Imported CitiesIndex
|
313
|
-
Imported CountriesIndex
|
329
|
+
Applying journal to \\[CitiesIndex, CountriesIndex\\], 3 entries, stage 1
|
330
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
331
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
314
332
|
Total: \\d+s\\Z
|
315
333
|
OUTPUT
|
316
334
|
end
|
@@ -321,8 +339,8 @@ Total: \\d+s\\Z
|
|
321
339
|
.not_to update_index(CitiesIndex)
|
322
340
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
323
341
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
324
|
-
Applying journal to \\[CountriesIndex
|
325
|
-
Imported CountriesIndex
|
342
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
343
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
326
344
|
Total: \\d+s\\Z
|
327
345
|
OUTPUT
|
328
346
|
end
|
@@ -333,8 +351,8 @@ Total: \\d+s\\Z
|
|
333
351
|
.to update_index(CitiesIndex)
|
334
352
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
335
353
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
336
|
-
Applying journal to \\[CitiesIndex
|
337
|
-
Imported CitiesIndex
|
354
|
+
Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
|
355
|
+
Imported CitiesIndex in \\d+s, stats: index 2
|
338
356
|
Total: \\d+s\\Z
|
339
357
|
OUTPUT
|
340
358
|
end
|
@@ -345,8 +363,8 @@ Total: \\d+s\\Z
|
|
345
363
|
.not_to update_index(CitiesIndex)
|
346
364
|
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
347
365
|
\\AApplying journal entries created after [+-:\\d\\s]+
|
348
|
-
Applying journal to \\[CountriesIndex
|
349
|
-
Imported CountriesIndex
|
366
|
+
Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
|
367
|
+
Imported CountriesIndex in \\d+s, stats: index 1
|
350
368
|
Total: \\d+s\\Z
|
351
369
|
OUTPUT
|
352
370
|
end
|
@@ -393,4 +411,76 @@ Total: \\d+s\\Z
|
|
393
411
|
OUTPUT
|
394
412
|
end
|
395
413
|
end
|
414
|
+
|
415
|
+
describe '.reindex' do
|
416
|
+
before do
|
417
|
+
journal
|
418
|
+
CitiesIndex.create!
|
419
|
+
CountriesIndex.create!
|
420
|
+
end
|
421
|
+
|
422
|
+
let(:source_index) { 'cities' }
|
423
|
+
let(:dest_index) { 'countries' }
|
424
|
+
|
425
|
+
context 'with correct arguments' do
|
426
|
+
specify do
|
427
|
+
output = StringIO.new
|
428
|
+
described_class.reindex(source: source_index, dest: dest_index, output: output)
|
429
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
430
|
+
\\Source index is cities
|
431
|
+
\\Destination index is countries
|
432
|
+
cities index successfully reindexed with countries index data
|
433
|
+
Total: \\d+s\\Z
|
434
|
+
OUTPUT
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
context 'with missing indexes' do
|
439
|
+
context 'without dest index' do
|
440
|
+
specify do
|
441
|
+
output = StringIO.new
|
442
|
+
expect { described_class.reindex(source: source_index, output: output) }
|
443
|
+
.to raise_error ArgumentError
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
context 'without source index' do
|
448
|
+
specify do
|
449
|
+
output = StringIO.new
|
450
|
+
expect { described_class.reindex(dest: dest_index, output: output) }
|
451
|
+
.to raise_error ArgumentError
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
describe '.update_mapping' do
|
458
|
+
before do
|
459
|
+
journal
|
460
|
+
CitiesIndex.create!
|
461
|
+
end
|
462
|
+
|
463
|
+
let(:index_name) { CitiesIndex.index_name }
|
464
|
+
let(:nonexistent_index) { 'wrong_index' }
|
465
|
+
|
466
|
+
context 'with existing index' do
|
467
|
+
specify do
|
468
|
+
output = StringIO.new
|
469
|
+
described_class.update_mapping(name: index_name, output: output)
|
470
|
+
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
|
471
|
+
\\Index name is cities
|
472
|
+
cities index successfully updated
|
473
|
+
Total: \\d+s\\Z
|
474
|
+
OUTPUT
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
context 'with non-existent index name' do
|
479
|
+
specify do
|
480
|
+
output = StringIO.new
|
481
|
+
expect { described_class.update_mapping(name: nonexistent_index, output: output) }
|
482
|
+
.to raise_error NameError
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
396
486
|
end
|