From 6f261a11035d4c2535029e277ae56dec7ec1fe1a Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Wed, 5 Jan 2022 17:09:13 +0000 Subject: [PATCH] [API] Updates utils spec for escaping spaces and other minor updates --- .../spec/elasticsearch/api/utils_spec.rb | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/elasticsearch-api/spec/elasticsearch/api/utils_spec.rb b/elasticsearch-api/spec/elasticsearch/api/utils_spec.rb index 9f61706751..2686c2642d 100644 --- a/elasticsearch-api/spec/elasticsearch/api/utils_spec.rb +++ b/elasticsearch-api/spec/elasticsearch/api/utils_spec.rb @@ -30,7 +30,7 @@ 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 @@ -38,18 +38,6 @@ 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 @@ -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 @@ -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 @@ -379,7 +367,7 @@ end let(:unsupported_params) do - [ { :foo => { :explanation => 'NOT_SUPPORTED'} }, :moo ] + [ { foo: { explanation: 'NOT_SUPPORTED'} }, :moo ] end