Skip to content

Commit

Permalink
[patch:lib] Handle nil query results (#45)
Browse files Browse the repository at this point in the history
* Handle nil query results

* Add coverage directory to .gitignore

* Remove coverage files
  • Loading branch information
eonu committed Apr 14, 2019
1 parent e0d3921 commit 0550480
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/pkg/
/spec/tmp/
/tmp/
/coverage/

## Used by dotenv library to load environment variables
.env
Expand Down
6 changes: 6 additions & 0 deletions lib/arx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def search(*ids, query: nil, sort_by: :relevance, sort_order: :descending)
raise Error::MissingPaper.new(ids.first) if results.title.empty?
elsif results.is_a? Array
results.reject! {|paper| paper.title.empty?}
elsif results.nil?
if ids.size == 1
raise Error::MissingPaper.new(ids.first)
else
results = []
end
end

results
Expand Down
8 changes: 8 additions & 0 deletions spec/arx/arx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
it { is_expected.to be_a Paper }
it { is_expected.to get_paper papers.first }
end
context '(valid restricted)' do
it { expect { Arx.search('1809.09415') {|q| q.title 'bob'} }.to raise_error Error::MissingPaper }
end
context '(valid URL)' do
subject { Arx.search 'https://arxiv.org/abs/1105.5379' }

Expand All @@ -39,6 +42,8 @@
end
context '(invalid)' do
it { expect { Arx.search '1234.1234' }.to raise_error Error::MissingPaper }
it { expect { Arx.search '1809.0000' }.to raise_error Error::MissingPaper }
it { expect { Arx.search '1809.00000' }.to raise_error Error::MissingPaper }
end
context '(invalid format)' do
it { expect { Arx.search 'abc' }.to raise_error ArgumentError }
Expand All @@ -52,6 +57,9 @@
it { is_expected.to all be_a Paper }
it { is_expected.to get_papers papers }
end
context '(valid restricted)' do
it { expect(Arx.search('1809.09415', 'cond-mat/9609089') {|q| q.title 'bob'}).to eq [] }
end
context '(invalid)' do
it { expect { Arx.search '1234.1234', 'invalid-category/1234567' }.to raise_error ArgumentError }
end
Expand Down

0 comments on commit 0550480

Please sign in to comment.