Permalink
Browse files

Added quick search feature

  • Loading branch information...
1 parent 2cff0f8 commit 3dafcb37090de19923dbf0ec8063d61c53a3e74f @sam-wan sam-wan committed Apr 16, 2008
Showing with 39 additions and 1 deletion.
  1. +4 −0 lib/itunes_link_maker.rb
  2. +35 −1 spec/itunes_link_maker_spec.rb
View
@@ -21,6 +21,10 @@ def self.search(query, media='music', country='US')
html = get_html(query, media, country)
parse_html(html)
end
+
+ def self.quick_search(query, media='music', country='US')
+ search(query, media, country).first
+ end
private
def self.parse_html(html)
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + 'spec_helper.rb'
+require File.dirname(__FILE__) + '/spec_helper.rb'
describe ItunesLinkMaker do
setup do
@@ -43,6 +43,22 @@ def search
end
+describe "Itunes quick search with no hits" do
+ setup do
+ @open_result = mock('open result', :read => read_fixture('no_results.html'))
+ ItunesLinkMaker.stub!(:open).and_return(@open_result)
+ end
+
+ def quick_search
+ ItunesLinkMaker.quick_search('kafoozl')
+ end
+
+ it "should return nil" do
+ quick_search.should be_nil
+ end
+end
+
+
describe "Itunes link search with multiple hits" do
setup do
@open_result = mock('open result', :read => read_fixture('has_results.html'))
@@ -57,3 +73,21 @@ def search
search.should_not be_empty
end
end
+
+
+describe "Itunes quick search with multiple hits" do
+ setup do
+ @open_result = mock('open result', :read => read_fixture('has_results.html'))
+ ItunesLinkMaker.stub!(:open).and_return(@open_result)
+ end
+
+ def quick_search
+ ItunesLinkMaker.quick_search('postal service such great heights')
+ end
+
+ it "should return the result object" do
+ expected = ItunesLinkMaker::Result.new('Such Great Heights', :name, '/WebObjects/MZStoreServices.woa/wa/itmsSearchDisplayUrl?desc=The+Postal+Service+-+Give+Up+-+Such+Great+Heights&WOURLEncoding=ISO8859_1&lang=1&url=http%3A%2F%2Fphobos.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbum%3Fi%3D2522315%26id%3D2522333%26s%3D143441')
+ quick_search.should == expected
+ end
+end
+

0 comments on commit 3dafcb3

Please sign in to comment.