elasticsearch-model 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ module Elasticsearch
22
22
  #
23
23
  def results
24
24
  # TODO: Configurable custom wrapper
25
- @results = response.response['hits']['hits'].map { |hit| Result.new(hit) }
25
+ response.response['hits']['hits'].map { |hit| Result.new(hit) }
26
26
  end
27
27
 
28
28
  end
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Model
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
@@ -11,6 +11,7 @@ module Elasticsearch
11
11
  ActiveRecord::Schema.define(:version => 1) do
12
12
  create_table :articles do |t|
13
13
  t.string :title
14
+ t.string :body
14
15
  t.datetime :created_at, :default => 'NOW()'
15
16
  end
16
17
  end
@@ -22,6 +23,7 @@ module Elasticsearch
22
23
  settings index: { number_of_shards: 1, number_of_replicas: 0 } do
23
24
  mapping do
24
25
  indexes :title, type: 'string', analyzer: 'snowball'
26
+ indexes :body, type: 'string'
25
27
  indexes :created_at, type: 'date'
26
28
  end
27
29
  end
@@ -30,9 +32,9 @@ module Elasticsearch
30
32
  Article.delete_all
31
33
  Article.__elasticsearch__.create_index! force: true
32
34
 
33
- ::Article.create! title: 'Test'
34
- ::Article.create! title: 'Testing Coding'
35
- ::Article.create! title: 'Coding'
35
+ ::Article.create! title: 'Test', body: ''
36
+ ::Article.create! title: 'Testing Coding', body: ''
37
+ ::Article.create! title: 'Coding', body: ''
36
38
 
37
39
  Article.__elasticsearch__.refresh_index!
38
40
  end
@@ -128,7 +130,7 @@ module Elasticsearch
128
130
  assert_equal 1, response.records.size
129
131
  end
130
132
 
131
- should "update specific attributes" do
133
+ should "update specific attributes" do
132
134
  article = Article.first
133
135
 
134
136
  response = Article.search 'title:special'
@@ -146,6 +148,29 @@ module Elasticsearch
146
148
  assert_equal 1, response.records.size
147
149
  end
148
150
 
151
+ should "update document when save is called multiple times in a transaction" do
152
+ article = Article.first
153
+ response = Article.search 'body:dummy'
154
+
155
+ assert_equal 0, response.results.size
156
+ assert_equal 0, response.records.size
157
+
158
+ ActiveRecord::Base.transaction do
159
+ article.body = 'dummy'
160
+ article.save
161
+
162
+ article.title = 'special'
163
+ article.save
164
+ end
165
+
166
+ article.__elasticsearch__.update_document
167
+ Article.__elasticsearch__.refresh_index!
168
+
169
+ response = Article.search 'body:dummy'
170
+ assert_equal 1, response.results.size
171
+ assert_equal 1, response.records.size
172
+ end
173
+
149
174
  should "return results for a DSL search" do
150
175
  response = Article.search query: { match: { title: { query: 'test' } } }
151
176
 
@@ -20,28 +20,28 @@ module Elasticsearch
20
20
  end
21
21
  end
22
22
 
23
- class ::Episode < ActiveRecord::Base
24
- include Elasticsearch::Model
25
- include Elasticsearch::Model::Callbacks
23
+ module ::NameSearch
24
+ extend ActiveSupport::Concern
25
+
26
+ included do
27
+ include Elasticsearch::Model
28
+ include Elasticsearch::Model::Callbacks
26
29
 
27
- settings index: {number_of_shards: 1, number_of_replicas: 0} do
28
- mapping do
29
- indexes :name, type: 'string', analyzer: 'snowball'
30
- indexes :created_at, type: 'date'
30
+ settings index: {number_of_shards: 1, number_of_replicas: 0} do
31
+ mapping do
32
+ indexes :name, type: 'string', analyzer: 'snowball'
33
+ indexes :created_at, type: 'date'
34
+ end
31
35
  end
