Skip to content

Commit b7ae562

Browse files
committed
Rename test_client to simply client
1 parent 86eb0bd commit b7ae562

File tree

13 files changed

+95
-104
lines changed

13 files changed

+95
-104
lines changed
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
# frozen_string_literal: true
22

33
RSpec.describe 'MeiliSearch::Client - Dumps' do
4-
before(:all) do
5-
@client = MeiliSearch::Client.new(URL, MASTER_KEY)
6-
clear_all_indexes(@client)
7-
end
8-
94
it 'creates a new dump' do
10-
response = @client.create_dump
5+
response = client.create_dump
116
expect(response).to be_a(Hash)
127
expect(response['uid']).to_not be_nil
138
expect(response['status']).to_not be_nil
149
expect(response['status']).to eq('in_progress')
15-
wait_for_dump_creation(@client, response['uid'])
10+
wait_for_dump_creation(client, response['uid'])
1611
end
1712

1813
it 'gets dump status' do
19-
dump = @client.create_dump
20-
response = @client.dump_status(dump['uid'])
14+
dump = client.create_dump
15+
response = client.dump_status(dump['uid'])
2116
expect(response['status']).to_not be_nil
22-
wait_for_dump_creation(@client, dump['uid'])
17+
wait_for_dump_creation(client, dump['uid'])
2318
end
2419

2520
it 'fails to get dump status without uid' do
2621
expect do
27-
@client.dump_status('uid_not_exists')
22+
client.dump_status('uid_not_exists')
2823
end.to raise_meilisearch_api_error_with(404, 'not_found', 'invalid_request_error')
2924
end
3025

3126
it 'works with method aliases' do
32-
expect(@client.method(:dump_status) == @client.method(:get_dump_status)).to be_truthy
27+
expect(client.method(:dump_status) == client.method(:get_dump_status)).to be_truthy
3328
end
3429
end

spec/meilisearch/client/indexes_spec.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
RSpec.describe 'MeiliSearch::Client - Indexes' do
44
it 'creates an index without primary-key' do
5-
index = test_client.create_index('index')
5+
index = client.create_index('index')
66
expect(index).to be_a(MeiliSearch::Index)
77
expect(index.uid).to eq('index')
88
expect(index.primary_key).to be_nil
99
expect(index.fetch_primary_key).to be_nil
1010
end
1111

1212
it 'creates an index with primary-key' do
13-
index = test_client.create_index('index', primaryKey: 'primary_key')
13+
index = client.create_index('index', primaryKey: 'primary_key')
1414
expect(index).to be_a(MeiliSearch::Index)
1515
expect(index.uid).to eq('index')
1616
expect(index.primary_key).to eq('primary_key')
1717
expect(index.fetch_primary_key).to eq('primary_key')
1818
end
1919

2020
it 'creates an index with uid in options - should not take it into account' do
21-
index = test_client.create_index('index', primaryKey: 'primary_key', uid: 'wrong')
21+
index = client.create_index('index', primaryKey: 'primary_key', uid: 'wrong')
2222
expect(index).to be_a(MeiliSearch::Index)
2323
expect(index.uid).to eq('index')
2424
expect(index.primary_key).to eq('primary_key')
@@ -27,64 +27,64 @@
2727

2828
it 'creates an new index with get_or_create_index method' do
2929
expect do
30-
index = test_client.get_or_create_index('index')
30+
index = client.get_or_create_index('index')
3131

3232
expect(index).to be_a(MeiliSearch::Index)
3333
expect(index.uid).to eq('index')
3434
expect(index.primary_key).to be_nil
35-
end.to(change { test_client.indexes.length }.by(1))
35+
end.to(change { client.indexes.length }.by(1))
3636

37-
fetched_index = test_client.fetch_index('index')
37+
fetched_index = client.fetch_index('index')
3838
expect(fetched_index.uid).to eq('index')
3939
expect(fetched_index.primary_key).to be_nil
4040
end
4141

