Skip to content

Commit

Permalink
Update (non) separator 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 ae278d8 commit 7a39c9c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
12 changes: 8 additions & 4 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
62 changes: 25 additions & 37 deletions spec/meilisearch/index/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7a39c9c

Please sign in to comment.