elasticsearch-model 7.2.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/README.md +22 -22
  4. data/Rakefile +7 -6
  5. data/elasticsearch-model.gemspec +5 -5
  6. data/examples/activerecord_associations.rb +1 -1
  7. data/examples/activerecord_custom_analyzer.rb +2 -2
  8. data/gemfiles/{6.0.gemfile → 6.1.gemfile} +6 -6
  9. data/gemfiles/{5.0.gemfile → 7.0.gemfile} +8 -7
  10. data/gemfiles/{3.0.gemfile → 7.1.gemfile} +9 -8
  11. data/lib/elasticsearch/model/adapter.rb +0 -2
  12. data/lib/elasticsearch/model/adapters/active_record.rb +0 -4
  13. data/lib/elasticsearch/model/adapters/default.rb +0 -4
  14. data/lib/elasticsearch/model/adapters/mongoid.rb +9 -11
  15. data/lib/elasticsearch/model/adapters/multiple.rb +0 -1
  16. data/lib/elasticsearch/model/importing.rb +1 -12
  17. data/lib/elasticsearch/model/indexing.rb +6 -19
  18. data/lib/elasticsearch/model/multimodel.rb +1 -10
  19. data/lib/elasticsearch/model/naming.rb +7 -58
  20. data/lib/elasticsearch/model/proxy.rb +6 -7
  21. data/lib/elasticsearch/model/response/result.rb +0 -6
  22. data/lib/elasticsearch/model/searching.rb +2 -3
  23. data/lib/elasticsearch/model/version.rb +1 -1
  24. data/lib/elasticsearch/model.rb +6 -3
  25. data/spec/elasticsearch/model/adapter_spec.rb +0 -11
  26. data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +48 -76
  27. data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +6 -78
  28. data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +6 -2
  29. data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +1 -5
  30. data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +0 -8
  31. data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +1 -4
  32. data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +9 -11
  33. data/spec/elasticsearch/model/adapters/mongoid_spec.rb +1 -1
  34. data/spec/elasticsearch/model/adapters/multiple_spec.rb +1 -11
  35. data/spec/elasticsearch/model/importing_spec.rb +6 -35
  36. data/spec/elasticsearch/model/indexing_spec.rb +45 -170
  37. data/spec/elasticsearch/model/module_spec.rb +0 -1
  38. data/spec/elasticsearch/model/multimodel_spec.rb +2 -8
  39. data/spec/elasticsearch/model/naming_spec.rb +0 -68
  40. data/spec/elasticsearch/model/proxy_spec.rb +8 -2
  41. data/spec/elasticsearch/model/response/aggregations_spec.rb +4 -4
  42. data/spec/elasticsearch/model/response/base_spec.rb +0 -1
  43. data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +3 -4
  44. data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +0 -1
  45. data/spec/elasticsearch/model/response/records_spec.rb +0 -1
  46. data/spec/elasticsearch/model/response/response_spec.rb +0 -1
  47. data/spec/elasticsearch/model/response/result_spec.rb +0 -17
  48. data/spec/elasticsearch/model/response/results_spec.rb +0 -1
  49. data/spec/elasticsearch/model/searching_search_request_spec.rb +5 -6
  50. data/spec/spec_helper.rb +9 -11
  51. data/spec/support/app/answer.rb +0 -1
  52. data/spec/support/app/article.rb +0 -2
  53. data/spec/support/app/article_no_type.rb +1 -1
  54. data/spec/support/app/namespaced_book.rb +0 -2
  55. data/spec/support/app/parent_and_child_searchable.rb +6 -4
  56. data/spec/support/app/question.rb +0 -1
  57. metadata +15 -16
  58. data/gemfiles/4.0.gemfile +0 -36
