Skip to content

Commit db2ae7b

Browse files
committed
Configure index settings before tests to reset them
1 parent eaff378 commit db2ae7b

File tree

1 file changed

+94
-14
lines changed

1 file changed

+94
-14
lines changed

spec/meilisearch/index/settings_spec.rb

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,18 @@
7474
end
7575

7676
it 'resets all settings' do
77+
response = index.update_settings(
78+
rankingRules: ['title:asc', 'typo'],
79+
distinctAttribute: 'title',
80+
stopWords: ['the', 'a'],
81+
synonyms: { wow: ['world of warcraft'] }
82+
)
83+
index.wait_for_pending_update(response['updateId'])
84+
7785
response = index.reset_settings
7886
expect(response).to have_key('updateId')
7987
index.wait_for_pending_update(response['updateId'])
88+
8089
settings = index.settings
8190
expect(settings['rankingRules']).to eq(default_ranking_rules)
8291
expect(settings['distinctAttribute']).to be_nil
@@ -108,60 +117,75 @@
108117
end
109118

110119
it 'updates ranking rules at null' do
120+
response = index.update_ranking_rules(ranking_rules)
121+
index.wait_for_pending_update(response['updateId'])
122+
111123
response = index.update_ranking_rules(nil)
112124
expect(response).to have_key('updateId')
113125
index.wait_for_pending_update(response['updateId'])
126+
114127
expect(index.ranking_rules).to eq(default_ranking_rules)
115128
end
116129

117130
it 'fails when updating with wrong ranking rules name' do
118131
response = index.update_ranking_rules(wrong_ranking_rules)
119132
index.wait_for_pending_update(response['updateId'])
133+
120134
response = index.get_update_status(response['updateId'])
135+
121136
expect(response.keys).to include('message')
122137
expect(response['errorCode']).to eq('invalid_request')
123138
end
124139

125140
it 'resets ranking rules' do
141+
response = index.update_ranking_rules(ranking_rules)
142+
index.wait_for_pending_update(response['updateId'])
143+
126144
response = index.reset_ranking_rules
127145
expect(response).to have_key('updateId')
128146
index.wait_for_pending_update(response['updateId'])
147+
129148
expect(index.ranking_rules).to eq(default_ranking_rules)
130149
end
131150
end
132151

133152
context 'On distinct-attribute sub-routes' do
134-
before do
135-
@uid = random_uid
136-
client.create_index(@uid)
137-
end
138-
139-
let(:index) { client.index(@uid) }
153+
let(:uid) { random_uid }
154+
let(:index) { client.index(uid) }
140155
let(:distinct_attribute) { 'title' }
141156

142157
it 'gets default values of distinct attribute' do
158+
client.create_index(uid)
143159
response = index.distinct_attribute
160+
144161
expect(response).to be_nil
145162
end
146163

147164
it 'updates distinct attribute' do
148165
response = index.update_distinct_attribute(distinct_attribute)
149166
expect(response).to have_key('updateId')
150167
index.wait_for_pending_update(response['updateId'])
168+
151169
expect(index.distinct_attribute).to eq(distinct_attribute)
152170
end
153171

154172
it 'updates distinct attribute at null' do
173+
response = index.update_distinct_attribute(distinct_attribute)
174+
index.wait_for_pending_update(response['updateId'])
175+
155176
response = index.update_distinct_attribute(nil)
156-
expect(response).to have_key('updateId')
157177
index.wait_for_pending_update(response['updateId'])
178+
158179
expect(index.distinct_attribute).to be_nil
159180
end
160181

161182
it 'resets distinct attribute' do
183+
response = index.update_distinct_attribute(distinct_attribute)
184+
index.wait_for_pending_update(response['updateId'])
185+
162186
response = index.reset_distinct_attribute
163-
expect(response).to have_key('updateId')
164187
index.wait_for_pending_update(response['updateId'])
188+
165189
expect(index.distinct_attribute).to be_nil
166190
end
167191
end
@@ -188,16 +212,24 @@
188212
end
189213

190214
it 'updates searchable attributes at null' do
215+
response = index.update_searchable_attributes(searchable_attributes)
216+
index.wait_for_pending_update(response['updateId'])
217+
191218
response = index.update_searchable_attributes(nil)
192219
expect(response).to have_key('updateId')
220+
193221
index.wait_for_pending_update(response['updateId'])
194222
expect(index.searchable_attributes).to eq(default_searchable_attributes)
195223
end
196224

197225
it 'resets searchable attributes' do
226+
response = index.update_searchable_attributes(searchable_attributes)
227+
index.wait_for_pending_update(response['updateId'])
228+
198229
response = index.reset_searchable_attributes
199230
expect(response).to have_key('updateId')
200231
index.wait_for_pending_update(response['updateId'])
232+
201233
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
202234
expect(index.searchable_attributes).to eq(default_searchable_attributes)
203235
end
@@ -221,20 +253,29 @@
221253
response = index.update_displayed_attributes(displayed_attributes)
222254
expect(response).to have_key('updateId')
223255
index.wait_for_pending_update(response['updateId'])
256+
224257
expect(index.displayed_attributes).to contain_exactly(*displayed_attributes)
225258
end
226259

227260
it 'updates displayed attributes at null' do
261+
response = index.update_displayed_attributes(displayed_attributes)
262+
index.wait_for_pending_update(response['updateId'])
263+
228264
response = index.update_displayed_attributes(nil)
229265
expect(response).to have_key('updateId')
230266
index.wait_for_pending_update(response['updateId'])
267+
231268
expect(index.displayed_attributes).to eq(default_displayed_attributes)
232269
end
233270

