1
0
Fork 0

track_search now works, will be moved to it's own recording model.

This commit is contained in:
Thomas Wolfe 2013-05-31 20:32:45 -05:00 committed by Diego d'Ursel
parent 426fed8906
commit 813b6f0383
4 changed files with 34 additions and 19 deletions

View File

@ -24,11 +24,15 @@ module MusicBrainz
MusicBrainz.client
end
def search(hash)
def search(hash, resource=nil)
hash = escape_strings(hash)
query_val = build_query(hash)
underscore_name = self.name[13..-1].underscore
client.load(underscore_name.to_sym, { query: query_val, limit: 10 }, { binding: underscore_name.insert(-1,"_search").to_sym })
if resource # only needed since "track" is really a "recording", ugly
client.load(resource, { query: query_val, limit: 10 }, { binding: underscore_name.insert(-1,"_search").to_sym })
else
client.load(underscore_name.to_sym, { query: query_val, limit: 10 }, { binding: underscore_name.insert(-1,"_search").to_sym })
end
end
class ::String

View File

@ -14,7 +14,8 @@ module MusicBrainz
end
def search(artist_name, track_name)
super({artist: artist_name, recording: track_name})
# this model really should be named "recording" I'd rename, but I don't want to break anything
super({recording: track_name, artist: artist_name}, "recording")
end
end
end

View File

@ -61,7 +61,6 @@ describe MusicBrainz::ReleaseGroup do
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
.with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels')
.and_return({ status: 200, body: response})
release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
expect(release_group.id).to eq '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
end

View File

@ -3,21 +3,32 @@
require "spec_helper"
describe MusicBrainz::Track do
it "gets no exception while loading release info" do
expect {
MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
}.to_not raise_error(Exception)
end
describe '.find' do
it "gets no exception while loading release info" do
lambda {
MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
}.should_not raise_error(Exception)
end
it "gets correct instance" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
expect(track).to be_an_instance_of(MusicBrainz::Track)
end
it "gets correct instance" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
track.should be_an_instance_of(MusicBrainz::Track)
end
it "gets correct track data" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
expect(track.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
expect(track.title).to eq "Empire"
expect(track.length).to eq 233013
end
it "gets correct track data" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
track.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7"
track.title.should == "Empire"
track.length.should == 233013
end
end
describe '.search' do
it "searches tracks (aka recordings) by artist name and title" do
matches = MusicBrainz::Track.search('Local H', 'Bound for the floor')
matches.length.should be > 0
matches.first[:title].should == 'Empire'
matches.first[:type].should == 'Album'
end
end
end