32
36
  end
33
37
  end
34
38
 
35
- class ::Series < ActiveRecord::Base
36
- include Elasticsearch::Model
37
- include Elasticsearch::Model::Callbacks
39
+ class ::Episode < ActiveRecord::Base
40
+ include NameSearch
41
+ end
38
42
 
39
- settings index: {number_of_shards: 1, number_of_replicas: 0} do
40
- mapping do
41
- indexes :name, type: 'string', analyzer: 'snowball'
42
- indexes :created_at, type: 'date'
43
- end
44
- end
43
+ class ::Series < ActiveRecord::Base
44
+ include NameSearch
45
45
  end
46
46
 
47
47
  [::Episode, ::Series].each do |model|
@@ -56,7 +56,7 @@ module Elasticsearch
56
56
  end
57
57
 
58
58
  should "find matching documents across multiple models" do
59
- response = Elasticsearch::Model.search("greatest", [Series, Episode])
59
+ response = Elasticsearch::Model.search(%q<"The greatest Episode"^2 OR "The greatest Series">, [Series, Episode])
60
60
 
61
61
  assert response.any?, "Response should not be empty: #{response.to_a.inspect}"
62
62
 
@@ -75,22 +75,40 @@ module Elasticsearch
75
75
  end
76
76
 
77
77
  should "provide access to results" do
78
- q = {query: {query_string: {query: 'A great *'}}, highlight: {fields: {name: {}}}}
79
- response = Elasticsearch::Model.search(q, [Series, Episode])
78
+ response = Elasticsearch::Model.search(%q<"A great Episode"^2 OR "A great Series">, [Series, Episode])
80
79
 
81
80
  assert_equal 'A great Episode', response.results[0].name
82
81
  assert_equal true, response.results[0].name?
83
82
  assert_equal false, response.results[0].boo?
84
- assert_equal true, response.results[0].highlight?
85
- assert_equal true, response.results[0].highlight.name?
86
- assert_equal false, response.results[0].highlight.boo?
87
83
 
88
84
  assert_equal 'A great Series', response.results[1].name
89
85
  assert_equal true, response.results[1].name?
90
86
  assert_equal false, response.results[1].boo?
91
- assert_equal true, response.results[1].highlight?
92
- assert_equal true, response.results[1].highlight.name?
93
- assert_equal false, response.results[1].highlight.boo?
87
+ end
88
+
89
+ should "only retrieve records for existing results" do
90
+ ::Series.find_by_name("The greatest Series").delete
91
+ ::Series.__elasticsearch__.refresh_index!
92
+ response = Elasticsearch::Model.search(%q<"The greatest Episode"^2 OR "The greatest Series">, [Series, Episode])
93
+
94
+ assert response.any?, "Response should not be empty: #{response.to_a.inspect}"
95
+
96
+ assert_equal 2, response.results.size
97
+ assert_equal 1, response.records.size
98
+
99
+ assert_instance_of Elasticsearch::Model::Response::Result, response.results.first
100
+ assert_instance_of Episode, response.records.first
101
+
102
+ assert_equal 'The greatest Episode', response.results[0].name
103
+ assert_equal 'The greatest Episode', response.records[0].name
104
+ end
105
+
106
+ should "paginate the results" do
107
+ response = Elasticsearch::Model.search('series OR episode', [Series, Episode])
108
+
109
+ assert_equal 3, response.page(1).per(3).results.size
110
+ assert_equal 3, response.page(2).per(3).results.size
111
+ assert_equal 0, response.page(3).per(3).results.size
94
112
  end
95
113
 
96
114
  if Mongo.available?
@@ -128,7 +146,7 @@ module Elasticsearch
128
146
  end
129
147
 
130
148
  should "find matching documents across multiple models" do
131
- response = Elasticsearch::Model.search("greatest", [Episode, Image])
149
+ response = Elasticsearch::Model.search(%q<"greatest Episode" OR "greatest Image"^2>, [Episode, Image])
132
150
 
