From 6c2d47544ab2eac1829b8bf4697c6b407117f3d3 Mon Sep 17 00:00:00 2001 From: Mathias Gawlista Date: Fri, 14 Jun 2013 11:31:51 +0200 Subject: [PATCH] Stubs music artist search. --- spec/fixtures/artist/search.xml | 67 +++++++++++++++++++++++++++++++++ spec/models/artist_spec.rb | 14 +++---- 2 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 spec/fixtures/artist/search.xml diff --git a/spec/fixtures/artist/search.xml b/spec/fixtures/artist/search.xml new file mode 100644 index 0000000..fae1233 --- /dev/null +++ b/spec/fixtures/artist/search.xml @@ -0,0 +1,67 @@ + + + + + Chris Martin + Martin, Chris + Reggae / Dancehall singer Christopher Martin + + false + + + + Chris Martin + Martin, Chris + Illustrator + + false + + + + Chris Martin + Martin, Chris + male + GB + + United Kingdom + United Kingdom + + lead singer of Coldplay + + 00280536565 + + + 1977-03-02 + false + + + Christopher Anthony John Martin + + + + pop/rock + + + + + Chris Martin + Martin, Chris + hip hop producer DJ Premier, DJ Primo + + 1965-05-05 + false + + + Christopher Edward Martin + + + + Chris Martin + Martin, Chris + Disney songwriter/composer + + false + + + + diff --git a/spec/models/artist_spec.rb b/spec/models/artist_spec.rb index 8391ff3..1172f53 100644 --- a/spec/models/artist_spec.rb +++ b/spec/models/artist_spec.rb @@ -21,18 +21,16 @@ describe MusicBrainz::Artist do end it "should return search results in the right order and pass back the correct score" do + response = File.open(File.join(File.dirname(__FILE__), "../fixtures/artist/search.xml")).read + MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/artist?query=artist:"Chris+Martin"&limit=10'). + and_return({ status: 200, body: response}) + matches = MusicBrainz::Artist.search('Chris Martin') matches[0][:score].should == 100 - matches[0][:id].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca" + matches[0][:id].should == "90fff570-a4ef-4cd4-ba21-e00c7261b05a" matches[1][:score].should == 100 - matches[1][:id].should == "af2ab893-3212-4226-9e73-73a1660b6952" - end - - it "finds name first than alias" do - matches = MusicBrainz::Artist.search('Chris Martin') - matches.length.should be > 0 - matches.first[:mbid].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca" + matches[1][:id].should == "b732a912-af95-472c-be52-b14610734c64" end it "gets correct result by name" do