elasticsearch-persistence 7.2.1 → 8.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,180 +18,54 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe Elasticsearch::Persistence::Repository::Search do
21
-
22
21
  after do
23
22
  begin; repository.delete_index!; rescue; end
24
23
  end
25
24
 
26
- describe '#search' do
25
+ let(:repository) do
26
+ DEFAULT_REPOSITORY
27
+ end
27
28
 
28
- let(:repository) do
29
- DEFAULT_REPOSITORY
29
+ describe '#search' do
30
+ before do
31
+ repository.save({ name: 'user' }, refresh: true)
30
32
  end
31
33
 
32
- context 'when the repository does not have a type set' do
33
-
34
- before do
35
- repository.save({ name: 'user' }, refresh: true)
36
- end
37
-
38
- context 'when a query definition is provided as a hash' do
39
-
40
- it 'uses the default document type' do
41
- expect(repository.search({ query: { match: { name: 'user' } } }).first).to eq('name' => 'user')
42
- end
43
- end
44
-
45
- context 'when a query definition is provided as a string' do
46
-
47
- it 'uses the default document type' do
48
- expect(repository.search('user').first).to eq('name' => 'user')
49
- end
50
- end
51
-
52
- context 'when the query definition is neither a String nor a Hash' do
53
-
54
- it 'raises an ArgumentError' do
55
- expect {
56
- repository.search(1)
57
- }.to raise_exception(ArgumentError)
58
- end
59
- end
60
-
61
- context 'when options are provided' do
62
-
63
- context 'when a query definition is provided as a hash' do
64
-
65
- it 'uses the default document type' do
66
- expect(repository.search({ query: { match: { name: 'user' } } }, type: 'other').first).to be_nil
67
- end
68
- end
69
-
70
- context 'when a query definition is provided as a string' do
71
-
72
- it 'uses the default document type' do
73
- expect(repository.search('user', type: 'other').first).to be_nil
74
- end
75
- end
76
-
77
- context 'when the query definition is neither a String nor a Hash' do
78
-
79
- it 'raises an ArgumentError' do
80
- expect {
81
- repository.search(1)
82
- }.to raise_exception(ArgumentError)
83
- end
84
- end
34
+ context 'when a query definition is provided as a hash' do
35
+ it 'searches' do
36
+ expect(repository.search({ query: { match: { name: 'user' } } }).first).to eq('name' => 'user')
85
37
  end
86
38
  end
87
39
 
88
- context 'when the repository does have a type set' do
89
-
90
- let(:repository) do
91
- MyTestRepository.new(document_type: 'other_note')
92
- end
93
-
94
- before do
95
- repository.save({ name: 'user' }, refresh: true)
40
+ context 'when a query definition is provided as a string' do
41
+ it 'searches' do
42
+ expect(repository.search('user').first).to eq('name' => 'user')
96
43
  end
44
+ end
97
45
 
98
- context 'when options are provided' do
99
-
100
- context 'when a query definition is provided as a hash' do
101
-
102
- it 'uses the options' do
103
- expect(repository.search({ query: { match: { name: 'user' } } }, type: 'other').first).to be_nil
104
- end
105
- end
106
-
107
- context 'when a query definition is provided as a string' do
108
-
109
- it 'uses the options' do
110
- expect(repository.search('user', type: 'other').first).to be_nil
111
- end
112
- end
113
-
114
- context 'when the query definition is neither a String nor a Hash' do
115
-
116
- it 'raises an ArgumentError' do
117
- expect {
118
- repository.search(1)
119
- }.to raise_exception(ArgumentError)
120
- end
121
- end
46
+ context 'when the query definition is neither a String nor a Hash' do
47
+ it 'raises an ArgumentError' do
48
+ expect {
49
+ repository.search(1)
50
+ }.to raise_exception(ArgumentError)
122
51
  end
123
52
  end
124
53
  end
125
54
 
126
55
  describe '#count' do
127
-
128
- context 'when the repository does not have a type set' do
129
-
130
- let(:repository) do
131
- DEFAULT_REPOSITORY
132
- end
133
-
134
- before do
135
- repository.save({ name: 'user' }, refresh: true)
136
- end
137
-
138
- context 'when a query definition is provided as a hash' do
139
-
140
- it 'uses the default document type' do
141
- expect(repository.count({ query: { match: { name: 'user' } } })).to eq(1)
142
- end
143
- end
144
-
145
- context 'when a query definition is provided as a string' do
146
-
147
- it 'uses the default document type' do
148
- expect(repository.count('user')).to eq(1)
149
- end
150
- end
151
-
152
- context 'when options are provided' do
153
-
154
- context 'when a query definition is provided as a hash' do
155
-
156
- it 'uses the options' do
157
- expect(repository.count({ query: { match: { name: 'user' } } }, type: 'other')).to eq(0)
158
- end
159
- end
160
-
161
- context 'when a query definition is provided as a string' do
162
-
163
- it 'uses the options' do
164
- expect(repository.count('user', type: 'other')).to eq(0)
165
- end
166
- end
167
- end
56
+ before do
57
+ repository.save({ name: 'usuario' }, refresh: true)
168
58
  end
