Skip to content

Commit

Permalink
Fixed bug with ESearch converting arrays in terms hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
ordinaryzelig committed May 31, 2011
1 parent c7814c9 commit 703a092
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions lib/entrez.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def request_times
# #=> 'low coverage[WORD]+AND+inprogress[SEQS]'
def convert_search_term_hash(hash)
hash.map do |field, value|
value = value.join(',') if value.is_a?(Array)
"#{value}[#{field}]"
end.join('+AND+')
end
Expand Down
2 changes: 1 addition & 1 deletion lib/entrez/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Entrez
VERSION = "0.5.4"
VERSION = "0.5.5"
end
51 changes: 30 additions & 21 deletions spec/entrez_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,44 @@
response.body.should include('Hapmap')
end

it '#ESearch retrieves results' do
response = Entrez.ESearch('genomeprj', {WORD: 'hapmap', SEQS: 'inprogress'}, retmode: :xml)
response.body.should include('28911')
end

it '#EInfo retrieves results' do
response = Entrez.EInfo('snp', retmode: :xml)
response.body.should include('<Name>RS</Name>')
end

it '#ESearch response returns IDs for convenience' do
response = Entrez.ESearch('genomeprj', {WORD: 'hapmap', SEQS: 'inprogress'}, retmode: :xml)
response.ids.should == [60153, 29429, 28911, 48101, 59851, 59849, 59847, 59845, 59839, 59835, 59833, 59831, 51895, 59829, 59827, 60835, 59811, 60831, 60819, 33895]
end
context '#ESearch' do

it '#ESearch returns empty array if nothing found' do
response = Entrez.ESearch('genomeprj', {NON_EXISTENT_SEARCH_FIELD: 'does not exist even in oompaloompa land'}, retmode: :xml)
response.ids.should be_empty
end
it 'retrieves results' do
response = Entrez.ESearch('genomeprj', {WORD: 'hapmap', SEQS: 'inprogress'}, retmode: :xml)
response.body.should include('28911')
end

it '#ESearch returns array even if only 1 id found' do
id = 60153
response = Entrez.ESearch('genomeprj', {uid: id}, retmode: :xml)
response.ids.should == [id]
end
it 'response returns IDs for convenience' do
response = Entrez.ESearch('genomeprj', {WORD: 'hapmap', SEQS: 'inprogress'}, retmode: :xml)
response.ids.should == [60153, 29429, 28911, 48101, 59851, 59849, 59847, 59845, 59839, 59835, 59833, 59831, 51895, 59829, 59827, 60835, 59811, 60831, 60819, 33895]
end

it 'returns empty array if nothing found' do
response = Entrez.ESearch('genomeprj', {NON_EXISTENT_SEARCH_FIELD: 'does not exist even in oompaloompa land'}, retmode: :xml)
response.ids.should be_empty
end

it 'returns array even if only 1 id found' do
id = 60153
response = Entrez.ESearch('genomeprj', {uid: id}, retmode: :xml)
response.ids.should == [id]
end

it 'accepts string as search_terms parameter' do
response = Entrez.ESearch('genomeprj', 'hapmap[WORD]', retmode: :xml)
response.ids.should include(60153)
end

it 'can handle array of uids' do
response = Entrez.ESearch('gene', {UID: [1, 2, 3]})
response.ids.should =~ [1, 2, 3]
end

it '#ESearch accepts string as search_terms parameter' do
response = Entrez.ESearch('genomeprj', 'hapmap[WORD]', retmode: :xml)
response.ids.should include(60153)
end

it 'should respect query limit' do
Expand Down

0 comments on commit 703a092

Please sign in to comment.