4242
it 'creates an new index with get_or_create_index method and a primary-key' do
4343
expect do
44-
index = test_client.get_or_create_index('index', primaryKey: 'title')
44+
index = client.get_or_create_index('index', primaryKey: 'title')
4545

4646
expect(index).to be_a(MeiliSearch::Index)
4747
expect(index.uid).to eq('index')
4848
expect(index.primary_key).to eq('title')
49-
end.to(change { test_client.indexes.length }.by(1))
49+
end.to(change { client.indexes.length }.by(1))
5050

51-
fetched_index = test_client.fetch_index('index')
51+
fetched_index = client.fetch_index('index')
5252
expect(fetched_index.uid).to eq('index')
5353
expect(fetched_index.primary_key).to eq('title')
5454
end
5555

5656
it 'get an already existing index with get_or_create_index method' do
57-
test_client.create_index(test_uid)
57+
client.create_index(test_uid)
5858

5959
expect do
60-
index = test_client.get_or_create_index(test_uid)
60+
index = client.get_or_create_index(test_uid)
6161

6262
expect(index).to be_a(MeiliSearch::Index)
6363
expect(index.uid).to eq(test_uid)
6464
expect(index.primary_key).to be_nil
65-
end.not_to(change { test_client.indexes.length })
65+
end.not_to(change { client.indexes.length })
6666
end
6767

6868
it 'fails to create an index with an uid already taken' do
69-
test_client.create_index(test_uid)
69+
client.create_index(test_uid)
7070

7171
expect do
72-
test_client.create_index(test_uid)
72+
client.create_index(test_uid)
7373
end.to raise_meilisearch_api_error_with(400, 'index_already_exists', 'invalid_request_error')
7474
end
7575

7676
it 'fails to create an index with bad UID format' do
7777
expect do
78-
test_client.create_index('two words')
78+
client.create_index('two words')
7979
end.to raise_meilisearch_api_error_with(400, 'invalid_index_uid', 'invalid_request_error')
8080
end
8181

8282
it 'gets list of indexes' do
83-
test_client.create_index('first_index')
84-
test_client.create_index('second_index')
85-
test_client.create_index('third_index')
83+
client.create_index('first_index')
84+
client.create_index('second_index')
85+
client.create_index('third_index')
8686

87-
indexes = test_client.indexes
87+
indexes = client.indexes
8888

8989
expect(indexes).to be_a(Array)
9090
expect(indexes.length).to eq(3)
@@ -93,9 +93,9 @@
9393
end
9494

9595
it 'fetch a specific index' do
96-
test_client.create_index('specific_index', primaryKey: 'primary_key')
96+
client.create_index('specific_index', primaryKey: 'primary_key')
9797

98-
response = test_client.fetch_index('specific_index')
98+
response = client.fetch_index('specific_index')
9999

100100
expect(response).to be_a(MeiliSearch::Index)
101101
expect(response.uid).to eq('specific_index')
@@ -104,9 +104,9 @@
104104
end
105105

106106
it 'returns an index object based on uid' do
107-
test_client.create_index('index_with_pk', primaryKey: 'primary_key')
107+
client.create_index('index_with_pk', primaryKey: 'primary_key')
108108

109-
index = test_client.index('index_with_pk')
109+
index = client.index('index_with_pk')
110110

111111
expect(index).to be_a(MeiliSearch::Index)
112112
expect(index.uid).to eq('index_with_pk')
@@ -117,21 +117,21 @@
117117

118118
it 'deletes index' do
119119
expect do
120-
test_client.create_index('index')
121-
end.to(change { test_client.indexes.length }.by(1))
120+
client.create_index('index')
121+
end.to(change { client.indexes.length }.by(1))
122122

123123
expect do
124-
expect(test_client.delete_index('index')).to be_nil
125-
end.to(change { test_client.indexes.length }.by(-1))
124+
expect(client.delete_index('index')).to be_nil
125+
end.to(change { client.indexes.length }.by(-1))
126126
end
127127