@@ -18,44 +18,7 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe Elasticsearch::Model::Adapter::ActiveRecord do
21
-
22
- context 'when a document_type is not defined for the Model' do
23
-
24
- before do
25
- ActiveRecord::Schema.define(:version => 1) do
26
- create_table :article_no_types do |t|
27
- t.string :title
28
- t.string :body
29
- t.integer :clicks, :default => 0
30
- t.datetime :created_at, :default => 'NOW()'
31
- end
32
- end
33
-
34
- ArticleNoType.delete_all
35
- ArticleNoType.__elasticsearch__.create_index!(force: true)
36
-
37
- ArticleNoType.create!(title: 'Test', body: '', clicks: 1)
38
- ArticleNoType.create!(title: 'Testing Coding', body: '', clicks: 2)
39
- ArticleNoType.create!(title: 'Coding', body: '', clicks: 3)
40
-
41
- ArticleNoType.__elasticsearch__.refresh_index!
42
- end
43
-
44
- describe 'indexing a document' do
45
-
46
- let(:search_result) do
47
- ArticleNoType.search('title:test')
48
- end
49
-
50
- it 'allows searching for documents' do
51
- expect(search_result.results.size).to be(2)
52
- expect(search_result.records.size).to be(2)
53
- end
54
- end
55
- end
56
-
57
- context 'when a document_type is defined for the Model' do
58
-
21
+ context 'for the Model' do
59
22
  before(:all) do
60
23
  ActiveRecord::Schema.define(:version => 1) do
61
24
  create_table :articles do |t|
@@ -67,7 +30,7 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
67
30
  end
68
31
 
69
32
  Article.delete_all
70
- Article.__elasticsearch__.create_index!(force: true, include_type_name: true)
33
+ Article.__elasticsearch__.create_index!(force: true)
71
34
 
72
35
  Article.create!(title: 'Test', body: '', clicks: 1)
73
36
  Article.create!(title: 'Testing Coding', body: '', clicks: 2)
@@ -77,7 +40,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
77
40
  end
78
41
 
79
42
  describe 'indexing a document' do
80
-
81
43
  let(:search_result) do
82
44
  Article.search('title:test')
83
45
  end
@@ -89,7 +51,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
89
51
  end
90
52
 
91
53
  describe '#results' do
92
-
93
54
  let(:search_result) do
94
55
  Article.search('title:test')
95
56
  end
@@ -98,12 +59,11 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
98
59
  expect(search_result.results.first).to be_a(Elasticsearch::Model::Response::Result)
99
60
  end
100
61
 
101
- it 'prooperly loads the document' do
62
+ it 'properly loads the document' do
102
63
  expect(search_result.results.first.title).to eq('Test')
103
64
  end
104
65
 
105
66
  context 'when the result contains other data' do
106
-
107
67
  let(:search_result) do
108
68
  Article.search(query: { match: { title: 'test' } }, highlight: { fields: { title: {} } })
109
69
  end
@@ -120,7 +80,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
120
80
  end
121
81
 
122
82
  describe '#records' do
123
-
124
83
  let(:search_result) do
125
84
  Article.search('title:test')
126
85
  end
@@ -135,7 +94,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
135
94
  end
136
95
 
137
96
  describe 'Enumerable' do
138
-
139
97
  let(:search_result) do
140
98
  Article.search('title:test')
141
99
  end
@@ -150,7 +108,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
150
108
  end
151
109
 
152
110
  describe '#id' do
153
-
154
111
  let(:search_result) do
155
112
  Article.search('title:test')
156
113
  end
@@ -160,19 +117,7 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
160
117
  end
161
118
  end
162
119
 
163
- describe '#id' do
164
-
165
- let(:search_result) do
166
- Article.search('title:test')
167
- end
168
-
169
- it 'returns the type' do
170
- expect(search_result.results.first.type).to eq('article')
171
- end
172
- end
173
-
174
120
  describe '#each_with_hit' do
175
-
176
121
  let(:search_result) do
177
122
  Article.search('title:test')
178
123
  end
@@ -186,7 +131,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
186
131
  end
187
132
 
188
133
  describe 'search results order' do
189
-
190
134
  let(:search_result) do
191
135
  Article.search(query: { match: { title: 'code' }}, sort: { clicks: :desc })
192
136
  end
@@ -209,7 +153,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
209
153
  end
210
154
 
211
155
  describe 'a paged collection' do
212
-
213
156
  let(:search_result) do
