Skip to content

Commit

Permalink
[API] Updates utils spec for escaping spaces and other minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Jan 6, 2022
1 parent 46e99ec commit 6f261a1
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions elasticsearch-api/spec/elasticsearch/api/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,14 @@
end

it 'encodes special characters' do
expect(utils.__escape('foo bar')).to eq('foo+bar')
expect(utils.__escape('foo bar')).to eq('foo%20bar')
expect(utils.__escape('foo/bar')).to eq('foo%2Fbar')
expect(utils.__escape('foo^bar')).to eq('foo%5Ebar')
end

it 'does not encode asterisks' do
expect(utils.__escape('*')).to eq('*')
end

it 'users CGI.escape by default' do
expect(CGI).to receive(:escape).and_call_original
expect(utils.__escape('foo bar')).to eq('foo+bar')
end

it 'uses the escape_utils gem when available', unless: defined?(JRUBY_VERSION) do
require 'escape_utils'
expect(CGI).not_to receive(:escape)
expect(EscapeUtils).to receive(:escape_url).and_call_original
expect(utils.__escape('foo bar')).to eq('foo+bar')
end
end

describe '#__listify' do
Expand Down Expand Up @@ -77,7 +65,7 @@
context 'when the escape option is set to false' do

it 'does not escape the characters' do
expect(utils.__listify(['foo', 'bar^bam'], :escape => false)).to eq('foo,bar^bam')
expect(utils.__listify(['foo', 'bar^bam'], escape: false)).to eq('foo,bar^bam')
end
end
end
Expand Down Expand Up @@ -107,19 +95,19 @@

let(:result) do
utils.__bulkify [
{ :index => { :_index => 'myindexA', :_type => 'mytype', :_id => '1', :data => { :title => 'Test' } } },
{ :update => { :_index => 'myindexB', :_type => 'mytype', :_id => '2', :data => { :doc => { :title => 'Update' } } } },
{ :delete => { :_index => 'myindexC', :_type => 'mytypeC', :_id => '3' } }
{ index: { _index: 'myindexA', _id: '1', data: { title: 'Test' } } },
{ update: { _index: 'myindexB', _id: '2', data: { doc: { title: 'Update' } } } },
{ delete: { _index: 'myindexC', _id: '3' } }
]
end

let(:expected_string) do
<<-PAYLOAD.gsub(/^\s+/, '')
{"index":{"_index":"myindexA","_type":"mytype","_id":"1"}}
{"index":{"_index":"myindexA","_id":"1"}}
{"title":"Test"}
{"update":{"_index":"myindexB","_type":"mytype","_id":"2"}}
{"update":{"_index":"myindexB","_id":"2"}}
{"doc":{"title":"Update"}}
{"delete":{"_index":"myindexC","_type":"mytypeC","_id":"3"}}
{"delete":{"_index":"myindexC","_id":"3"}}
PAYLOAD
end

Expand Down Expand Up @@ -379,7 +367,7 @@
end

let(:unsupported_params) do
[ { :foo => { :explanation => 'NOT_SUPPORTED'} }, :moo ]
[ { foo: { explanation: 'NOT_SUPPORTED'} }, :moo ]
end


Expand Down

0 comments on commit 6f261a1

Please sign in to comment.