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,15 +48,13 @@ def importing_mixin
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 )
56
54
end
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
60
allow ( DummyImportingModel ) . to receive ( :document_type ) . and_return ( 'foo' )
@@ -75,7 +72,6 @@ def importing_mixin
75
72
end
76
73
77
74
context 'when no options are provided' do
78
-
79
75
before do
80
76
expect ( DummyImportingModel ) . to receive ( :client ) . and_return ( client )
81
77
allow ( DummyImportingModel ) . to receive ( :index_exists? ) . and_return ( true )
@@ -87,7 +83,6 @@ def importing_mixin
87
83
end
88
84
89
85
context 'when there is an error' do
90
-
91
86
before do
92
87
expect ( DummyImportingModel ) . to receive ( :client ) . and_return ( client )
93
88
allow ( DummyImportingModel ) . to receive ( :index_exists? ) . and_return ( true )
@@ -102,14 +97,12 @@ def importing_mixin
102
97
end
103
98
104
99
context 'when the method is called with the option to return the errors' do
105
-
106
100
it 'returns the errors' do
107
101
expect ( DummyImportingModel . import ( return : 'errors' ) ) . to eq ( [ { 'index' => { 'error' => 'FAILED' } } ] )
108
102
end
109
103
end
110
104
111
105
context 'when the method is called with a block' do
112
-
113
106
it 'yields the response to the block' do
114
107
DummyImportingModel . import do |response |
115
108
expect ( response [ 'items' ] . size ) . to eq ( 2 )
@@ -119,7 +112,6 @@ def importing_mixin
119
112
end
120
113
121
114
context 'when the index does not exist' do
122
-
123
115
before do
124
116
allow ( DummyImportingModel ) . to receive ( :index_exists? ) . and_return ( false )
125
117
end
@@ -132,7 +124,6 @@ def importing_mixin
132
124
end
133
125
134
126
context 'when the method is called with the force option' do
135
-
136
127
before do
137
128
expect ( DummyImportingModel ) . to receive ( :create_index! ) . with ( force : true , index : 'foo' ) . and_return ( true )
138
129
expect ( DummyImportingModel ) . to receive ( :__find_in_batches ) . with ( foo : 'bar' ) . and_return ( true )
@@ -144,7 +135,6 @@ def importing_mixin
144
135
end
145
136
146
137
context 'when the method is called with the refresh option' do
147
-
148
138
before do
149
139
expect ( DummyImportingModel ) . to receive ( :refresh_index! ) . with ( index : 'foo' ) . and_return ( true )
150
140
expect ( DummyImportingModel ) . to receive ( :__find_in_batches ) . with ( foo : 'bar' ) . and_return ( true )
@@ -156,7 +146,6 @@ def importing_mixin
156
146
end
157
147
158
148
context 'when a different index name is provided' do
159
-
160
149
before do
161
150
expect ( DummyImportingModel ) . to receive ( :client ) . and_return ( client )
162
151
expect ( client ) . to receive ( :bulk ) . with ( body : nil , index : 'my-new-index' , type : 'foo' ) . and_return ( response )
@@ -168,7 +157,6 @@ def importing_mixin
168
157
end
169
158
170
159
context 'when a different document type is provided' do
171
-
172
160
before do
173
161
expect ( DummyImportingModel ) . to receive ( :client ) . and_return ( client )
174
162
expect ( client ) . to receive ( :bulk ) . with ( body : nil , index : 'foo' , type : 'my-new-type' ) . and_return ( response )
@@ -180,7 +168,6 @@ def importing_mixin
180
168
end
181
169
182
170
context 'the transform method' do
183
-
184
171
before do
185
172
expect ( DummyImportingModel ) . to receive ( :client ) . and_return ( client )
186
173
expect ( DummyImportingModel ) . to receive ( :__transform ) . and_return ( transform )
@@ -197,9 +184,7 @@ def importing_mixin
197
184
end
198
185
199
186
context 'when a transform is provided as an option' do
200
-
201
187
context 'when the transform option is not a lambda' do
202
-
203
188
let ( :transform ) do
204
189
'not_callable'
205
190
end
@@ -212,7 +197,6 @@ def importing_mixin
212
197
end
213
198
214
199
context 'when the transform option is a lambda' do
215
-
216
200
before do
217
201
expect ( DummyImportingModel ) . to receive ( :client ) . and_return ( client )
218
202
expect ( DummyImportingModel ) . to receive ( :__batch_to_bulk ) . with ( anything , transform )
@@ -229,7 +213,6 @@ def importing_mixin
229
213
end
230
214
231
215
context 'when a pipeline is provided as an options' do
232
-
233
216
before do
234
217
expect ( DummyImportingModel ) . to receive ( :client ) . and_return ( client )
235
218
expect ( client ) . to receive ( :bulk ) . with ( body : nil , index : 'foo' , type : 'foo' , pipeline : 'my-pipeline' ) . and_return ( response )
0 commit comments