128128
context 'with snake_case options' do
129129
it 'creates an index without errors' do
130130
uid = SecureRandom.uuid
131131

132132
expect do
133-
@client.create_index(uid, primary_key: @primary_key)
134-
@client.fetch_index(uid)
133+
client.create_index(uid, primary_key: @primary_key)
134+
client.fetch_index(uid)
135135
end.to_not raise_error
136136
end
137137
end

spec/meilisearch/client/keys_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'MeiliSearch::Client - Keys' do
44
it 'gets the list of keys' do
5-
response = test_client.keys
5+
response = client.keys
66
expect(response).to be_a(Hash)
77
expect(response.count).to eq(2)
88
expect(response.keys).to contain_exactly('private', 'public')
@@ -11,15 +11,15 @@
1111
end
1212

1313
it 'fails to get settings if public key used' do
14-
public_key = test_client.keys['public']
14+
public_key = client.keys['public']
1515
new_client = MeiliSearch::Client.new(URL, public_key)
1616
expect do
1717
new_client.index(test_uid).settings
1818
end.to raise_meilisearch_api_error_with(403, 'invalid_token', 'authentication_error')
1919
end
2020

2121
it 'fails to get keys if private key used' do
22-
private_key = test_client.keys['private']
22+
private_key = client.keys['private']
2323
new_client = MeiliSearch::Client.new(URL, private_key)
2424
expect do
2525
new_client.keys
@@ -34,8 +34,8 @@
3434
end
3535

3636
it 'succeeds to search when using public key' do
37-
public_key = test_client.keys['public']
38-
index = test_client.create_index(test_uid)
37+
public_key = client.keys['public']
38+
index = client.create_index(test_uid)
3939
response = index.add_documents(title: 'Test')
4040
index.wait_for_pending_update(response['updateId'])
4141

@@ -45,14 +45,14 @@
4545
end
4646

4747
it 'succeeds to get settings when using private key' do
48-
test_client.create_index(test_uid)
49-
private_key = test_client.keys['private']
48+
client.create_index(test_uid)
49+
private_key = client.keys['private']
5050
new_client = MeiliSearch::Client.new(URL, private_key)
5151
response = new_client.index(test_uid).settings
5252
expect(response).to have_key('rankingRules')
5353
end
5454

5555
it 'works with method aliases' do
56-
expect(test_client.method(:keys) == test_client.method(:get_keys)).to be_truthy
56+
expect(client.method(:keys) == client.method(:get_keys)).to be_truthy
5757
end
5858
end
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# frozen_string_literal: true
22

33
RSpec.describe 'MeiliSearch::Client - Stats' do
4-
before(:all) do
5-
@client = MeiliSearch::Client.new(URL, MASTER_KEY)
6-
end
7-
84
it 'gets version' do
9-
response = @client.version
5+
response = client.version
106
expect(response).to be_a(Hash)
117
expect(response).to have_key('commitSha')
128
expect(response).to have_key('commitDate')
139
expect(response).to have_key('pkgVersion')
1410
end
1511

1612
it 'gets stats' do
17-
response = @client.stats
13+
response = client.stats
1814
expect(response).to have_key('databaseSize')
1915
end
2016
end

spec/meilisearch/index/base_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33
RSpec.describe MeiliSearch::Index do
44
it 'fetch the info of the index' do
5-
index = test_client.create_index('new_index')
5+
index = client.create_index('new_index')
66
index.fetch_info
77
expect(index).to be_a(MeiliSearch::Index)
88
expect(index.uid).to eq('new_index')
99
expect(index.primary_key).to be_nil
1010
end
1111

1212
it 'get primary-key of index if null' do
13-
index = test_client.create_index('index_without_primary_key')
13+
index = client.create_index('index_without_primary_key')
1414
expect(index.primary_key).to be_nil
1515
expect(index.fetch_primary_key).to be_nil
1616
end
1717