169
59
 
170
- context 'when the repository does have a type set' do
171
-
172
- let(:repository) do
173
- MyTestRepository.new(document_type: 'other_note')
60
+ context 'when a query definition is provided as a hash' do
61
+ it 'uses the default document type' do
62
+ expect(repository.count({ query: { match: { name: 'usuario' } } })).to eq(1)
174
63
  end
64
+ end
175
65
 
176
- before do
177
- repository.save({ name: 'user' }, refresh: true)
178
- end
179
-
180
- context 'when options are provided' do
181
-
182
- context 'when a query definition is provided as a hash' do
183
-
184
- it 'uses the options' do
185
- expect(repository.count({ query: { match: { name: 'user' } } }, type: 'other')).to eq(0)
186
- end
187
- end
188
-
189
- context 'when a query definition is provided as a string' do
190
-
191
- it 'uses the options' do
192
- expect(repository.count('user', type: 'other')).to eq(0)
193
- end
194
- end
66
+ context 'when a query definition is provided as a string' do
67
+ it 'uses the default document type' do
68
+ expect(repository.count('usuario')).to eq(1)
195
69
  end
196
70
  end
197
71
  end
@@ -18,7 +18,6 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe Elasticsearch::Persistence::Repository::Store do
21
-
22
21
  let(:repository) do
23
22
  DEFAULT_REPOSITORY
24
23
  end
@@ -28,7 +27,6 @@ describe Elasticsearch::Persistence::Repository::Store do
28
27
  end
29
28
 
30
29
  describe '#save' do
31
-
32
30
  let(:document) do
33
31
  { a: 1 }
34
32
  end
@@ -42,7 +40,6 @@ describe Elasticsearch::Persistence::Repository::Store do
42
40
  end
43
41
 
44
42
  context 'when the repository defines a custom serialize method' do
45
-
46
43
  before do
47
44
  class OtherNoteRepository
48
45
  include Elasticsearch::Persistence::Repository
@@ -70,24 +67,9 @@ describe Elasticsearch::Persistence::Repository::Store do
70
67
  expect(repository.find(response['_id'])).to eq('b' => 1)
71
68
  end
72
69
  end
73
-
74
- context 'when options are provided' do
75
-
76
- let!(:response) do
77
- repository.save(document, type: 'other_note')
78
- end
79
-
80
- it 'saves the document using the options' do
81
- expect {
82
- repository.find(response['_id'])
83
- }.to raise_exception(Elasticsearch::Persistence::Repository::DocumentNotFound)
84
- expect(repository.find(response['_id'], type: 'other_note')).to eq('a' => 1)
85
- end
86
- end
87
70
  end
88
71
 
89
72
  describe '#update' do
90
-
91
73
  before(:all) do
92
74
  class Note
93
75
  def to_hash
@@ -103,15 +85,12 @@ describe Elasticsearch::Persistence::Repository::Store do
103
85
  end
104
86
 
105
87
  context 'when the document exists' do
106
-
107
88
  let!(:id) do
108
89
  repository.save(Note.new)['_id']
109
90
  end
110
91
 
111
92
  context 'when an id is provided' do
112
-
113
93
  context 'when a doc is specified in the options' do
114
-
115
94
  before do
116
95
  repository.update(id, doc: { text: 'testing_2' })
117
96
  end
@@ -122,7 +101,6 @@ describe Elasticsearch::Persistence::Repository::Store do
122
101
  end
123
102
 
124
103
  context 'when a script is specified in the options' do
125
-
126
104
  before do
127
105
  repository.update(id, script: { inline: 'ctx._source.views += 1' })
128
106
  end
@@ -133,7 +111,6 @@ describe Elasticsearch::Persistence::Repository::Store do
133
111
  end
134
112
 
135
113
  context 'when params are specified in the options' do
136
-
137
114
  before do
138
115
  repository.update(id, script: { inline: 'ctx._source.views += params.count',
139
116
  params: { count: 2 } })
@@ -145,7 +122,6 @@ describe Elasticsearch::Persistence::Repository::Store do
145
122
  end
146
123
 
147
124
  context 'when upsert is specified in the options' do
148
-
149
125
  before do
150
126
  repository.update(id, script: { inline: 'ctx._source.views += 1' },
151
127
  upsert: { text: 'testing_2' })
@@ -157,7 +133,6 @@ describe Elasticsearch::Persistence::Repository::Store do
157
133
  end
158
134
 
159
135
  context 'when doc_as_upsert is specified in the options' do
160
-
161
136
  before do
162
137
  repository.update(id, doc: { text: 'testing_2' },
163
138
  doc_as_upsert: true)
