Skip to content

Commit

Permalink
chore: Extend spec coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgns committed Jun 2, 2018
1 parent 4885308 commit eae1cf2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
7 changes: 3 additions & 4 deletions lib/sequel/plugins/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions spec/sequel/plugins/elasticsearch/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -50,16 +50,26 @@ 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
expect(subject.count).to eq result['hits']['hits'].count
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)
Expand Down

0 comments on commit eae1cf2

Please sign in to comment.