234271
it 'resets displayed attributes' do
272+
response = index.update_displayed_attributes(displayed_attributes)
273+
index.wait_for_pending_update(response['updateId'])
274+
235275
response = index.reset_displayed_attributes
236276
expect(response).to have_key('updateId')
237277
index.wait_for_pending_update(response['updateId'])
278+
238279
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
239280
expect(index.displayed_attributes).to eq(default_displayed_attributes)
240281
end
@@ -353,9 +394,13 @@
353394
end
354395

355396
it 'updates stop-words at null' do
397+
response = index.update_stop_words(stop_words_string)
398+
index.wait_for_pending_update(response['updateId'])
399+
356400
response = index.update_stop_words(nil)
357401
expect(response).to have_key('updateId')
358402
index.wait_for_pending_update(response['updateId'])
403+
359404
expect(index.stop_words).to be_empty
360405
end
361406

@@ -366,10 +411,14 @@
366411
end
367412

368413
it 'resets stop-words' do
414+
response = index.update_stop_words(stop_words_string)
415+
index.wait_for_pending_update(response['updateId'])
416+
369417
response = index.reset_stop_words
370418
expect(response).to be_a(Hash)
371419
expect(response).to have_key('updateId')
372420
index.wait_for_pending_update(response['updateId'])
421+
373422
expect(index.stop_words).to be_a(Array)
374423
expect(index.stop_words).to be_empty
375424
end
@@ -398,16 +447,24 @@
398447
end
399448

400449
it 'updates filterable attributes at null' do
450+
response = index.update_filterable_attributes(filterable_attributes)
451+
expect(response).to have_key('updateId')
452+
401453
response = index.update_filterable_attributes(nil)
402454
expect(response).to have_key('updateId')
403455
index.wait_for_pending_update(response['updateId'])
456+
404457
expect(index.filterable_attributes).to be_empty
405458
end
406459

407460
it 'resets filterable attributes' do
461+
response = index.update_filterable_attributes(filterable_attributes)
462+
expect(response).to have_key('updateId')
463+
408464
response = index.reset_filterable_attributes
409465
expect(response).to have_key('updateId')
410466
index.wait_for_pending_update(response['updateId'])
467+
411468
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
412469
expect(index.filterable_attributes).to be_empty
413470
end
@@ -436,16 +493,24 @@
436493
end
437494

438495
it 'updates sortable attributes at null' do
496+
response = index.update_sortable_attributes(sortable_attributes)
497+
index.wait_for_pending_update(response['updateId'])
498+
439499
response = index.update_sortable_attributes(nil)
440500
expect(response).to have_key('updateId')
441501
index.wait_for_pending_update(response['updateId'])
502+
442503
expect(index.sortable_attributes).to be_empty
443504
end
444505

445506
it 'resets sortable attributes' do
507+
response = index.update_sortable_attributes(sortable_attributes)
508+
index.wait_for_pending_update(response['updateId'])
509+
446510
response = index.reset_sortable_attributes
447511
expect(response).to have_key('updateId')
448512
index.wait_for_pending_update(response['updateId'])
513+
449514
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
450515
expect(index.sortable_attributes).to be_empty
451516
end
@@ -496,9 +561,20 @@
496561
end
497562

498563
it 'resets all settings' do
564+
response = index.update_settings(
565+
rankingRules: ['title:asc', 'typo'],
566+
distinctAttribute: 'title',
567+
stopWords: ['the'],
568+
synonyms: {
569+
wow: ['world of warcraft']
570+
}
571+
)
572+
index.wait_for_pending_update(response['updateId'])
573+
499574
response = index.reset_settings
500575
expect(response).to have_key('updateId')
501576
index.wait_for_pending_update(response['updateId'])
577+
502578
settings = index.settings
503579
expect(settings['rankingRules']).to eq(default_ranking_rules)
504580
expect(settings['distinctAttribute']).to be_nil
@@ -508,12 +584,7 @@
508584
end
509585

510586
context 'Manipulation of searchable/displayed attributes with the primary-key' do
511-
before do
512-
@uid = random_uid
513-
client.create_index(@uid)
514-
end
515-
516-
let(:index) { client.index(@uid) }
587+
let(:index) { client.index(random_uid) }
517588

518589
it 'does not add document when there is no primary-key' do
519590
response = index.add_documents(title: 'Test')
@@ -531,14 +602,23 @@
531602
end
532603

533604
it 'resets searchable/displayed attributes' do
605+
response = index.update_displayed_attributes(['title', 'description'])
606+
index.wait_for_pending_update(response['updateId'])
607+
response = index.update_searchable_attributes(['title'])
608+
expect(response).to have_key('updateId')
609+
index.wait_for_pending_update(response['updateId'])
610+
534611
response = index.reset_displayed_attributes
535612
expect(response).to have_key('updateId')
536613
index.wait_for_pending_update(response['updateId'])
537614
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
615+
538616
response = index.reset_searchable_attributes
539617
expect(response).to have_key('updateId')
540618
index.wait_for_pending_update(response['updateId'])
541619
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
620+
621+
expect(index.displayed_attributes).to eq(['*'])
542622
expect(index.searchable_attributes).to eq(['*'])
543623
end
544624
end

0 commit comments

Comments
 (0)