Skip to content

Commit

Permalink
chore: More spec coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgns committed Feb 10, 2018
1 parent ed24ed7 commit 471f222
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion spec/sequel/plugins/elasticsearch_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'sequel'
require 'sequel/plugins/elasticsearch'
require 'sequel/plugins/elasticsearch/result'

describe Sequel::Plugins::Elasticsearch do
before(:all) do
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 471f222

Please sign in to comment.