spec/elastic/transport/client_spec.rb in elastic-transport-8.2.3 vs spec/elastic/transport/client_spec.rb in elastic-transport-8.2.4
- old
+ new
@@ -1188,9 +1188,52 @@
end
client.perform_request('GET', '/')
expect(logger).to have_received(:warn).with(warning)
end
end
+
+ context 'when Elasticsearch response includes long precision Float' do
+ let(:client) do
+ Elastic::Transport::Client.new(hosts: hosts)
+ end
+ before do
+ expect_any_instance_of(Faraday::Connection).to receive(:run_request) do
+ Elastic::Transport::Transport::Response.new(200, "{\"score\":1.11111111111111111}", { 'content-type' => 'application/json; charset=UTF-8' })
+ end
+ end
+
+ context 'when default JSON engine is used' do
+ after do
+ # Clear MultiJson's adapter
+ ::MultiJson.instance_variable_set(:@adapter, nil)
+ end
+ it 'returns as a Float' do
+ response = client.perform_request('GET', '/')
+ score = response.body['score']
+ expect(score).to eq 1.11111111111111111
+ expect(score.class).to eq Float
+ end
+ end
+
+ unless defined?(JRUBY_VERSION)
+ context 'when Oj is used as a JSON engine' do
+ before do
+ require 'oj'
+ end
+ after do
+ # Clear MultiJson's adapter
+ ::MultiJson.instance_variable_set(:@adapter, nil)
+ end
+
+ it 'returns as a Float' do
+ response = client.perform_request('GET', '/')
+ score = response.body['score']
+ expect(score).to eq 1.11111111111111111
+ expect(score.class).to eq Float
+ end
+ end
+ end
+ end
end
context 'when the client connects to Elasticsearch' do
let(:logger) do
Logger.new($stderr) unless ENV['QUIET']