created new track_search binding to allow searching for tracks (really recordings). Modified existing model classes to call super() to handle search (open/closed principle, attempting to reduce duplicate code). Fixed xml namespace issue in specs.

This commit is contained in:
Thomas Wolfe
2013-05-05 18:14:44 -05:00
parent 687ce1b785
commit d8184565a2
13 changed files with 96 additions and 26 deletions
+3 -3
View File
@@ -5,8 +5,8 @@ require "spec_helper"
describe MusicBrainz::Bindings::ReleaseGroupSearch do
describe '.parse' do
it "gets correct release group data" do
response = '<release-group-list><release-group id="246bc928-2dc8-35ba-80ee-7a0079de1632" type="Single" ext:score="100"><title>Empire</title></release-group>'
described_class.parse(Nokogiri::XML.parse(response)).should == [
response = '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><release-group-list><release-group id="246bc928-2dc8-35ba-80ee-7a0079de1632" type="Single" ext:score="100"><title>Empire</title></release-group></release-group-list></metadata>'
described_class.parse(Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')).should == [
{
id: '246bc928-2dc8-35ba-80ee-7a0079de1632', mbid: '246bc928-2dc8-35ba-80ee-7a0079de1632',
title: 'Empire', type: 'Single', score: 100
@@ -14,4 +14,4 @@ describe MusicBrainz::Bindings::ReleaseGroupSearch do
]
end
end
end
end
+17
View File
@@ -0,0 +1,17 @@
# -*- encoding: utf-8 -*-
require "spec_helper"
describe MusicBrainz::Bindings::TrackSearch do
describe '.parse' do
it "gets correct Track (really recording) data" do
response = '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><recording-list offset="0" count="1"><recording id="0b382a13-32f0-4743-9248-ba5536a6115e" ext:score="100"><title>King Fred</title><artist-credit><name-credit><artist id="f52f7a92-d495-4d32-89e7-8b1e5b8541c8"><name>Too Much Joy</name></artist></name-credit></artist-credit><release-list><release id="8442e42b-c40a-4817-89a0-dbe663c94d2d"><title>Green Eggs and Crack</title></release></release-list></recording></recording-list></metadata>'
described_class.parse(Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')).should == [
{
id: '0b382a13-32f0-4743-9248-ba5536a6115e', mbid: '0b382a13-32f0-4743-9248-ba5536a6115e',
title: 'King Fred', artist: 'Too Much Joy', releases: ['Green Eggs and Crack'], score: 100
}
]
end
end
end
+3 -3
View File
@@ -31,13 +31,13 @@ describe MusicBrainz::ReleaseGroup do
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire')
matches.length.should be > 0
matches.first[:title].should == 'Empire'
matches.first[:type].should == 'Single'
matches.first[:type].should == 'Album'
end
end
context 'with type filter' do
it "searches release group by artist name and title" do
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', type: 'Album')
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', 'Album')
matches.length.should be > 0
matches.first[:title].should == 'Empire'
matches.first[:type].should == 'Album'
@@ -48,7 +48,7 @@ describe MusicBrainz::ReleaseGroup do
describe '.find_by_artist_and_title' do
it "gets first release group by artist name and title" do
release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
release_group.id.should == '246bc928-2dc8-35ba-80ee-7a0079de1632'
release_group.id.should == '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
end
end