1
0
Fork 0

Merge pull request #32 from jvoegele/feature/find-release-by-discid

Find release by DiscID with updated RSpec
This commit is contained in:
Gregory Eremin 2015-03-14 22:00:10 +07:00
commit 426fed8906
5 changed files with 31 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.ruby-version
coverage
.bundle
tmp

View File

@ -24,6 +24,7 @@ require "musicbrainz/models/track"
require "musicbrainz/bindings/artist"
require "musicbrainz/bindings/artist_search"
require "musicbrainz/bindings/artist_release_groups"
require "musicbrainz/bindings/discid_releases"
require "musicbrainz/bindings/relations"
require "musicbrainz/bindings/release_group"
require "musicbrainz/bindings/release_group_search"

View File

@ -0,0 +1,13 @@
module MusicBrainz
module Bindings
module DiscidReleases
def parse(xml)
xml.xpath('./disc/release-list/release').map do |xml|
MusicBrainz::Bindings::Release.parse(xml)
end
end
extend self
end
end
end

View File

@ -10,7 +10,7 @@ module MusicBrainz
field :asin, String
field :barcode, String
field :quality, String
def tracks
@tracks ||= client.load(:release, { id: id, inc: [:recordings, :media], limit: 100 }, {
binding: :release_tracks,
@ -26,6 +26,13 @@ module MusicBrainz
create_model: :release
})
end
def find_by_discid(id)
client.load(:discid, { id: id }, {
binding: :discid_releases,
create_models: :release
})
end
end
end
end

View File

@ -35,4 +35,12 @@ describe MusicBrainz::Release do
expect(tracks.first.title).to eq "Empire"
expect(tracks.first.length).to eq 233013
end
it "gets a list of matching releases for a discid" do
releases = MusicBrainz::Release.find_by_discid("pmzhT6ZlFiwSRCdVwV0eqire5_Y-")
expect(releases.length).to eq 2
expect(releases.first.id).to eq "7a31cd5f-6a57-4fca-a731-c521df1d3b78"
expect(releases.first.title).to eq "Kveikur"
expect(releases.first.asin).to eq "B00C1GBOU6"
end
end