Skip to content

Commit

Permalink
[API] Convert indices tests to rspec (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
estolfo authored Oct 19, 2018
1 parent 1f295db commit d62ea45
Show file tree
Hide file tree
Showing 90 changed files with 2,952 additions and 2,388 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
require 'spec_helper'

describe 'client.indices#analyze' do

let(:expected_args) do
[
'GET',
url,
params,
body,
nil
]
end

let(:body) do
nil
end

let(:url) do
'_analyze'
end

let(:params) do
{}
end

it 'performs the request' do
expect(client_double.indices.analyze).to eq({})
end

context 'when an index is specified' do

let(:url) do
'foo/_analyze'
end

let(:params) do
{ index: 'foo' }
end

it 'performs the request' do
expect(client_double.indices.analyze(index: 'foo')).to eq({})
end
end

context 'when an url params are specified' do

let(:params) do
{ text: 'foo', analyzer: 'bar' }
end

it 'performs the request' do
expect(client_double.indices.analyze(text: 'foo', analyzer: 'bar')).to eq({})
end
end

context 'when a body is specified' do

let(:body) do
'foo'
end

it 'performs the request' do
expect(client_double.indices.analyze(body: 'foo')).to eq({})
end
end

context 'when filters are specified' do

let(:params) do
{ filters: 'foo,bar', text: 'Test', tokenizer: 'whitespace' }
end

it 'performs the request' do
expect(client_double.indices.analyze(text: 'Test', tokenizer: 'whitespace', filters: ['foo,bar'])).to eq({})
end
end

context 'when path must be URL-escaped' do

let(:url) do
'foo%5Ebar/_analyze'
end

let(:params) do
{ text: 'Test', index: 'foo^bar' }
end

it 'performs the request' do
expect(client_double.indices.analyze(index: 'foo^bar', text: 'Test')).to eq({})
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'spec_helper'

describe 'client.indices#clear_cache' do

let(:expected_args) do
[
'POST',
url,
params,
nil,
nil
]
end

let(:url) do
'_cache/clear'
end

let(:params) do
{}
end

it 'performs the request' do
expect(client_double.indices.clear_cache).to eq({})
end

context 'when an index is specified' do

let(:url) do
'foo/_cache/clear'
end

let(:params) do
{ index: 'foo' }
end

it 'performs the request' do
expect(client_double.indices.clear_cache(index: 'foo')).to eq({})
end
end

context 'when params are specified' do

let(:params) do
{ field_data: true }
end

it 'performs the request' do
expect(client_double.indices.clear_cache(field_data: true)).to eq({})
end
end

context 'when the path must be URL-escaped' do

let(:url) do
'foo%5Ebar/_cache/clear'
end

let(:params) do
{ index: 'foo^bar' }
end

it 'performs the request' do
expect(client_double.indices.clear_cache(index: 'foo^bar')).to eq({})
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require 'spec_helper'

describe 'client.indices#close' do

let(:expected_args) do
[
'POST',
url,
params,
nil,
nil
]
end

let(:params) do
{}
end

context 'when there is no index specified' do

let(:client) do
Class.new { include Elasticsearch::API }.new
end

it 'raises an exception' do
expect {
client.indices.close
}.to raise_exception(ArgumentError)
end
end

context 'when an index is specified' do

let(:url) do
'foo/_close'
end

it 'performs the request' do
expect(client_double.indices.close(index: 'foo')).to eq({})
end
end

context 'when params are specified' do

let(:params) do
{ timeout: '1s' }
end

let(:url) do
'foo/_close'
end

it 'performs the request' do
expect(client_double.indices.close(index: 'foo', timeout: '1s')).to eq({})
end
end

context 'when the path must be URL-escaped' do

let(:url) do
'foo%5Ebar/_close'
end

it 'performs the request' do
expect(client_double.indices.close(index: 'foo^bar')).to eq({})
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require 'spec_helper'

describe 'client.indices#create' do

let(:expected_args) do
[
'PUT',
url,
params,
nil,
nil
]
end

let(:params) do
{}
end

context 'when there is no index specified' do

let(:client) do
Class.new { include Elasticsearch::API }.new
end

it 'raises an exception' do
expect {
client.indices.create
}.to raise_exception(ArgumentError)
end
end

context 'when an index is specified' do

let(:url) do
'foo'
end

it 'performs the request' do
expect(client_double.indices.create(index: 'foo')).to eq({})
end
end

context 'when params are specified' do

let(:params) do
{ timeout: '1s' }
end

let(:url) do
'foo'
end

it 'performs the request' do
expect(client_double.indices.create(index: 'foo', timeout: '1s')).to eq({})
end
end

context 'when the path must be URL-escaped' do

let(:url) do
'foo%5Ebar'
end

it 'performs the request' do
expect(client_double.indices.create(index: 'foo^bar')).to eq({})
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'spec_helper'

describe 'client.indices#delete_alias' do

let(:expected_args) do
[
'DELETE',
url,
params,
nil,
nil
]
end

let(:params) do
{}
end

context 'when there is no index specified' do

let(:client) do
Class.new { include Elasticsearch::API }.new
end

it 'raises an exception' do
expect {
client.indices.delete_alias(name: 'foo')
}.to raise_exception(ArgumentError)
end
end

context 'when there is no name specified' do

let(:client) do
Class.new { include Elasticsearch::API }.new
end

it 'raises an exception' do
expect {
client.indices.delete_alias(index: 'foo')
}.to raise_exception(ArgumentError)
end
end

context 'when an index and name are specified' do

let(:url) do
'foo/_alias/bar'
end

it 'performs the request' do
expect(client_double.indices.delete_alias(index: 'foo', name: 'bar')).to eq({})
end
end

context 'when the path must be URL-escaped' do

let(:url) do
'foo%5Ebar/_alias/bar%2Fbam'
end

it 'performs the request' do
expect(client_double.indices.delete_alias(index: 'foo^bar', name: 'bar/bam')).to eq({})
end
end
end
Loading

0 comments on commit d62ea45

Please sign in to comment.