sandro-metamuse 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/History CHANGED
@@ -1,7 +1,11 @@
1
- 0.1.3 07/19/2009
1
+ 0.1.4 08/19/2009
2
+ * Return an invalid artist when an artist search fails. Closes gh-6
3
+ * artist.albums.uniq returns unique albums by name. Closes gh-7
4
+
5
+ 0.1.3 08/19/2009
2
6
  * Artist controls validity and whether or not to use #best_guess
3
7
 
4
- 0.1.2 07/18/2009
8
+ 0.1.2 08/18/2009
5
9
  * Modified Cracks date parser, queries for Radiohead now work
6
10
  * Ruby 1.9 compatibility
7
11
  * Moved Metamuse queries from echonest to Lastfm
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -19,6 +19,13 @@ module Metamuse
19
19
  end
20
20
  end
21
21
 
22
+ def hash
23
+ [artist, name].hash
24
+ end
25
+
26
+ def eql?(other)
27
+ name == other.name
28
+ end
22
29
  end
23
30
  end
24
31
 
@@ -4,8 +4,12 @@ class Metamuse::Services::Lastfm::Artist
4
4
  include ::Metamuse::InstanceInitialize
5
5
 
6
6
  def self.build(response)
7
- data = response['lfm']['artist']
8
- new data
7
+ if response['lfm']['status'] == 'ok'
8
+ data = response['lfm']['artist']
9
+ new data
10
+ else
11
+ new :invalid => true
12
+ end
9
13
  end
10
14
 
11
15
  def initialize(attrs={})
@@ -44,6 +48,6 @@ class Metamuse::Services::Lastfm::Artist
44
48
  end
45
49
 
46
50
  def valid?
47
- url !~ %r(/music/\+noredirect/)
51
+ url && url !~ %r(/music/\+noredirect/)
48
52
  end
49
53
  end
@@ -1,11 +1,8 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{metamuse}
8
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Sandro Turriate"]
@@ -1,14 +1,16 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Metamuse::Album do
4
+ subject { Metamuse::Album }
5
+
4
6
  describe "#<=>" do
5
7
  context "comparing nil ranks" do
6
8
  before do
7
- @nil1 = Metamuse::Album.new :rank => nil
8
- @nil2 = Metamuse::Album.new :rank => nil
9
- @album1 = Metamuse::Album.new(:rank => 1)
10
- @album3 = Metamuse::Album.new(:rank => 3)
11
- @album5 = Metamuse::Album.new(:rank => 5)
9
+ @nil1 = subject.new :rank => nil
10
+ @nil2 = subject.new :rank => nil
11
+ @album1 = subject.new :rank => 1
12
+ @album3 = subject.new :rank => 3
13
+ @album5 = subject.new :rank => 5
12
14
  end
13
15
 
14
16
  it "moves the nil from the beginning to the end" do
@@ -32,4 +34,33 @@ describe Metamuse::Album do
32
34
  end
33
35
  end
34
36
  end
37
+
38
+ describe "#hash" do
39
+ it "hashes based on the artist and album name" do
40
+ artist = Metamuse::Artist.new :name => 'Radiohead'
41
+ album = subject.new :name => 'In Rainbows', :artist => artist
42
+ album.hash.should == [artist, 'In Rainbows'].hash
43
+ end
44
+ end
45
+
46
+ describe "#eql?" do
47
+ it "evaluates equality by name" do
48
+ album1 = subject.new :name => 'In Rainbows'
49
+ album2 = subject.new :name => 'In Rainbows'
50
+ album1.should eql(album2)
51
+ end
52
+ end
53
+
54
+ describe "a unique set of albums" do
55
+ before do
56
+ @album1 = subject.new :name => 'In Rainbows'
57
+ @album2 = subject.new :name => 'Hail to the Thief'
58
+ @album3 = subject.new :name => 'In Rainbows'
59
+ end
60
+
61
+ it "removes the duplicate album name from the set" do
62
+ albums = [@album1, @album2, @album3]
63
+ albums.uniq.should == [@album1, @album2]
64
+ end
65
+ end
35
66
  end
@@ -3,6 +3,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
3
3
  describe Metamuse::Services::Lastfm::Artist do
4
4
  subject { Metamuse::Services::Lastfm::Artist }
5
5
 
6
+ describe ".build" do
7
+ context "unsuccessful response from lastfm" do
8
+ it "returns an invalid artist with no similar artists" do
9
+ response = {'lfm' => {'status' => 'failed'}}
10
+ artist = subject.build(response)
11
+ artist.should_not be_valid
12
+ artist.similar_artists.should be_empty
13
+ end
14
+ end
15
+ end
16
+
6
17
  describe "#valid?" do
7
18
  it "is an invalid artist when the url contains '+noredirect'" do
8
19
  artist = subject.new :url => 'http://last.fm/music/+noredirect/Cold Play'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandro-metamuse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Turriate