133
151
  assert response.any?, "Response should not be empty: #{response.to_a.inspect}"
134
152
 
@@ -0,0 +1 @@
1
+ { "baz": "qux" }
@@ -0,0 +1,2 @@
1
+ baz:
2
+ 'qux'
@@ -76,7 +76,9 @@ class Elasticsearch::Model::AdapterMongoidTest < Test::Unit::TestCase
76
76
 
77
77
  context "Importing" do
78
78
  should "implement the __find_in_batches method" do
79
- DummyClassForMongoid.expects(:all).returns([])
79
+ relation = mock()
80
+ relation.stubs(:no_timeout).returns([])
81
+ DummyClassForMongoid.expects(:all).returns(relation)
80
82
 
81
83
  DummyClassForMongoid.__send__ :extend, Elasticsearch::Model::Adapter::Mongoid::Importing
82
84
  DummyClassForMongoid.__find_in_batches do; end
@@ -44,6 +44,7 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
44
44
  DummyImportingModel.expects(:client).returns(client)
45
45
  DummyImportingModel.expects(:index_name).returns('foo')
46
46
  DummyImportingModel.expects(:document_type).returns('foo')
47
+ DummyImportingModel.stubs(:index_exists?).returns(true)
47
48
  DummyImportingModel.stubs(:__batch_to_bulk)
48
49
  assert_equal 0, DummyImportingModel.import
49
50
  end
@@ -61,6 +62,7 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
61
62
  DummyImportingModel.stubs(:client).returns(client)
62
63
  DummyImportingModel.stubs(:index_name).returns('foo')
63
64
  DummyImportingModel.stubs(:document_type).returns('foo')
65
+ DummyImportingModel.stubs(:index_exists?).returns(true)
64
66
  DummyImportingModel.stubs(:__batch_to_bulk)
65
67
 
66
68
  assert_equal 1, DummyImportingModel.import
@@ -79,6 +81,7 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
79
81
  DummyImportingModel.stubs(:client).returns(client)
80
82
  DummyImportingModel.stubs(:index_name).returns('foo')
81
83
  DummyImportingModel.stubs(:document_type).returns('foo')
84
+ DummyImportingModel.stubs(:index_exists?).returns(true)
82
85
  DummyImportingModel.stubs(:__batch_to_bulk)
83
86
 
84
87
  assert_equal [{'index' => {'error' => 'FAILED'}}], DummyImportingModel.import(return: 'errors')
@@ -97,6 +100,7 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
97
100
  DummyImportingModel.stubs(:client).returns(client)
98
101
  DummyImportingModel.stubs(:index_name).returns('foo')
99
102
  DummyImportingModel.stubs(:document_type).returns('foo')
103
+ DummyImportingModel.stubs(:index_exists?).returns(true)
100
104
  DummyImportingModel.stubs(:__batch_to_bulk)
101
105
 
102
106
  DummyImportingModel.import do |response|
@@ -104,22 +108,42 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
104
108
  end
105
109
  end
106
110
 
107
- should "delete and create the index with the force option" do
108
- DummyImportingModel.expects(:__find_in_batches).with do |options|
109
- assert_equal 'bar', options[:foo]
110
- assert_nil options[:force]
111
- true
112
- end
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)
113
122
 
114
- DummyImportingModel.expects(:create_index!).with do |options|
115
- assert_equal true, options[:force]
116
- true
123
+ assert_raise ArgumentError do
124
+ DummyImportingModel.import
125
+ end
117
126
  end
127
+ end
118
128
 
119
- DummyImportingModel.expects(:index_name).returns('foo')
120
- DummyImportingModel.expects(:document_type).returns('foo')
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')
121
144
 
122
- DummyImportingModel.import force: true, foo: 'bar'
145
+ DummyImportingModel.import force: true, foo: 'bar'
146
+ end
123
147
  end
124
148
 
125
149
  should "allow passing a different index / type" do