1818
it 'get primary-key of index if it exists' do
19-
index = test_client.create_index('index_with_prirmary_key', primaryKey: 'primary_key')
19+
index = client.create_index('index_with_prirmary_key', primaryKey: 'primary_key')
2020
expect(index.primary_key).to eq('primary_key')
2121
expect(index.fetch_primary_key).to eq('primary_key')
2222
end
2323

2424
it 'get uid of index' do
25-
index = test_client.create_index('uid')
25+
index = client.create_index('uid')
2626
expect(index.uid).to eq('uid')
2727
end
2828

2929
it 'updates primary-key of index if not defined before' do
30-
index = test_client.create_index('uid')
30+
index = client.create_index('uid')
3131
index.update(primaryKey: 'new_primary_key')
3232
expect(index).to be_a(MeiliSearch::Index)
3333
expect(index.uid).to eq('uid')
@@ -36,7 +36,7 @@
3636
end
3737

3838
it 'returns error if trying to update primary-key if it is already defined' do
39-
index = test_client.create_index('uid', primaryKey: 'primary_key')
39+
index = client.create_index('uid', primaryKey: 'primary_key')
4040
expect do
4141
index.update(primaryKey: 'new_primary_key')
4242
end.to raise_meilisearch_api_error_with(
@@ -65,13 +65,13 @@
6565
end
6666

6767
it 'deletes index' do
68-
index = test_client.create_index('uid')
68+
index = client.create_index('uid')
6969
expect(index.delete).to be_nil
7070
expect { index.fetch_info }.to raise_index_not_found_meilisearch_api_error
7171
end
7272

7373
it 'fails to manipulate index object after deletion' do
74-
index = test_client.create_index('uid')
74+
index = client.create_index('uid')
7575
expect(index.delete).to be_nil
7676

7777
expect { index.fetch_primary_key }.to raise_index_not_found_meilisearch_api_error
@@ -81,7 +81,7 @@
8181
end
8282

8383
it 'works with method aliases' do
84-
index = test_client.create_index('uid', primaryKey: 'primary_key')
84+
index = client.create_index('uid', primaryKey: 'primary_key')
8585

8686
expect(index.method(:fetch_primary_key) == index.method(:get_primary_key)).to be_truthy
8787
expect(index.method(:update) == index.method(:update_index)).to be_truthy

spec/meilisearch/index/documents_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe 'MeiliSearch::Index - Documents' do
4-
let(:index) { test_client.create_index(test_uid) }
4+
let(:index) { client.create_index(test_uid) }
55

66
context 'All basic tests with primary-key inference' do
77
let(:documents) do
@@ -71,13 +71,13 @@
7171
end
7272

7373
it 'create the index during document addition' do
74-
new_index = test_client.index('newIndex')
74+
new_index = client.index('newIndex')
7575
response = new_index.add_documents(documents)
7676
expect(response).to be_a(Hash)
7777
expect(response).to have_key('updateId')
7878
new_index.wait_for_pending_update(response['updateId'])
79-
expect(test_client.index('newIndex').fetch_primary_key).to eq('objectId')
80-
expect(test_client.index('newIndex').documents.count).to eq(documents.count)
79+
expect(client.index('newIndex').fetch_primary_key).to eq('objectId')
80+
expect(client.index('newIndex').documents.count).to eq(documents.count)
8181
end
8282

8383
it 'adds only one document to index (as an hash of one document)' do

spec/meilisearch/index/search/attributes_to_crop_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe 'MeiliSearch::Index - Cropped search' do
4-
let(:index) { test_client.create_index('books') }
4+
let(:index) { client.create_index('books') }
55
let(:document) do
66
{
77
objectId: 42,

spec/meilisearch/index/search/multi_params_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
context 'with snake_case options' do
8484
it 'does a custom search with attributes in a unusual formatting' do
85-
response = @index.search(
85+
response = index.search(
8686
'prince',
8787
{
8888
aTTributes_TO_Crop: ['title'],

0 commit comments

Comments
 (0)