Skip to content

Commit

Permalink
Added tested get_blogs method
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerhendrix committed Jul 11, 2009
1 parent 46d1362 commit 24f2662
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 13 deletions.
26 changes: 13 additions & 13 deletions generators/echonest_unit_test/templates/unit_test.rb.erb
Expand Up @@ -9,30 +9,30 @@ describe "<%=name.capitalize%>Result" do
end

it "should parse xml" do
EchoNest::AudioResult.parse(@xml)
EchoNest::<%=name.capitalize%>Result.parse(@xml)
end

it "should have artist" do
audio = EchoNest::<%=name.capitalize%>Result.parse(@xml)
audio.artist.should be_kind_of(EchoNest::Artist)
audio.artist.name.should == "Wavves"
audio.artist.id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
<%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
<%=name%>.artist.should be_kind_of(EchoNest::Artist)
<%=name%>.artist.name.should == "Wavves"
<%=name%>.artist.id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
end

it "should have results" do
audio = EchoNest::<%=name.capitalize%>Result.parse(@xml)
audio.results.should be_kind_of(EchoNest::BlogResults)
<%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
<%=name%>.results.should be_kind_of(EchoNest::BlogResults)
#TODO: Fill in these values as found in fixture
audio.results.found.should == "51"
audio.results.shown.should == "15"
audio.results.start.should == "0"
audio.results.docs.should be_kind_of(Array)
audio.results.docs.length.should == 15
<%=name%>.results.found.should == "51"
<%=name%>.results.shown.should == "15"
<%=name%>.results.start.should == "0"
<%=name%>.results.docs.should be_kind_of(Array)
<%=name%>.results.docs.length.should == 15
end

describe "result" do
it "should be an <%=name.capitalize%>Doc" do
audio = EchoNest::AudioResult.parse(@xml)
<%=name%> = EchoNest::AudioResult.parse(@xml)
doc = audio.results.docs[0]
doc.should be_kind_of(EchoNest::<%=name.capitalize%>Doc)
#TODO: Create tests based on attributes in resource
Expand Down
3 changes: 3 additions & 0 deletions lib/echonest.rb
Expand Up @@ -19,4 +19,7 @@ def self.api_key
require "echonest/audio_doc.rb"
require "echonest/audio_results.rb"
require "echonest/audio_result.rb"
require "echonest/blog_doc.rb"
require "echonest/blog_results.rb"
require "echonest/blog_result.rb"

5 changes: 5 additions & 0 deletions lib/echonest/artist.rb
Expand Up @@ -15,5 +15,10 @@ def get_audio
AudioResult.parse request.fetch
end

def get_blogs
request = ApiRequest.new("get_audio", {:id => id})
BlogResult.parse request.fetch
end

end
end
13 changes: 13 additions & 0 deletions lib/echonest/blog_doc.rb
@@ -0,0 +1,13 @@

module EchoNest
class BlogDoc
include HappyMapper

tag :doc

element :name, String
element :url, String
element :summary, String
element :date_found, String
end
end
12 changes: 12 additions & 0 deletions lib/echonest/blog_result.rb
@@ -0,0 +1,12 @@

module EchoNest
class BlogResult
include HappyMapper

tag :response

has_one :artist, Artist
has_one :results, BlogResults

end
end
15 changes: 15 additions & 0 deletions lib/echonest/blog_results.rb
@@ -0,0 +1,15 @@

module EchoNest
class BlogResults
include HappyMapper

tag :results

attribute :found, String
attribute :shown, String
attribute :start, String

has_many :docs, BlogDoc

end
end
48 changes: 48 additions & 0 deletions spec/echonest/blog_result_spec.rb
@@ -0,0 +1,48 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe "BlogResult" do

describe "#parse" do

before(:each) do
@xml = File.read(File.dirname(__FILE__) + "/../fixtures/blog/radiohead.xml")
end

it "should parse xml" do
EchoNest::BlogResult.parse(@xml)
end

it "should have artist" do
blog = EchoNest::BlogResult.parse(@xml)
blog.artist.should be_kind_of(EchoNest::Artist)
blog.artist.name.should == "Radiohead"
blog.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
end

it "should have results" do
blog = EchoNest::BlogResult.parse(@xml)
blog.results.should be_kind_of(EchoNest::BlogResults)
#TODO: Fill in these values as found in fixture
blog.results.found.should == "131"
blog.results.shown.should == "2"
blog.results.start.should == "0"
blog.results.docs.should be_kind_of(Array)
blog.results.docs.length.should == 2
end

describe "result" do
it "should be an BlogDoc" do
blog = EchoNest::BlogResult.parse(@xml)
doc = blog.results.docs[0]
doc.should be_kind_of(EchoNest::BlogDoc)
#TODO: Create tests based on attributes in resource
doc.name.should == "Radiohead live at Santa Barbara 28.8.08 « Misspeak Music"
doc.url.should == "http://misspeakmusic.wordpress.com/2008/09/01/radiohead-live-at-santa-barbara-28808/"
doc.summary.should == "[blog text removed]"
doc.date_found.should == "2008-10-14 16:38:15.582000"
end
end
end


end
32 changes: 32 additions & 0 deletions spec/fixtures/blog/radiohead.xml
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<response version="3">
<status>
<code>0</code>
<message>Success</message>
</status>
<query>
<parameter name="api_key">5ZAOMB3BUR8QUN4PE</parameter>
<parameter name="id">music://id.echonest.com/~/AR/ARH6W4X1187B99274F</parameter>
<parameter name="start">0</parameter>
<parameter name="rows">2</parameter>
</query>
<artist>
<name>Radiohead</name>
<id>music://id.echonest.com/~/AR/ARH6W4X1187B99274F</id>
<foreign_id>music://id.echonest.com/5ZAOMB3BUR8QUN4PE/AR/1</foreign_id>
</artist>
<results found="131" shown="2" start="0">
<doc id="808bd8998c36ca73ee35c77453461b05" type="web">
<name>Radiohead live at Santa Barbara 28.8.08 « Misspeak Music</name>
<url>http://misspeakmusic.wordpress.com/2008/09/01/radiohead-live-at-santa-barbara-28808/</url>
<summary>[blog text removed]</summary>
<date_found>2008-10-14 16:38:15.582000</date_found>
</doc>
<doc id="20fc2d49343546ba647ddcae5c0e70e0" type="web">
<name>Apartment 41: Radiohead's Santa Barbara Webcast</name>
<url>http://coldbrains41.blogspot.com/2008/08/radioheads-santa-barbara-webcast-video.html</url>
<summary>[blog text removed]</summary>
<date_found>2008-10-14 16:38:15.582000</date_found>
</doc>
</results>
</response>

0 comments on commit 24f2662

Please sign in to comment.