@@ -141,6 +165,7 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
141
165
  .returns({'items' => [ {'index' => {} }]})
142
166
 
143
167
  DummyImportingModel.stubs(:client).returns(client)
168
+ DummyImportingModel.stubs(:index_exists?).returns(true)
144
169
  DummyImportingModel.stubs(:__batch_to_bulk)
145
170
 
146
171
  DummyImportingModel.import index: 'my-new-index', type: 'my-other-type'
@@ -151,6 +176,7 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
151
176
  transform = lambda {|a|}
152
177
 
153
178
  DummyImportingModel.stubs(:client).returns(client)
179
+ DummyImportingModel.stubs(:index_exists?).returns(true)
154
180
  DummyImportingModel.expects(:__transform).returns(transform)
155
181
  DummyImportingModel.expects(:__batch_to_bulk).with(anything, transform)
156
182
 
@@ -162,6 +188,7 @@ class Elasticsearch::Model::ImportingTest < Test::Unit::TestCase
162
188
  transform = lambda {|a|}
163
189
 
164
190
  DummyImportingModel.stubs(:client).returns(client)
191
+ DummyImportingModel.stubs(:index_exists?).returns(true)
165
192
  DummyImportingModel.expects(:__batch_to_bulk).with(anything, transform)
166
193
 
167
194
  DummyImportingModel.import index: 'foo', type: 'bar', transform: transform
@@ -28,13 +28,27 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
28
28
  assert_instance_of Elasticsearch::Model::Indexing::Settings, DummyIndexingModel.settings
29
29
  end
30
30
 
31
- should "update and return the index settings" do
31
+ should "update and return the index settings from a hash" do
32
32
  DummyIndexingModel.settings foo: 'boo'
33
33
  DummyIndexingModel.settings bar: 'bam'
34
34
 
35
35
  assert_equal( {foo: 'boo', bar: 'bam'}, DummyIndexingModel.settings.to_hash)
36
36
  end
37
37
 
38
+ should "update and return the index settings from a yml file" do
39
+ DummyIndexingModel.settings File.open("test/support/model.yml")
40
+ DummyIndexingModel.settings bar: 'bam'
41
+
42
+ assert_equal( {foo: 'boo', bar: 'bam', 'baz' => 'qux'}, DummyIndexingModel.settings.to_hash)
43
+ end
44
+
45
+ should "update and return the index settings from a json file" do
46
+ DummyIndexingModel.settings File.open("test/support/model.json")
47
+ DummyIndexingModel.settings bar: 'bam'
48
+
49
+ assert_equal( {foo: 'boo', bar: 'bam', 'baz' => 'qux'}, DummyIndexingModel.settings.to_hash)
50
+ end
51
+
38
52
  should "evaluate the block" do
39
53
  DummyIndexingModel.expects(:foo)
40
54
 
@@ -76,6 +90,28 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
76
90
  assert_equal 'string', mappings.to_hash[:mytype][:properties][:bar][:type]
77
91
  end
78
92
 
93
+ should "define multiple fields" do
94
+ mappings = Elasticsearch::Model::Indexing::Mappings.new :mytype
95
+
96
+ mappings.indexes :foo_1, type: 'string' do
97
+ indexes :raw, analyzer: 'keyword'
98
+ end
99
+
100
+ mappings.indexes :foo_2, type: 'multi_field' do
101
+ indexes :raw, analyzer: 'keyword'
102
+ end
103
+
104
+ assert_equal 'string', mappings.to_hash[:mytype][:properties][:foo_1][:type]
105
+ assert_equal 'string', mappings.to_hash[:mytype][:properties][:foo_1][:fields][:raw][:type]
106
+ assert_equal 'keyword', mappings.to_hash[:mytype][:properties][:foo_1][:fields][:raw][:analyzer]
107
+ assert_nil mappings.to_hash[:mytype][:properties][:foo_1][:properties]
108
+
109
+ assert_equal 'multi_field', mappings.to_hash[:mytype][:properties][:foo_2][:type]
110
+ assert_equal 'string', mappings.to_hash[:mytype][:properties][:foo_2][:fields][:raw][:type]
111
+ assert_equal 'keyword', mappings.to_hash[:mytype][:properties][:foo_2][:fields][:raw][:analyzer]
112
+ assert_nil mappings.to_hash[:mytype][:properties][:foo_2][:properties]
113
+ end
114
+
79
115
  should "define embedded properties" do