214
157
  Article.search(query: { match: { title: { query: 'test' } } },
215
158
  size: 2,
@@ -225,7 +168,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
225
168
  end
226
169
 
227
170
  describe '#destroy' do
228
-
229
171
  before do
230
172
  Article.create!(title: 'destroy', body: '', clicks: 1)
231
173
  Article.__elasticsearch__.refresh_index!
@@ -246,7 +188,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
246
188
  end
247
189
 
248
190
  describe 'full document updates' do
249
-
250
191
  before do
251
192
  article = Article.create!(title: 'update', body: '', clicks: 1)
252
193
  Article.__elasticsearch__.refresh_index!
@@ -267,7 +208,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
267
208
  end
268
209
 
269
210
  describe 'attribute updates' do
270
-
271
211
  before do
272
212
  article = Article.create!(title: 'update', body: '', clicks: 1)
273
213
  Article.__elasticsearch__.refresh_index!
@@ -288,7 +228,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
288
228
  end
289
229
 
290
230
  describe '#save' do
291
-
292
231
  before do
293
232
  article = Article.create!(title: 'save', body: '', clicks: 1)
294
233
 
@@ -315,7 +254,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
315
254
  end
316
255
 
317
256
  describe 'a DSL search' do
318
-
319
257
  let(:search_result) do
320
258
  Article.search(query: { match: { title: { query: 'test' } } })
321
259
  end
@@ -327,7 +265,6 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
327
265
  end
328
266
 
329
267
  describe 'chaining SQL queries on response.records' do
330
-
331
268
  let(:search_result) do
332
269
  Article.search(query: { match: { title: { query: 'test' } } })
333
270
  end
@@ -340,31 +277,23 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
340
277
  end
341
278
 
342
279
  describe 'ordering of SQL queries' do
343
-
344
280
  context 'when order is called on the ActiveRecord query' do
345
-
346
281
  let(:search_result) do
347
282
  Article.search query: { match: { title: { query: 'test' } } }
348
283
  end
349
284
 
350
- it 'allows the SQL query to be ordered independent of the Elasticsearch results order', unless: active_record_at_least_4? do
351
- expect(search_result.records.order('title DESC').first.title).to eq('Testing Coding')
352
- expect(search_result.records.order('title DESC')[0].title).to eq('Testing Coding')
353
- end
354
-
355
- it 'allows the SQL query to be ordered independent of the Elasticsearch results order', if: active_record_at_least_4? do
285
+ it 'allows the SQL query to be ordered independent of the Elasticsearch results order' do
356
286
  expect(search_result.records.order(title: :desc).first.title).to eq('Testing Coding')
357
287
  expect(search_result.records.order(title: :desc)[0].title).to eq('Testing Coding')
358
288
  end
359
289
  end
360
290
 
361
291
  context 'when more methods are chained on the ActiveRecord query' do
362
-
363
292
  let(:search_result) do
364
293
  Article.search query: {match: {title: {query: 'test'}}}
365
294
  end
366
295
 
367
- it 'allows the SQL query to be ordered independent of the Elasticsearch results order', if: active_record_at_least_4? do
296
+ it 'allows the SQL query to be ordered independent of the Elasticsearch results order' do
368
297
  expect(search_result.records.distinct.order(title: :desc).first.title).to eq('Testing Coding')
369
298
  expect(search_result.records.distinct.order(title: :desc)[0].title).to eq('Testing Coding')
370
299
  end
@@ -372,11 +301,10 @@ describe Elasticsearch::Model::Adapter::ActiveRecord do
372
301
  end
373
302
 
374
303
  describe 'access to the response via methods' do
375
-
376
304
  let(:search_result) do
377
305
  Article.search(query: { match: { title: { query: 'test' } } },
378
306
  aggregations: {
379
- dates: { date_histogram: { field: 'created_at', interval: 'hour' } },
307
+ dates: { date_histogram: { field: 'created_at', calendar_interval: 'hour' } },
380
308
  clicks: { global: {}, aggregations: { min: { min: { field: 'clicks' } } } }
381
309
  },
382
310
  suggest: { text: 'tezt', title: { term: { field: 'title', suggest_mode: 'always' } } })
@@ -19,12 +19,12 @@ require 'spec_helper'
19
19
 
20
20
  describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
21
21
  before(:all) do
22
- ActiveRecord::Schema.define(:version => 1) do
22
+ ActiveRecord::Schema.define(version: 1) do
23
23
  create_table :import_articles do |t|
24
24
  t.string :title
25
25
  t.integer :views
26
26
  t.string :numeric # For the sake of invalid data sent to Elasticsearch
27
- t.datetime :created_at, :default => 'NOW()'
27
+ t.datetime :created_at, default: 'NOW()'
28
28
  end
29
29
  end
30
30
 
@@ -52,6 +52,10 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
52
52
  it 'imports all documents' do
53
53
  expect(ImportArticle.search('*').results.total).to eq(10)
54
54
  end
55
+
56
+ it "does not pollute the model's namespace" do
57
+ expect(ImportArticle.methods).not_to include(:__transform)
58
+ end
55
59
  end
56
60
 
57
61
  context 'when batch size is specified' do
@@ -27,7 +27,7 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Namespaced Model' do
27
27
  end
28
28
 
29
29
  MyNamespace::Book.delete_all
30
- MyNamespace::Book.__elasticsearch__.create_index!(force: true, include_type_name: true)
30
+ MyNamespace::Book.__elasticsearch__.create_index!(force: true)
31
31
  MyNamespace::Book.create!(title: 'Test')
32
32
  MyNamespace::Book.__elasticsearch__.refresh_index!
33
33
  end
@@ -43,10 +43,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Namespaced Model' do
43
43
  expect(MyNamespace::Book.index_name).to eq('my_namespace-books')
44
44
  end
45
45
 
46
- it 'has the proper document type' do
47
- expect(MyNamespace::Book.document_type).to eq('book')
48
- end
49
-
50
46
  it 'saves the document into the index' do
51
47
  expect(MyNamespace::Book.search('title:test').results.size).to eq(1)
52
48
  expect(MyNamespace::Book.search('title:test').results.first.title).to eq('Test')
@@ -18,7 +18,6 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe 'Elasticsearch::Model::Adapter::ActiveRecord Pagination' do
21
-
22
21
  before(:all) do
23
22
  ActiveRecord::Schema.define(:version => 1) do
24
23
  create_table ArticleForPagination.table_name do |t|
@@ -41,48 +40,41 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Pagination' do
41
40
  end
42
41
 
43
42
  context 'when no other page is specified' do
44
-
45
43
  let(:records) do
46
44
  ArticleForPagination.search('title:test').page(1).records
47
45
  end
48
46
 
49
47
  describe '#size' do
50
-
51
48
  it 'returns the correct size' do
52
49
  expect(records.size).to eq(25)
53
50
  end
54
51
  end
55
52
 
56
53
  describe '#current_page' do
57
-
58
54
  it 'returns the correct current page' do
59
55
  expect(records.current_page).to eq(1)
60
56
  end
61
57
  end
62
58
 
63
59
  describe '#prev_page' do
64
-
65
60
  it 'returns the correct previous page' do
66
61
  expect(records.prev_page).to be_nil
67
62
  end
68
63
  end
69
64
 
70
65
  describe '#next_page' do
71
-
72
66
  it 'returns the correct next page' do
73
67
  expect(records.next_page).to eq(2)
74
68
  end
75
69
  end
76
70
 
77
71
  describe '#total_pages' do
78
-
79
72
  it 'returns the correct total pages' do
80
73
  expect(records.total_pages).to eq(3)
81
74
  end
82
75
  end
83
76
 
84
77
  describe '#first_page?' do
85
-
86
78
  it 'returns the correct first page' do
87
79
  expect(records.first_page?).to be(true)
88
80
  end
@@ -38,7 +38,7 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Parent-Child' do
38
38
  add_index(:answers, :question_id) unless index_exists?(:answers, :question_id)
39
39
 
40
40
  clear_tables(Question)
41
- ParentChildSearchable.create_index!(force: true, include_type_name: true)
41
+ ParentChildSearchable.create_index!(force: true)
42
42
 
43
43
  q_1 = Question.create!(title: 'First Question', author: 'John')
44
44
  q_2 = Question.create!(title: 'Second Question', author: 'Jody')
@@ -53,7 +53,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Parent-Child' do
53
53
  end
54
54
 
55
55
  describe 'has_child search' do
56
-
57
56
  let(:search_result) do
58
57
  Question.search(query: { has_child: { type: 'answer', query: { match: { author: 'john' } } } })
59
58
  end
@@ -64,7 +63,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Parent-Child' do
64
63
  end
65
64
 
66
65
  describe 'hash_parent search' do
67
-
68
66
  let(:search_result) do
69
67
  Answer.search(query: { has_parent: { parent_type: 'question', query: { match: { author: 'john' } } } })
70
68
  end
@@ -75,7 +73,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Parent-Child' do
75
73
  end
76
74
 
77
75
  context 'when a parent is deleted' do
78
-
79
76
  before do
80
77
  Question.where(title: 'First Question').each(&:destroy)
81
78
  Question.__elasticsearch__.refresh_index!
@@ -18,7 +18,6 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe 'Elasticsearch::Model::Adapter::ActiveRecord Serialization' do
21
-
22
21
  before(:all) do
23
22
  ActiveRecord::Schema.define(:version => 1) do
24
23
  create_table ArticleWithCustomSerialization.table_name do |t|
@@ -32,18 +31,17 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Serialization' do
32
31
  end
33
32
 
34
33
  context 'when the model has a custom serialization defined' do
35
-
36
34
  before do
37
35
  ArticleWithCustomSerialization.create!(title: 'Test', status: 'green')
38
36
  ArticleWithCustomSerialization.__elasticsearch__.refresh_index!
39
37
  end
40
38
 
41
39
  context 'when a document is indexed' do
42
-
43
40
  let(:search_result) do
44
- ArticleWithCustomSerialization.__elasticsearch__.client.get(index: 'article_with_custom_serializations',
45
- type: '_doc',
46
- id: '1')
41
+ ArticleWithCustomSerialization.__elasticsearch__.client.get(
42
+ index: 'article_with_custom_serializations',
43
+ id: '1'
44
+ )
47
45
  end
48
46
 
49
47
  it 'applies the serialization when indexing' do
@@ -52,9 +50,8 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Serialization' do
52
50
  end
53
51
 
54
52
  context 'when a document is updated' do
55
-
56
53
  before do
57
- article.update_attributes(title: 'UPDATED', status: 'yellow')
54
+ article.update(title: 'UPDATED', status: 'yellow')
58
55
  ArticleWithCustomSerialization.__elasticsearch__.refresh_index!
59
56
  end
60
57
 
@@ -65,9 +62,10 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Serialization' do
65
62
  end
66
63
 
67
64
  let(:search_result) do
68
- ArticleWithCustomSerialization.__elasticsearch__.client.get(index: 'article_with_custom_serializations',
69
- type: '_doc',
70
- id: article.id)
65
+ ArticleWithCustomSerialization.__elasticsearch__.client.get(
66
+ index: 'article_with_custom_serializations',
67
+ id: article.id
68
+ )
71
69
  end
72
70
 
73
71
  it 'applies the serialization when updating' do
@@ -174,7 +174,7 @@ describe Elasticsearch::Model::Adapter::Mongoid do
174
174
  context 'query criteria specified as a hash' do
175
175
 
176
176
  before do
177
- expect(relation).to receive(:where).with(color: 'red').and_return(relation)
177
+ expect(relation).to receive(:where).with({ color: 'red' }).and_return(relation)
178
178
  end
179
179
 
180
180
  let(:query) do
@@ -18,13 +18,11 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe Elasticsearch::Model::Adapter::Multiple do
21
-
22
21
  before(:all) do
23
22
  class DummyOne
24
23
  include Elasticsearch::Model
25
24
 
26
25
  index_name 'dummy'
27
- document_type 'dummy_one'
28
26
 
29
27
  def self.find(ids)
30
28
  ids.map { |id| new(id) }
@@ -42,7 +40,6 @@ describe Elasticsearch::Model::Adapter::Multiple do
42
40
  include Elasticsearch::Model
43
41
 
44
42
  index_name 'dummy'
45
- document_type 'dummy_two'
46
43
 
47
44
  def self.find(ids)
48
45
  ids.map { |id| new(id) }
@@ -60,7 +57,6 @@ describe Elasticsearch::Model::Adapter::Multiple do
60
57
  include Elasticsearch::Model
61
58
 
62
59
  index_name 'other_index'
63
- document_type 'dummy_two'
64
60
 
65
61
  def self.find(ids)
66
62
  ids.map { |id| new(id) }
@@ -86,27 +82,22 @@ describe Elasticsearch::Model::Adapter::Multiple do
86
82
  [
87
83
  {
88
84
  _index: 'dummy',
89
- _type: 'dummy_two',
90
85
  _id: '2'
91
86
  },
92
87
  {
93
88
  _index: 'dummy',
94
- _type: 'dummy_one',
95
89
  _id: '2'
96
90
  },
97
91
  {
98
92
  _index: 'other_index',
99
- _type: 'dummy_two',
100
93
  _id: '1'
101
94
  },
102
95
  {
103
96
  _index: 'dummy',
104
- _type: 'dummy_two',
105
97
  _id: '1'
106
98
  },
107
99
  {
108
100
  _index: 'dummy',
109
- _type: 'dummy_one',
110
101
  _id: '3'
111
102
  }
112
103
  ]
@@ -121,13 +112,12 @@ describe Elasticsearch::Model::Adapter::Multiple do
121
112
  end
122
113
 
123
114
  describe '#records' do
124
-
125
115
  before do
126
116
  multimodel.class.send :include, Elasticsearch::Model::Adapter::Multiple::Records
127
117
  expect(multimodel).to receive(:response).at_least(:once).and_return(response)
128
118
  end
129
119
 
130
- it 'instantiates the correct types of instances' do
120
+ xit 'instantiates the correct types of instances' do
131
121
  expect(multimodel.records[0]).to be_a(Namespace::DummyTwo)
132
122
  expect(multimodel.records[1]).to be_a(DummyOne)
133
123
  expect(multimodel.records[2]).to be_a(DummyTwo)
@@ -18,18 +18,17 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe Elasticsearch::Model::Importing do
21
-
22
21
  before(:all) do
23
22
  class DummyImportingModel
24
23
  end
25
24
 
26
25
  module DummyImportingAdapter
27
26
  module ImportingMixin
28
- def __find_in_batches(options={}, &block)
27
+ def __find_in_batches(options = {}, &block)
29
28
  yield if block_given?
30
29
  end
31
30
  def __transform
32
- lambda {|a|}
31
+ lambda { |a| }
33
32
  end
34
33
  end
35
34
 
@@ -49,7 +48,6 @@ describe Elasticsearch::Model::Importing do
49
48
  end
50
49
 
51
50
  context 'when a model includes the Importing module' do
52
-
53
51
  it 'provides importing methods' do
54
52
  expect(DummyImportingModel.respond_to?(:import)).to be(true)
55
53
  expect(DummyImportingModel.respond_to?(:__find_in_batches)).to be(true)
@@ -57,10 +55,8 @@ describe Elasticsearch::Model::Importing do
57
55
  end
58
56
 
59
57
  describe '#import' do
60
-
61
58
  before do
62
59
  allow(DummyImportingModel).to receive(:index_name).and_return('foo')
63
- allow(DummyImportingModel).to receive(:document_type).and_return('foo')
64
60
  allow(DummyImportingModel).to receive(:index_exists?).and_return(true)
65
61
  allow(DummyImportingModel).to receive(:__batch_to_bulk)
66
62
  allow(client).to receive(:bulk).and_return(response)
@@ -75,7 +71,6 @@ describe Elasticsearch::Model::Importing do
75
71
  end
76
72
 
77
73
  context 'when no options are provided' do
78
-
79
74
  before do
80
75
  expect(DummyImportingModel).to receive(:client).and_return(client)
81
76
  allow(DummyImportingModel).to receive(:index_exists?).and_return(true)
@@ -87,7 +82,6 @@ describe Elasticsearch::Model::Importing do
87
82
  end
88
83
 
89
84
  context 'when there is an error' do
90
-
91
85
  before do
92
86
  expect(DummyImportingModel).to receive(:client).and_return(client)
93
87
  allow(DummyImportingModel).to receive(:index_exists?).and_return(true)
@@ -102,14 +96,12 @@ describe Elasticsearch::Model::Importing do
102
96
  end
103
97
 
104
98
  context 'when the method is called with the option to return the errors' do
105
-
106
99
  it 'returns the errors' do
107
100
  expect(DummyImportingModel.import(return: 'errors')).to eq([{ 'index' => { 'error' => 'FAILED' } }])
108
101
  end
109
102
  end
110
103
 
111
104
  context 'when the method is called with a block' do
112
-
113
105
  it 'yields the response to the block' do
114
106
  DummyImportingModel.import do |response|
115
107
  expect(response['items'].size).to eq(2)
@@ -119,7 +111,6 @@ describe Elasticsearch::Model::Importing do
119
111
  end
120
112
 
121
113
  context 'when the index does not exist' do
122
-
123
114
  before do
124
115
  allow(DummyImportingModel).to receive(:index_exists?).and_return(false)
125
116
  end
@@ -132,10 +123,9 @@ describe Elasticsearch::Model::Importing do
132
123
  end
133
124
 
134
125
  context 'when the method is called with the force option' do
135
-
136
126
  before do
137
127
  expect(DummyImportingModel).to receive(:create_index!).with(force: true, index: 'foo').and_return(true)
138
- expect(DummyImportingModel).to receive(:__find_in_batches).with(foo: 'bar').and_return(true)
128
+ expect(DummyImportingModel).to receive(:__find_in_batches).with({ foo: 'bar' }).and_return(true)
139
129
  end
140
130
 
141
131
  it 'deletes and creates the index' do
@@ -144,10 +134,9 @@ describe Elasticsearch::Model::Importing do
144
134
  end
145
135
 
146
136
  context 'when the method is called with the refresh option' do
147
-
148
137
  before do
149
138
  expect(DummyImportingModel).to receive(:refresh_index!).with(index: 'foo').and_return(true)
150
- expect(DummyImportingModel).to receive(:__find_in_batches).with(foo: 'bar').and_return(true)
139
+ expect(DummyImportingModel).to receive(:__find_in_batches).with({ foo: 'bar' }).and_return(true)
151
140
  end
152
141
 
153
142
  it 'refreshes the index' do
@@ -156,10 +145,9 @@ describe Elasticsearch::Model::Importing do
156
145
  end
157
146
 
158
147
  context 'when a different index name is provided' do
159
-
160
148
  before do
161
149
  expect(DummyImportingModel).to receive(:client).and_return(client)
162
- expect(client).to receive(:bulk).with(body: nil, index: 'my-new-index', type: 'foo').and_return(response)
150
+ expect(client).to receive(:bulk).with({ body: nil, index: 'my-new-index' }).and_return(response)
163
151
  end
164
152
 
165
153
  it 'uses the alternate index name' do
@@ -167,20 +155,7 @@ describe Elasticsearch::Model::Importing do
167
155
  end
168
156
  end
169
157
 
170
- context 'when a different document type is provided' do
171
-
172
- before do
173
- expect(DummyImportingModel).to receive(:client).and_return(client)
174
- expect(client).to receive(:bulk).with(body: nil, index: 'foo', type: 'my-new-type').and_return(response)
175
- end
176
-
177
- it 'uses the alternate index name' do
178
- expect(DummyImportingModel.import(type: 'my-new-type')).to eq(0)
179
- end
180
- end
181
-
182
158
  context 'the transform method' do
183
-
184
159
  before do
185
160
  expect(DummyImportingModel).to receive(:client).and_return(client)
186
161
  expect(DummyImportingModel).to receive(:__transform).and_return(transform)
@@ -197,9 +172,7 @@ describe Elasticsearch::Model::Importing do
197
172
  end
198
173
 
199
174
  context 'when a transform is provided as an option' do
200
-
201
175
  context 'when the transform option is not a lambda' do
202
-
203
176
  let(:transform) do
204
177
  'not_callable'
205
178
  end
@@ -212,7 +185,6 @@ describe Elasticsearch::Model::Importing do
212
185
  end
213
186
 
214
187
  context 'when the transform option is a lambda' do
215
-
216
188
  before do
217
189
  expect(DummyImportingModel).to receive(:client).and_return(client)
218
190
  expect(DummyImportingModel).to receive(:__batch_to_bulk).with(anything, transform)
@@ -229,10 +201,9 @@ describe Elasticsearch::Model::Importing do
229
201
  end
230
202
 
231
203
  context 'when a pipeline is provided as an options' do
232
-
233
204
  before do
234
205
  expect(DummyImportingModel).to receive(:client).and_return(client)
235
- expect(client).to receive(:bulk).with(body: nil, index: 'foo', type: 'foo', pipeline: 'my-pipeline').and_return(response)
206
+ expect(client).to receive(:bulk).with({ body: nil, index: 'foo', pipeline: 'my-pipeline' }).and_return(response)
236
207
  end
237
208
 
238
209
  it 'uses the pipeline option' do