@@ -170,9 +145,7 @@ describe Elasticsearch::Persistence::Repository::Store do
170
145
  end
171
146
 
172
147
  context 'when a document is provided as the query criteria' do
173
-
174
148
  context 'when no options are provided' do
175
-
176
149
  before do
177
150
  repository.update(id: id, text: 'testing_2')
178
151
  end
@@ -183,9 +156,7 @@ describe Elasticsearch::Persistence::Repository::Store do
183
156
  end
184
157
 
185
158
  context 'when options are provided' do
186
-
187
159
  context 'when a doc is specified in the options' do
188
-
189
160
  before do
190
161
  repository.update({ id: id, text: 'testing' }, doc: { text: 'testing_2' })
191
162
  end
@@ -196,10 +167,11 @@ describe Elasticsearch::Persistence::Repository::Store do
196
167
  end
197
168
 
198
169
  context 'when a script is specified in the options' do
199
-
200
170
  before do
201
- repository.update({ id: id, text: 'testing' },
202
- script: { inline: 'ctx._source.views += 1' })
171
+ repository.update(
172
+ { id: id, text: 'testing' },
173
+ script: { inline: 'ctx._source.views += 1' }
174
+ )
203
175
  end
204
176
 
205
177
  it 'updates using the id and script from the options' do
@@ -208,7 +180,6 @@ describe Elasticsearch::Persistence::Repository::Store do
208
180
  end
209
181
 
210
182
  context 'when params are specified in the options' do
211
-
212
183
  before do
213
184
  repository.update({ id: id, text: 'testing' },
214
185
  script: { inline: 'ctx._source.views += params.count',
@@ -221,7 +192,6 @@ describe Elasticsearch::Persistence::Repository::Store do
221
192
  end
222
193
 
223
194
  context 'when upsert is specified in the options' do
224
-
225
195
  before do
226
196
  repository.update({ id: id, text: 'testing_2' },
227
197
  doc_as_upsert: true)
@@ -236,17 +206,14 @@ describe Elasticsearch::Persistence::Repository::Store do
236
206
  end
237
207
 
238
208
  context 'when the document does not exist' do
239
-
240
209
  context 'when an id is provided 'do
241
-
242
210
  it 'raises an exception' do
243
211
  expect {
244
212
  repository.update(1, doc: { text: 'testing_2' })
245
- }.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
213
+ }.to raise_exception(Elastic::Transport::Transport::Errors::NotFound)
246
214
  end
247
215
 
248
216
  context 'when upsert is provided' do
249
-
250
217
  before do
251
218
  repository.update(1, doc: { text: 'testing' }, doc_as_upsert: true)
252
219
  end
@@ -258,15 +225,13 @@ describe Elasticsearch::Persistence::Repository::Store do
258
225
  end
259
226
 
260
227
  context 'when a document is provided' do
261
-
262
228
  it 'raises an exception' do
263
229
  expect {
264
230
  repository.update(id: 1, text: 'testing_2')
265
- }.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
231
+ }.to raise_exception(Elastic::Transport::Transport::Errors::NotFound)
266
232
  end
267
233
 
268
234
  context 'when upsert is provided' do
269
-
270
235
  before do
271
236
  repository.update({ id: 1, text: 'testing' }, doc_as_upsert: true)
272
237
  end
@@ -280,7 +245,6 @@ describe Elasticsearch::Persistence::Repository::Store do
280
245
  end
281
246
 
282
247
  describe '#delete' do
283
-
284
248
  before(:all) do
285
249
  class Note
286
250
  def to_hash
@@ -296,13 +260,11 @@ describe Elasticsearch::Persistence::Repository::Store do
296
260
  end
297
261
 
298
262
  context 'when the document exists' do
299
-
300
263
  let!(:id) do
301
264
  repository.save(Note.new)['_id']
302
265
  end
303
266
 
304
267
  context 'an id is provided' do
305
-
306
268
  before do
307
269
  repository.delete(id)
308
270
  end
@@ -315,7 +277,6 @@ describe Elasticsearch::Persistence::Repository::Store do
315
277
  end
316
278
 
317
279
  context 'when a document is provided' do
318
-
319
280
  before do
320
281
  repository.delete(id: id, text: 'testing')
321
282
  end
@@ -329,15 +290,14 @@ describe Elasticsearch::Persistence::Repository::Store do
329
290
  end
330
291
 
331
292
  context 'when the document does not exist' do
332
-
333
293
  before do
334
- repository.create_index!(include_type_name: true)
294
+ repository.create_index!
335
295
  end
336
296
 
337
297
  it 'raises an exception' do
338
298
  expect {
339
299
  repository.delete(1)
340
- }.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
300
+ }.to raise_exception(Elastic::Transport::Transport::Errors::NotFound)
341
301
  end
342
302
  end
343
303
  end