From 471f222144ed54355a8c3873dfae1499977e0c9e Mon Sep 17 00:00:00 2001 From: Jurgens du Toit Date: Sat, 10 Feb 2018 13:16:26 +0200 Subject: [PATCH] chore: More spec coverage --- spec/sequel/plugins/elasticsearch_spec.rb | 37 ++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/spec/sequel/plugins/elasticsearch_spec.rb b/spec/sequel/plugins/elasticsearch_spec.rb index 9287bcb..af9d5b8 100644 --- a/spec/sequel/plugins/elasticsearch_spec.rb +++ b/spec/sequel/plugins/elasticsearch_spec.rb @@ -1,5 +1,6 @@ require 'sequel' require 'sequel/plugins/elasticsearch' +require 'sequel/plugins/elasticsearch/result' describe Sequel::Plugins::Elasticsearch do before(:all) do @@ -83,13 +84,20 @@ expect(stub).to have_been_requested.once end - it 'handles exceptions' do + it 'handles not found exceptions' do stub_request(:get, %r{http://localhost:9200/documents/sync/_search.*}) .to_return(status: 404) subject.plugin :elasticsearch expect { subject.es('test') }.to_not raise_error end + it 'handles connection failed exceptions' do + stub_request(:get, %r{http://localhost:9200/documents/sync/_search.*}) + allow(Faraday::Connection).to receive(:get).and_raise(Faraday::ConnectionFailed) + subject.plugin :elasticsearch + expect { subject.es('test') }.to_not raise_error + end + it 'returns an enumerable' do stub_request(:get, %r{http://localhost:9200/documents/sync/_search.*}) subject.plugin :elasticsearch @@ -114,6 +122,33 @@ expect { subject.es!('test') }.to raise_error Elasticsearch::Transport::Transport::Error end end + + context '.scroll!' do + it 'accepts a scroll_id' do + stub = stub_request(:get, 'http://localhost:9200/_search/scroll?scroll%5Bscroll%5D=1m&scroll_id=somescrollid') + .to_return(status: 200) + subject.plugin :elasticsearch + subject.scroll!('somescrollid', scroll: '1m') + expect(stub).to have_been_requested.once + end + + it 'accepts a Result' do + result = Sequel::Plugins::Elasticsearch::Result.new('_scroll_id' => 'somescrollid') + allow(result).to receive(:scroll_id).and_return('somescrollid') + stub = stub_request(:get, 'http://localhost:9200/_search/scroll?scroll%5Bscroll%5D=1m&scroll_id=somescrollid') + .to_return(status: 200) + subject.plugin :elasticsearch + subject.scroll!(result, scroll: '1m') + expect(stub).to have_been_requested.once + end + + it 'does not handle exceptions' do + stub_request(:get, 'http://localhost:9200/_search/scroll?scroll=1m&scroll_id=somescrollid') + .to_return(status: 500) + subject.plugin :elasticsearch + expect { subject.scroll!('somescrollid', '1m') }.to raise_error Elasticsearch::Transport::Transport::Error + end + end end context 'InstanceMethods' do