elasticsearch-model 0.1.9 → 7.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -2
- data/Gemfile +22 -0
- data/LICENSE.txt +199 -10
- data/README.md +96 -43
- data/Rakefile +49 -35
- data/elasticsearch-model.gemspec +53 -41
- data/examples/activerecord_article.rb +18 -1
- data/examples/activerecord_associations.rb +86 -17
- data/examples/activerecord_custom_analyzer.rb +152 -0
- data/examples/activerecord_mapping_completion.rb +33 -16
- data/examples/activerecord_mapping_edge_ngram.rb +118 -0
- data/examples/couchbase_article.rb +17 -0
- data/examples/datamapper_article.rb +28 -1
- data/examples/mongoid_article.rb +17 -0
- data/examples/ohm_article.rb +17 -0
- data/examples/riak_article.rb +17 -0
- data/gemfiles/3.0.gemfile +23 -1
- data/gemfiles/4.0.gemfile +25 -1
- data/gemfiles/5.0.gemfile +35 -0
- data/gemfiles/6.0.gemfile +36 -0
- data/lib/elasticsearch/model/adapter.rb +17 -0
- data/lib/elasticsearch/model/adapters/active_record.rb +31 -27
- data/lib/elasticsearch/model/adapters/default.rb +17 -0
- data/lib/elasticsearch/model/adapters/mongoid.rb +27 -3
- data/lib/elasticsearch/model/adapters/multiple.rb +29 -4
- data/lib/elasticsearch/model/callbacks.rb +17 -0
- data/lib/elasticsearch/model/client.rb +17 -0
- data/lib/elasticsearch/model/ext/active_record.rb +17 -0
- data/lib/elasticsearch/model/hash_wrapper.rb +32 -0
- data/lib/elasticsearch/model/importing.rb +61 -17
- data/lib/elasticsearch/model/indexing.rb +87 -49
- data/lib/elasticsearch/model/multimodel.rb +17 -0
- data/lib/elasticsearch/model/naming.rb +33 -2
- data/lib/elasticsearch/model/proxy.rb +61 -18
- data/lib/elasticsearch/model/response/aggregations.rb +55 -0
- data/lib/elasticsearch/model/response/base.rb +25 -3
- data/lib/elasticsearch/model/response/pagination/kaminari.rb +126 -0
- data/lib/elasticsearch/model/response/pagination/will_paginate.rb +112 -0
- data/lib/elasticsearch/model/response/pagination.rb +19 -192
- data/lib/elasticsearch/model/response/records.rb +17 -1
- data/lib/elasticsearch/model/response/result.rb +19 -2
- data/lib/elasticsearch/model/response/results.rb +17 -0
- data/lib/elasticsearch/model/response/suggestions.rb +20 -1
- data/lib/elasticsearch/model/response.rb +28 -10
- data/lib/elasticsearch/model/searching.rb +17 -0
- data/lib/elasticsearch/model/serializing.rb +17 -0
- data/lib/elasticsearch/model/version.rb +18 -1
- data/lib/elasticsearch/model.rb +36 -39
- data/spec/elasticsearch/model/adapter_spec.rb +136 -0
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +351 -0
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +395 -0
- data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +35 -0
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +193 -0
- data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +127 -0
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +55 -0
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +332 -0
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +92 -0
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +78 -0
- data/spec/elasticsearch/model/adapters/active_record_spec.rb +224 -0
- data/spec/elasticsearch/model/adapters/default_spec.rb +58 -0
- data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +284 -0
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +83 -0
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +252 -0
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +142 -0
- data/spec/elasticsearch/model/callbacks_spec.rb +50 -0
- data/spec/elasticsearch/model/client_spec.rb +83 -0
- data/spec/elasticsearch/model/hash_wrapper_spec.rb +29 -0
- data/spec/elasticsearch/model/importing_spec.rb +243 -0
- data/spec/elasticsearch/model/indexing_spec.rb +1014 -0
- data/spec/elasticsearch/model/module_spec.rb +94 -0
- data/spec/elasticsearch/model/multimodel_spec.rb +72 -0
- data/spec/elasticsearch/model/naming_spec.rb +203 -0
- data/spec/elasticsearch/model/proxy_spec.rb +124 -0
- data/spec/elasticsearch/model/response/aggregations_spec.rb +83 -0
- data/spec/elasticsearch/model/response/base_spec.rb +107 -0
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +472 -0
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +279 -0
- data/spec/elasticsearch/model/response/records_spec.rb +135 -0
- data/spec/elasticsearch/model/response/response_spec.rb +148 -0
- data/spec/elasticsearch/model/response/result_spec.rb +139 -0
- data/spec/elasticsearch/model/response/results_spec.rb +73 -0
- data/spec/elasticsearch/model/searching_search_request_spec.rb +129 -0
- data/spec/elasticsearch/model/searching_spec.rb +66 -0
- data/spec/elasticsearch/model/serializing_spec.rb +39 -0
- data/spec/spec_helper.rb +193 -0
- data/spec/support/app/answer.rb +50 -0
- data/spec/support/app/article.rb +39 -0
- data/spec/support/app/article_for_pagination.rb +29 -0
- data/spec/support/app/article_no_type.rb +37 -0
- data/spec/support/app/article_with_custom_serialization.rb +30 -0
- data/spec/support/app/article_with_dynamic_index_name.rb +32 -0
- data/spec/support/app/author.rb +26 -0
- data/spec/support/app/authorship.rb +21 -0
- data/spec/support/app/category.rb +20 -0
- data/spec/support/app/comment.rb +20 -0
- data/spec/support/app/episode.rb +28 -0
- data/spec/support/app/image.rb +36 -0
- data/spec/support/app/import_article.rb +29 -0
- data/spec/support/app/mongoid_article.rb +38 -0
- data/spec/support/app/namespaced_book.rb +27 -0
- data/spec/support/app/parent_and_child_searchable.rb +41 -0
- data/spec/support/app/post.rb +31 -0
- data/spec/support/app/question.rb +44 -0
- data/spec/support/app/searchable.rb +65 -0
- data/spec/support/app/series.rb +28 -0
- data/spec/support/app.rb +46 -0
- data/spec/support/model.json +1 -0
- data/{test → spec}/support/model.yml +0 -0
- metadata +175 -121
- data/test/integration/active_record_associations_parent_child.rb +0 -139
- data/test/integration/active_record_associations_test.rb +0 -326
- data/test/integration/active_record_basic_test.rb +0 -234
- data/test/integration/active_record_custom_serialization_test.rb +0 -62
- data/test/integration/active_record_import_test.rb +0 -109
- data/test/integration/active_record_namespaced_model_test.rb +0 -49
- data/test/integration/active_record_pagination_test.rb +0 -145
- data/test/integration/dynamic_index_name_test.rb +0 -47
- data/test/integration/mongoid_basic_test.rb +0 -177
- data/test/integration/multiple_models_test.rb +0 -172
- data/test/support/model.json +0 -1
- data/test/test_helper.rb +0 -93
- data/test/unit/adapter_active_record_test.rb +0 -157
- data/test/unit/adapter_default_test.rb +0 -41
- data/test/unit/adapter_mongoid_test.rb +0 -104
- data/test/unit/adapter_multiple_test.rb +0 -106
- data/test/unit/adapter_test.rb +0 -69
- data/test/unit/callbacks_test.rb +0 -31
- data/test/unit/client_test.rb +0 -27
- data/test/unit/importing_test.rb +0 -203
- data/test/unit/indexing_test.rb +0 -650
- data/test/unit/module_test.rb +0 -57
- data/test/unit/multimodel_test.rb +0 -38
- data/test/unit/naming_test.rb +0 -103
- data/test/unit/proxy_test.rb +0 -100
- data/test/unit/response_base_test.rb +0 -40
- data/test/unit/response_pagination_kaminari_test.rb +0 -433
- data/test/unit/response_pagination_will_paginate_test.rb +0 -398
- data/test/unit/response_records_test.rb +0 -91
- data/test/unit/response_result_test.rb +0 -90
- data/test/unit/response_results_test.rb +0 -31
- data/test/unit/response_test.rb +0 -104
- data/test/unit/searching_search_request_test.rb +0 -78
- data/test/unit/searching_test.rb +0 -41
- data/test/unit/serializing_test.rb +0 -17
data/test/unit/importing_test.rb
DELETED
@@ -1,203 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
|
4
|
-
context "Importing module" do
|
5
|
-
class ::DummyImportingModel
|
6
|
-
end
|
7
|
-
|
8
|
-
module ::DummyImportingAdapter
|
9
|
-
module ImportingMixin
|
10
|
-
def __find_in_batches(options={}, &block)
|
11
|
-
yield if block_given?
|
12
|
-
end
|
13
|
-
def __transform
|
14
|
-
lambda {|a|}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def importing_mixin
|
19
|
-
ImportingMixin
|
20
|
-
end; module_function :importing_mixin
|
21
|
-
end
|
22
|
-
|
23
|
-
should "include methods from the module and adapter" do
|
24
|
-
Elasticsearch::Model::Adapter.expects(:from_class)
|
25
|
-
.with(DummyImportingModel)
|
26
|
-
.returns(DummyImportingAdapter)
|
27
|
-
|
28
|
-
DummyImportingModel.__send__ :include, Elasticsearch::Model::Importing
|
29
|
-
|
30
|
-
assert_respond_to DummyImportingModel, :import
|
31
|
-
assert_respond_to DummyImportingModel, :__find_in_batches
|
32
|
-
end
|
33
|
-
|
34
|
-
should "call the client when importing" do
|
35
|
-
Elasticsearch::Model::Adapter.expects(:from_class)
|
36
|
-
.with(DummyImportingModel)
|
37
|
-
.returns(DummyImportingAdapter)
|
38
|
-
|
39
|
-
DummyImportingModel.__send__ :include, Elasticsearch::Model::Importing
|
40
|
-
|
41
|
-
client = mock('client')
|
42
|
-
client.expects(:bulk).returns({'items' => []})
|
43
|
-
|
44
|
-
DummyImportingModel.expects(:client).returns(client)
|
45
|
-
DummyImportingModel.expects(:index_name).returns('foo')
|
46
|
-
DummyImportingModel.expects(:document_type).returns('foo')
|
47
|
-
DummyImportingModel.stubs(:index_exists?).returns(true)
|
48
|
-
DummyImportingModel.stubs(:__batch_to_bulk)
|
49
|
-
assert_equal 0, DummyImportingModel.import
|
50
|
-
end
|
51
|
-
|
52
|
-
should "return the number of errors" do
|
53
|
-
Elasticsearch::Model::Adapter.expects(:from_class)
|
54
|
-
.with(DummyImportingModel)
|
55
|
-
.returns(DummyImportingAdapter)
|
56
|
-
|
57
|
-
DummyImportingModel.__send__ :include, Elasticsearch::Model::Importing
|
58
|
-
|
59
|
-
client = mock('client')
|
60
|
-
client.expects(:bulk).returns({'items' => [ {'index' => {}}, {'index' => {'error' => 'FAILED'}} ]})
|
61
|
-
|
62
|
-
DummyImportingModel.stubs(:client).returns(client)
|
63
|
-
DummyImportingModel.stubs(:index_name).returns('foo')
|
64
|
-
DummyImportingModel.stubs(:document_type).returns('foo')
|
65
|
-
DummyImportingModel.stubs(:index_exists?).returns(true)
|
66
|
-
DummyImportingModel.stubs(:__batch_to_bulk)
|
67
|
-
|
68
|
-
assert_equal 1, DummyImportingModel.import
|
69
|
-
end
|
70
|
-
|
71
|
-
should "return an array of error elements" do
|
72
|
-
Elasticsearch::Model::Adapter.expects(:from_class)
|
73
|
-
.with(DummyImportingModel)
|
74
|
-
.returns(DummyImportingAdapter)
|
75
|
-
|
76
|
-
DummyImportingModel.__send__ :include, Elasticsearch::Model::Importing
|
77
|
-
|
78
|
-
client = mock('client')
|
79
|
-
client.expects(:bulk).returns({'items' => [ {'index' => {}}, {'index' => {'error' => 'FAILED'}} ]})
|
80
|
-
|
81
|
-
DummyImportingModel.stubs(:client).returns(client)
|
82
|
-
DummyImportingModel.stubs(:index_name).returns('foo')
|
83
|
-
DummyImportingModel.stubs(:document_type).returns('foo')
|
84
|
-
DummyImportingModel.stubs(:index_exists?).returns(true)
|
85
|
-
DummyImportingModel.stubs(:__batch_to_bulk)
|
86
|
-
|
87
|
-
assert_equal [{'index' => {'error' => 'FAILED'}}], DummyImportingModel.import(return: 'errors')
|
88
|
-
end
|
89
|
-
|
90
|
-
should "yield the response" do
|
91
|
-
Elasticsearch::Model::Adapter.expects(:from_class)
|
92
|
-
.with(DummyImportingModel)
|
93
|
-
.returns(DummyImportingAdapter)
|
94
|
-
|
95
|
-
DummyImportingModel.__send__ :include, Elasticsearch::Model::Importing
|
96
|
-
|
97
|
-
client = mock('client')
|
98
|
-
client.expects(:bulk).returns({'items' => [ {'index' => {}}, {'index' => {'error' => 'FAILED'}} ]})
|
99
|
-
|
100
|
-
DummyImportingModel.stubs(:client).returns(client)
|
101
|
-
DummyImportingModel.stubs(:index_name).returns('foo')
|
102
|
-
DummyImportingModel.stubs(:document_type).returns('foo')
|
103
|
-
DummyImportingModel.stubs(:index_exists?).returns(true)
|
104
|
-
DummyImportingModel.stubs(:__batch_to_bulk)
|
105
|
-
|
106
|
-
DummyImportingModel.import do |response|
|
107
|
-
assert_equal 2, response['items'].size
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "when the index does not exist" do
|
112
|
-
should "raise an exception" do
|
113
|
-
Elasticsearch::Model::Adapter.expects(:from_class)
|
114
|
-
.with(DummyImportingModel)
|
115
|
-
.returns(DummyImportingAdapter)
|
116
|
-
|
117
|
-
DummyImportingModel.__send__ :include, Elasticsearch::Model::Importing
|
118
|
-
|
119
|
-
DummyImportingModel.expects(:index_name).returns('foo')
|
120
|
-
DummyImportingModel.expects(:document_type).returns('foo')
|
121
|
-
DummyImportingModel.expects(:index_exists?).returns(false)
|
122
|
-
|
123
|
-
assert_raise ArgumentError do
|
124
|
-
DummyImportingModel.import
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "with the force option" do
|
130
|
-
should "delete and create the index" do
|
131
|
-
DummyImportingModel.expects(:__find_in_batches).with do |options|
|
132
|
-
assert_equal 'bar', options[:foo]
|
133
|
-
assert_nil options[:force]
|
134
|
-
true
|
135
|
-
end
|
136
|
-
|
137
|
-
DummyImportingModel.expects(:create_index!).with do |options|
|
138
|
-
assert_equal true, options[:force]
|
139
|
-
true
|
140
|
-
end
|
141
|
-
|
142
|
-
DummyImportingModel.expects(:index_name).returns('foo')
|
143
|
-
DummyImportingModel.expects(:document_type).returns('foo')
|
144
|
-
|
145
|
-
DummyImportingModel.import force: true, foo: 'bar'
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
should "allow passing a different index / type" do
|
150
|
-
Elasticsearch::Model::Adapter.expects(:from_class)
|
151
|
-
.with(DummyImportingModel)
|
152
|
-
.returns(DummyImportingAdapter)
|
153
|
-
|
154
|
-
DummyImportingModel.__send__ :include, Elasticsearch::Model::Importing
|
155
|
-
|
156
|
-
client = mock('client')
|
157
|
-
|
158
|
-
client
|
159
|
-
.expects(:bulk)
|
160
|
-
.with do |options|
|
161
|
-
assert_equal 'my-new-index', options[:index]
|
162
|
-
assert_equal 'my-other-type', options[:type]
|
163
|
-
true
|
164
|
-
end
|
165
|
-
.returns({'items' => [ {'index' => {} }]})
|
166
|
-
|
167
|
-
DummyImportingModel.stubs(:client).returns(client)
|
168
|
-
DummyImportingModel.stubs(:index_exists?).returns(true)
|
169
|
-
DummyImportingModel.stubs(:__batch_to_bulk)
|
170
|
-
|
171
|
-
DummyImportingModel.import index: 'my-new-index', type: 'my-other-type'
|
172
|
-
end
|
173
|
-
|
174
|
-
should "use the default transform from adapter" do
|
175
|
-
client = mock('client', bulk: {'items' => []})
|
176
|
-
transform = lambda {|a|}
|
177
|
-
|
178
|
-
DummyImportingModel.stubs(:client).returns(client)
|
179
|
-
DummyImportingModel.stubs(:index_exists?).returns(true)
|
180
|
-
DummyImportingModel.expects(:__transform).returns(transform)
|
181
|
-
DummyImportingModel.expects(:__batch_to_bulk).with(anything, transform)
|
182
|
-
|
183
|
-
DummyImportingModel.import index: 'foo', type: 'bar'
|
184
|
-
end
|
185
|
-
|
186
|
-
should "use the transformer from options" do
|
187
|
-
client = mock('client', bulk: {'items' => []})
|
188
|
-
transform = lambda {|a|}
|
189
|
-
|
190
|
-
DummyImportingModel.stubs(:client).returns(client)
|
191
|
-
DummyImportingModel.stubs(:index_exists?).returns(true)
|
192
|
-
DummyImportingModel.expects(:__batch_to_bulk).with(anything, transform)
|
193
|
-
|
194
|
-
DummyImportingModel.import index: 'foo', type: 'bar', transform: transform
|
195
|
-
end
|
196
|
-
|
197
|
-
should "raise an ArgumentError if transform doesn't respond to the call method" do
|
198
|
-
assert_raise ArgumentError do
|
199
|
-
DummyImportingModel.import index: 'foo', type: 'bar', transform: "not_callable"
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|