Skip to content

Commit

Permalink
Added album.getInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerhendrix committed Jan 12, 2009
1 parent 4f3d793 commit a9060d2
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/scrobbler2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Scrobbler2

require 'scrobbler2/base.rb'
require 'scrobbler2/auth.rb'
require 'scrobbler2/album.rb'
require 'scrobbler2/artist.rb'
require 'scrobbler2/user.rb'

Expand Down
11 changes: 11 additions & 0 deletions lib/scrobbler2/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Scrobbler2
class Album < Base

def initialize(artist, album)
@query = {:artist => artist, :album => album}
end

get_resource :info, :root => 'album'

end
end
56 changes: 56 additions & 0 deletions test/acceptance/album/info_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require File.dirname(__FILE__) + '/../test_helper.rb'

describe "Album info for Ride the Lightning" do

before(:all) do #We only want to hit the webservice once.
@album = Scrobbler2::Album.new "Metallica", "Ride The Lightning"
@info = @album.info
# puts "INFO: #{@info.inspect} \n"
end

it "should be hash" do
@info.should be_kind_of Hash
end

it "should have name 'Metallica'" do
@info["name"].should == "Ride the Lightning"
end

it "should have artist 'Metallica'" do
@info["artist"].should == "Metallica"
end


it "should have mbid '456efd39-f0dc-4b4d-87c7-82bbc562d8f3'" do
@info["mbid"].should == '456efd39-f0dc-4b4d-87c7-82bbc562d8f3'
end

it "should have url 'http://www.last.fm/music/Metallica'" do
@info["url"].should == 'http://www.last.fm/music/Metallica/Ride+the+Lightning'
end

it "should have listeners" do
@info.should have_key("listeners")
end

it "should have playcount" do
@info.should have_key("playcount")
end

it "should have images" do
@info["image"].should be_kind_of Array
@info["image"][0].should be_kind_of Hash
@info["image"][0]['size'].should be_kind_of String
@info["image"][0]['#text'].should be_kind_of String
#@info["image"][0]['#text'].should == 'http://userserve-ak.last.fm/serve/34/9527793.jpg'
end

it "should have toptags" do
pending "TopTags breaks parser" do
@info["toptags"].should be_kind_of Hash
@info["toptags"]["tags"].should be_kind_of Array
@info["toptags"]["tags"][0].should have_key('name')
@info["toptags"]["tags"][0].should have_key('url')
end
end
end
17 changes: 17 additions & 0 deletions test/unit/album_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require File.dirname(__FILE__) + "/spec_helper.rb"

describe "Album" do
before(:each) do
@album = Scrobbler2::Album.new "Metallica", "Ride The Lightning"
@album.class.stub!(:get).and_return Hash.new
end

it "should have a default query {:artist => 'Metallica', :album => 'Ride The Lightning'}" do
@album.instance_variable_get(:@query).should == {:artist => 'Metallica', :album => 'Ride The Lightning'}
end

it "info should call get with 'album.getInfo' with query params :artist => @artist, :album => @album" do
@album.class.should_receive(:get).with('album.getinfo', {:artist => "Metallica", :album => "Ride The Lightning"}, {}).and_return Hash.new
@album.info
end
end

0 comments on commit a9060d2

Please sign in to comment.