track_search now works, will be moved to it's own recording model.
This commit is contained in:
parent
426fed8906
commit
813b6f0383
|
@ -24,11 +24,15 @@ module MusicBrainz
|
||||||
MusicBrainz.client
|
MusicBrainz.client
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(hash)
|
def search(hash, resource=nil)
|
||||||
hash = escape_strings(hash)
|
hash = escape_strings(hash)
|
||||||
query_val = build_query(hash)
|
query_val = build_query(hash)
|
||||||
underscore_name = self.name[13..-1].underscore
|
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
|
end
|
||||||
|
|
||||||
class ::String
|
class ::String
|
||||||
|
|
|
@ -14,7 +14,8 @@ module MusicBrainz
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(artist_name, track_name)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,7 +61,6 @@ describe MusicBrainz::ReleaseGroup do
|
||||||
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
|
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')
|
.with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels')
|
||||||
.and_return({ status: 200, body: response})
|
.and_return({ status: 200, body: response})
|
||||||
|
|
||||||
release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
|
release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
|
||||||
expect(release_group.id).to eq '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
|
expect(release_group.id).to eq '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,21 +3,32 @@
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
describe MusicBrainz::Track do
|
describe MusicBrainz::Track do
|
||||||
it "gets no exception while loading release info" do
|
describe '.find' do
|
||||||
expect {
|
it "gets no exception while loading release info" do
|
||||||
MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
|
lambda {
|
||||||
}.to_not raise_error(Exception)
|
MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
|
||||||
end
|
}.should_not raise_error(Exception)
|
||||||
|
end
|
||||||
|
|
||||||
it "gets correct instance" do
|
it "gets correct instance" do
|
||||||
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
|
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
|
||||||
expect(track).to be_an_instance_of(MusicBrainz::Track)
|
track.should be_an_instance_of(MusicBrainz::Track)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gets correct track data" do
|
it "gets correct track data" do
|
||||||
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
|
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
|
||||||
expect(track.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
|
track.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7"
|
||||||
expect(track.title).to eq "Empire"
|
track.title.should == "Empire"
|
||||||
expect(track.length).to eq 233013
|
track.length.should == 233013
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue