Skip to content

Commit

Permalink
Update user dict methods to use Model::Task
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix committed Oct 12, 2023
1 parent 20cf10a commit ae278d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
6 changes: 4 additions & 2 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,13 @@ def dictionary

def update_dictionary(dictionary_attributes)
attributes = Utils.transform_attributes(dictionary_attributes)
http_put("/indexes/#{@uid}/settings/dictionary", attributes)
response = http_put("/indexes/#{@uid}/settings/dictionary", attributes)
MeiliSearch::Model::Task.new(response, task_endpoint)
end

def reset_dictionary
http_delete("/indexes/#{@uid}/settings/dictionary")
response = http_delete("/indexes/#{@uid}/settings/dictionary")
MeiliSearch::Model::Task.new(response, task_endpoint)
end
### SETTINGS - SEPARATOR TOKENS

Expand Down
24 changes: 9 additions & 15 deletions spec/meilisearch/index/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -655,29 +655,23 @@
context 'On user-defined dictionary' do
let(:index) { client.index(uid) }

before { client.create_index!(uid) }
before { client.create_index(uid).await }

it 'has no default value' do
settings = index.dictionary

expect(settings).to be_empty
expect(index.dictionary).to eq([])
end

it 'updates dictionary' do
update_task = index.update_dictionary(['J. R. R.', 'W. E. B.'])
client.wait_for_task(update_task['taskUid'])

it '#update_dictionary updates dictionary' do
index.update_dictionary(['J. R. R.', 'W. E. B.']).await
expect(index.dictionary).to contain_exactly('J. R. R.', 'W. E. B.')
end

it 'resets dictionary' do
update_task = index.update_dictionary(['J. R. R.', 'W. E. B.'])
client.wait_for_task(update_task['taskUid'])

reset_task = index.reset_dictionary
client.wait_for_task(reset_task['taskUid'])
it '#reset_dictionary resets dictionary' do
index.update_dictionary(['J. R. R.', 'W. E. B.']).await
expect(index.dictionary).to contain_exactly('J. R. R.', 'W. E. B.')

expect(index.dictionary).to be_empty
index.reset_dictionary.await
expect(index.dictionary).to eq([])
end
end

Expand Down

0 comments on commit ae278d8

Please sign in to comment.