80
116
  mappings = Elasticsearch::Model::Indexing::Mappings.new :mytype
81
117
 
@@ -83,20 +119,27 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
83
119
  indexes :bar
84
120
  end
85
121
 
86
- mappings.indexes :multi, type: 'multi_field' do
87
- indexes :multi, analyzer: 'snowball'
88
- indexes :raw, analyzer: 'keyword'
122
+ mappings.indexes :foo_object, type: 'object' do
123
+ indexes :bar
124
+ end
125
+
126
+ mappings.indexes :foo_nested, type: 'nested' do
127
+ indexes :bar
89
128
  end
90
129
 
130
+ # Object is the default when `type` is missing and there's a block passed
131
+ #
91
132
  assert_equal 'object', mappings.to_hash[:mytype][:properties][:foo][:type]
92
133
  assert_equal 'string', mappings.to_hash[:mytype][:properties][:foo][:properties][:bar][:type]
134
+ assert_nil mappings.to_hash[:mytype][:properties][:foo][:fields]
93
135
 
94
- assert_equal 'multi_field', mappings.to_hash[:mytype][:properties][:multi][:type]
95
- assert_equal 'snowball', mappings.to_hash[:mytype][:properties][:multi][:fields][:multi][:analyzer]
96
- assert_equal 'keyword', mappings.to_hash[:mytype][:properties][:multi][:fields][:raw][:analyzer]
97
- end
136
+ assert_equal 'object', mappings.to_hash[:mytype][:properties][:foo_object][:type]
137
+ assert_equal 'string', mappings.to_hash[:mytype][:properties][:foo_object][:properties][:bar][:type]
138
+ assert_nil mappings.to_hash[:mytype][:properties][:foo_object][:fields]
98
139
 
99
- should "define multi_field properties" do
140
+ assert_equal 'nested', mappings.to_hash[:mytype][:properties][:foo_nested][:type]
141
+ assert_equal 'string', mappings.to_hash[:mytype][:properties][:foo_nested][:properties][:bar][:type]
142
+ assert_nil mappings.to_hash[:mytype][:properties][:foo_nested][:fields]
100
143
  end
101
144
  end
102
145
 
@@ -106,8 +149,8 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
106
149
  end
107
150
 
108
151
  should "update and return the index mappings" do
109
- DummyIndexingModel.mappings foo: 'boo' do; end
110
- DummyIndexingModel.mappings bar: 'bam' do; end
152
+ DummyIndexingModel.mappings foo: 'boo'
153
+ DummyIndexingModel.mappings bar: 'bam'
111
154
  assert_equal( { dummy_indexing_model: { foo: "boo", bar: "bam", properties: {} } },
112
155
  DummyIndexingModel.mappings.to_hash )
113
156
  end
@@ -371,6 +414,55 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
371
414
  end
372
415
  end
373
416
 
