Skip to content

Commit c2b0e70

Browse files
committed
[API] Adjust specs and code after test failures
1 parent e0a2cc4 commit c2b0e70

31 files changed

+28
-1638
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/clear_scroll.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module Actions
2828
#
2929
def clear_scroll(arguments={})
3030
method = Elasticsearch::API::HTTP_DELETE
31-
path = "_search/scroll/#{arguments[:scroll_id]}"
31+
path = Utils.__pathify '_search/scroll', Utils.__listify(arguments.delete(:scroll_id))
3232
params = {}
3333
body = arguments[:body]
3434

elasticsearch-api/lib/elasticsearch/api/actions/index.rb

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
# Licensed to Elasticsearch B.V. under one or more contributor
2-
# license agreements. See the NOTICE file distributed with
3-
# this work for additional information regarding copyright
4-
# ownership. Elasticsearch B.V. licenses this file to you under
5-
# the Apache License, Version 2.0 (the "License"); you may
6-
# not use this file except in compliance with the License.
7-
# You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing,
12-
# software distributed under the License is distributed on an
13-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
# KIND, either express or implied. See the License for the
15-
# specific language governing permissions and limitations
16-
# under the License.
17-
181
module Elasticsearch
192
module API
203
module Actions
@@ -57,7 +40,7 @@ module Actions
5740
# client.cluster.put_settings body: { transient: { 'indices.ttl.interval' => '1s' } }
5841
#
5942
# # Enable the `_ttl` property for all types within the index
60-
# client.indices.create index: 'myindex', body: { mappings: { properties: { _ttl: { enabled: true } } } }
43+
# client.indices.create index: 'myindex', body: { mappings: { mytype: { _ttl: { enabled: true } } } }
6144
#
6245
# client.index index: 'myindex', type: 'mytype', id: '1', body: { title: 'TEST' }, ttl: '5s'
6346
#
@@ -69,7 +52,7 @@ module Actions
6952
#
7053
# @option arguments [String] :id Document ID
7154
# @option arguments [String] :index The name of the index (*Required*)
72-
# @option arguments [String] :type The type of the document
55+
# @option arguments [String] :type The type of the document (*Required*)
7356
# @option arguments [Hash] :body The document (*Required*)
7457
# @option arguments [String] :wait_for_active_shards Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)
7558
# @option arguments [String] :op_type Explicit operation type (options: index, create)
@@ -87,17 +70,21 @@ module Actions
8770
#
8871
def index(arguments={})
8972
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
90-
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
91-
method = Elasticsearch::API::HTTP_POST
92-
path = "#{arguments[:index]}/_doc"
93-
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
73+
raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
74+
method = arguments[:id] ? HTTP_PUT : HTTP_POST
75+
path = Utils.__pathify Utils.__escape(arguments[:index]),
76+
Utils.__escape(arguments[:type]),
77+
Utils.__escape(arguments[:id])
78+
79+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
9480
body = arguments[:body]
81+
9582
perform_request(method, path, params, body).body
9683
end
9784

9885
# Register this action with its valid params when the module is loaded.
9986
#
100-
# @since 6.1.1
87+
# @since 6.2.0
10188
ParamsRegistry.register(:index, [
10289
:wait_for_active_shards,
10390
:op_type,

elasticsearch-api/spec/elasticsearch/api/actions/cluster/state_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,4 @@
4949
expect(client_double.cluster.state(metric: ['foo', 'bar'])).to eq({})
5050
end
5151
end
52-
53-
context 'when index templates are specified' do
54-
55-
let(:expected_args) do
56-
[
57-
'GET',
58-
'_cluster/state',
59-
{ index_templates: 'foo,bar' },
60-
nil,
61-
nil
62-
]
63-
end
64-
65-
it 'performs the request' do
66-
expect(client_double.cluster.state(index_templates: ['foo', 'bar'])).to eq({})
67-
end
68-
end
6952
end

elasticsearch-api/spec/elasticsearch/api/actions/count_percolate_spec.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

elasticsearch-api/spec/elasticsearch/api/actions/delete_template_spec.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

elasticsearch-api/spec/elasticsearch/api/actions/field_stats_spec.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

elasticsearch-api/spec/elasticsearch/api/actions/get_script_spec.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,18 @@
3232
{ }
3333
end
3434

35-
context 'when the `lang` parameter is specificed' do
36-
37-
let(:url) do
38-
'_scripts/groovy/foo'
39-
end
40-
41-
it 'performs the request' do
42-
expect(client_double.get_script(lang: 'groovy', id: 'foo')).to eq({})
43-
end
35+
let(:url) do
36+
'_scripts/foo'
4437
end
4538

46-
context 'when the `lang` parameter is not specificed' do
39+
context 'when the `lang` parameter is specificed' do
4740

48-
let(:url) do
49-
'_scripts/foo'
41+
let(:params) do
42+
{ master_timeout: '1s' }
5043
end
5144

5245
it 'performs the request' do
53-
expect(client_double.get_script(id: 'foo')).to eq({})
46+
expect(client_double.get_script(master_timeout: '1s', id: 'foo')).to eq({})
5447
end
5548
end
5649
end

elasticsearch-api/spec/elasticsearch/api/actions/get_template_spec.rb

Lines changed: 0 additions & 69 deletions
This file was deleted.

elasticsearch-api/spec/elasticsearch/api/actions/index_document_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
}.to raise_exception(ArgumentError)
5555
end
5656

57+
it 'requires the :type argument' do
58+
expect {
59+
client.index(index: 'foo')
60+
}.to raise_exception(ArgumentError)
61+
end
62+
5763
it 'performs the request' do
5864
expect(client_double.index(index: 'foo', type: 'bar', body: { foo: 'bar' })).to eq({})
5965
end
@@ -136,7 +142,7 @@
136142

137143
context 'when an invalid URL parameter is provided' do
138144

139-
it 'raises an ArgumentError' do
145+
it 'raises and ArgumentError' do
140146
expect {
141147
client.index(index: 'foo', type: 'bar', id: '1', qwerty: 'yuiop')
142148
}.to raise_exception(ArgumentError)

elasticsearch-api/spec/elasticsearch/api/actions/indices/analyze_spec.rb

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@
6060
end
6161
end
6262

63-
context 'when an url params are specified' do
64-
65-
let(:params) do
66-
{ text: 'foo', analyzer: 'bar' }
67-
end
68-
69-
it 'performs the request' do
70-
expect(client_double.indices.analyze(text: 'foo', analyzer: 'bar')).to eq({})
71-
end
72-
end
73-
7463
context 'when a body is specified' do
7564

7665
let(:body) do
@@ -81,30 +70,4 @@
8170
expect(client_double.indices.analyze(body: 'foo')).to eq({})
8271
end
8372
end
84-
85-
context 'when filters are specified' do
86-
87-
let(:params) do
88-
{ filters: 'foo,bar', text: 'Test', tokenizer: 'whitespace' }
89-
end
90-
91-
it 'performs the request' do
92-
expect(client_double.indices.analyze(text: 'Test', tokenizer: 'whitespace', filters: ['foo,bar'])).to eq({})
93-
end
94-
end
95-
96-
context 'when path must be URL-escaped' do
97-
98-
let(:url) do
99-
'foo%5Ebar/_analyze'
100-
end
101-
102-
let(:params) do
103-
{ text: 'Test', index: 'foo^bar' }
104-
end
105-
106-
it 'performs the request' do
107-
expect(client_double.indices.analyze(index: 'foo^bar', text: 'Test')).to eq({})
108-
end
109-
end
11073
end

0 commit comments

Comments
 (0)