From eae1cf244fa5626fd3eb899a4e6b28cfa4ae908e Mon Sep 17 00:00:00 2001 From: Jurgens du Toit Date: Sat, 2 Jun 2018 13:20:23 +0200 Subject: [PATCH] chore: Extend spec coverage --- lib/sequel/plugins/elasticsearch.rb | 7 +++---- .../plugins/elasticsearch/result_spec.rb | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/sequel/plugins/elasticsearch.rb b/lib/sequel/plugins/elasticsearch.rb index a8e263f..d28b0aa 100644 --- a/lib/sequel/plugins/elasticsearch.rb +++ b/lib/sequel/plugins/elasticsearch.rb @@ -70,10 +70,9 @@ def es(query = '', opts = {}) # Wrapper method in which error handling is done for Elasticsearch calls. def call_es yield - rescue ::Elasticsearch::Transport::Transport::Errors::NotFound, ::Elasticsearch::Transport::Transport::Error => e - db.loggers.first.warn e if db.loggers.count.positive? - nil - rescue Faraday::ConnectionFailed => e + rescue ::Elasticsearch::Transport::Transport::Errors::NotFound, + ::Elasticsearch::Transport::Transport::Error, + Faraday::ConnectionFailed => e db.loggers.first.warn e if db.loggers.count.positive? nil end diff --git a/spec/sequel/plugins/elasticsearch/result_spec.rb b/spec/sequel/plugins/elasticsearch/result_spec.rb index c639bc5..c6a5733 100644 --- a/spec/sequel/plugins/elasticsearch/result_spec.rb +++ b/spec/sequel/plugins/elasticsearch/result_spec.rb @@ -13,7 +13,7 @@ def fixture(name) 'took' => 234, 'timed_out' => false, 'hits' => { - 'hits' => [ 'one', 'two' ], + 'hits' => [{ one: 'one', two: 'two' }, { one: 'three', two: 'four' }], 'total' => 2 } } @@ -50,9 +50,9 @@ def fixture(name) end it 'accesses the enumerable elements correctly' do - expect(subject).to include 'one' - expect(subject).to include 'two' - expect(subject).to_not include 'three' + expect(subject).to include one: 'one', two: 'two' + expect(subject).to include one: 'three', two: 'four' + expect(subject).to_not include one: 'five', two: 'six' end it 'reports the size of the hits array correctly' do @@ -60,6 +60,16 @@ def fixture(name) end end + context '#method_missing' do + let(:subject) do + described_class.new(result) + end + + it 'sends all methods to the hits array' do + expect(subject.count).to eq 2 + end + end + context 'scrollable' do let(:subject) do described_class.new(scroll_result)