417
+ context "Checking for index existence" do
418
+ context "the index exists" do
419
+ should "return true" do
420
+ indices = mock('indices', exists: true)
421
+ client = stub('client', indices: indices)
422
+
423
+ DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
424
+
425
+ assert_equal true, DummyIndexingModelForRecreate.index_exists?
426
+ end
427
+ end
428
+
429
+ context "the index does not exists" do
430
+ should "return false" do
431
+ indices = mock('indices', exists: false)
432
+ client = stub('client', indices: indices)
433
+
434
+ DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
435
+
436
+ assert_equal false, DummyIndexingModelForRecreate.index_exists?
437
+ end
438
+ end
439
+
440
+ context "the indices raises" do
441
+ should "return false" do
442
+ client = stub('client')
443
+ client.expects(:indices).raises(StandardError)
444
+
445
+ DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
446
+
447
+ assert_equal false, DummyIndexingModelForRecreate.index_exists?
448
+ end
449
+ end
450
+
451
+ context "the indices raises" do
452
+ should "return false" do
453
+ indices = stub('indices')
454
+ client = stub('client')
455
+ client.expects(:indices).returns(indices)
456
+
457
+ indices.expects(:exists).raises(StandardError)
458
+
459
+ DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
460
+
461
+ assert_equal false, DummyIndexingModelForRecreate.index_exists?
462
+ end
463
+ end
464
+ end
465
+
374
466
  context "Re-creating the index" do
375
467
  class ::DummyIndexingModelForRecreate
376
468
  extend ActiveModel::Naming
@@ -425,8 +517,6 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
425
517
  indices = stub('indices')
426
518
  client.stubs(:indices).returns(indices)
427
519
 
428
- indices.expects(:exists).returns(false)
429
-
430
520
  indices.expects(:create).with do |payload|
431
521
  assert_equal 'dummy_indexing_model_for_recreates', payload[:index]
432
522
  assert_equal 1, payload[:body][:settings][:index][:number_of_shards]
@@ -434,6 +524,7 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
434
524
  true
435
525
  end.returns({})
436
526
 
527
+ DummyIndexingModelForRecreate.expects(:index_exists?).returns(false)
437
528
  DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
438
529
 
439
530
  assert_nothing_raised { DummyIndexingModelForRecreate.create_index! }
@@ -444,11 +535,10 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
444
535
  indices = stub('indices')
445
536
  client.stubs(:indices).returns(indices)
446
537
 
447
- indices.expects(:exists).returns(true)
448
-
449
538
  indices.expects(:create).never
450
539
 
451
- DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
540
+ DummyIndexingModelForRecreate.expects(:index_exists?).returns(true)
541
+ DummyIndexingModelForRecreate.expects(:client).returns(client).never
452
542
 
453
543
  assert_nothing_raised { DummyIndexingModelForRecreate.create_index! }
454
544
  end
@@ -459,9 +549,9 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
459
549
  client.stubs(:indices).returns(indices)
460
550
 
461
551
  indices.expects(:delete).returns({})
462
- indices.expects(:exists).returns(false)
463
- indices.expects(:create).raises(Exception)
552
+ indices.expects(:create).raises(Exception).at_least_once
464
553
 
554
+ DummyIndexingModelForRecreate.expects(:index_exists?).returns(false)
465
555
  DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
466
556
 
467
557
  assert_raise(Exception) { DummyIndexingModelForRecreate.create_index! force: true }
@@ -473,9 +563,9 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
473
563
  client.stubs(:indices).returns(indices)
474
564
 
475
565
  indices.expects(:delete).returns({})
476
- indices.expects(:exists).returns(false)
477
566
  indices.expects(:create).returns({}).at_least_once
478
567
 
568
+ DummyIndexingModelForRecreate.expects(:index_exists?).returns(false)
479
569
  DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
480
570
 
481
571
  assert_nothing_raised do
@@ -516,12 +606,11 @@ class Elasticsearch::Model::IndexingTest < Test::Unit::TestCase
516
606
  end
517
607
 
518
608
  should "create the custom index" do
519
- @indices.expects(:exists).with do |arguments|
609
+ @indices.expects(:create).with do |arguments|
520
610
  assert_equal 'custom-foo', arguments[:index]
521
611
  true
522
612
  end
523
-
524
- @indices.expects(:create).with do |arguments|
613
+ DummyIndexingModelForRecreate.expects(:index_exists?).with do |arguments|
525
614
  assert_equal 'custom-foo', arguments[:index]
526
615
  true
527
616
  end