From 7a39c9c3107af390b800e9b0ebd6ec5f939df7f1 Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:55:38 +0200 Subject: [PATCH] Update (non) separator methods to use Model::Task --- lib/meilisearch/index.rb | 12 +++-- spec/meilisearch/index/settings_spec.rb | 62 ++++++++++--------------- 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 29421da9..fcff40a4 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -546,11 +546,13 @@ def separator_tokens def update_separator_tokens(separator_tokens_attributes) attributes = Utils.transform_attributes(separator_tokens_attributes) - http_put("/indexes/#{@uid}/settings/separator-tokens", attributes) + response = http_put("/indexes/#{@uid}/settings/separator-tokens", attributes) + MeiliSearch::Model::Task.new(response, task_endpoint) end def reset_separator_tokens - http_delete("/indexes/#{@uid}/settings/separator-tokens") + response = http_delete("/indexes/#{@uid}/settings/separator-tokens") + MeiliSearch::Model::Task.new(response, task_endpoint) end ### SETTINGS - NON SEPARATOR TOKENS @@ -561,11 +563,13 @@ def non_separator_tokens def update_non_separator_tokens(non_separator_tokens_attributes) attributes = Utils.transform_attributes(non_separator_tokens_attributes) - http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes) + response = http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes) + MeiliSearch::Model::Task.new(response, task_endpoint) end def reset_non_separator_tokens - http_delete("/indexes/#{@uid}/settings/non-separator-tokens") + response = http_delete("/indexes/#{@uid}/settings/non-separator-tokens") + MeiliSearch::Model::Task.new(response, task_endpoint) end end end diff --git a/spec/meilisearch/index/settings_spec.rb b/spec/meilisearch/index/settings_spec.rb index 59b5bd3a..2fd81914 100644 --- a/spec/meilisearch/index/settings_spec.rb +++ b/spec/meilisearch/index/settings_spec.rb @@ -678,52 +678,40 @@ context 'On separator tokens' do let(:index) { client.index(uid) } - before { client.create_index!(uid) } - - describe 'separator_tokens' do - it 'has no default value' do - expect(index.separator_tokens).to be_empty - end - - it 'updates separator tokens' do - update_task = index.update_separator_tokens ['|', '…'] - client.wait_for_task(update_task['taskUid']) - - expect(index.separator_tokens).to contain_exactly('|', '…') - end - - it 'resets separator tokens' do - update_task = index.update_separator_tokens ['|', '…'] - client.wait_for_task(update_task['taskUid']) + before { client.create_index(uid).await } - reset_task = index.reset_separator_tokens - client.wait_for_task(reset_task['taskUid']) + it '#separator_tokens has no default value' do + expect(index.separator_tokens).to eq([]) + end - expect(index.separator_tokens).to be_empty - end + it '#update_separator_tokens updates separator tokens' do + index.update_separator_tokens(['|', '…']).await + expect(index.separator_tokens).to contain_exactly('|', '…') end - describe '#non_separator_tokens' do - it 'has no default value' do - expect(index.non_separator_tokens).to be_empty - end + it '#reset_separator_tokens resets separator tokens' do + index.update_separator_tokens(['|', '…']).await + expect(index.separator_tokens).to contain_exactly('|', '…') - it 'updates non separator tokens' do - update_task = index.update_non_separator_tokens ['@', '#'] - client.wait_for_task(update_task['taskUid']) + index.reset_separator_tokens.await + expect(index.separator_tokens).to eq([]) + end - expect(index.non_separator_tokens).to contain_exactly('@', '#') - end + it '#non_separator_tokens has no default value' do + expect(index.non_separator_tokens).to eq([]) + end - it 'resets non separator tokens' do - update_task = index.update_non_separator_tokens ['@', '#'] - client.wait_for_task(update_task['taskUid']) + it '#update_non_separator_tokens updates non separator tokens' do + index.update_non_separator_tokens(['@', '#']).await + expect(index.non_separator_tokens).to contain_exactly('@', '#') + end - reset_task = index.reset_non_separator_tokens - client.wait_for_task(reset_task['taskUid']) + it '#reset_non_separator_tokens resets non separator tokens' do + index.update_non_separator_tokens(['@', '#']).await + expect(index.non_separator_tokens).to contain_exactly('@', '#') - expect(index.non_separator_tokens).to be_empty - end + index.reset_non_separator_tokens.await + expect(index.non_separator_tokens).to eq([]) end end end