Skip to content

Commit

Permalink
Add track ID (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard-Degenne authored Jan 6, 2025
1 parent 903988f commit 45ca1f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/musicbrainz/bindings/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Bindings
module Track
def parse(xml)
{
id: (xml.attribute('id').value rescue nil),
position: (xml.xpath('./position').text rescue nil),
recording_id: (xml.xpath('./recording').attribute('id').value rescue nil),
title: (xml.xpath('./recording/title').text rescue nil),
Expand Down
1 change: 1 addition & 0 deletions lib/musicbrainz/models/track.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module MusicBrainz
class Track < BaseModel
field :id, String
field :position, Integer
field :recording_id, String
field :title, String
Expand Down
27 changes: 27 additions & 0 deletions spec/bindings/track_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "spec_helper"

describe MusicBrainz::Bindings::Track do
describe '.parse' do
subject(:parse) { described_class.parse(xml) }

let(:xml) { Nokogiri::XML(<<~XML).at_xpath('track') }
<track id="0501cf38-48b7-3026-80d2-717d574b3d6a">
<position>1</position>
<number>1</number>
<length>233013</length>
<recording id="b3015bab-1540-4d4e-9f30-14872a1525f7">
<title>Empire</title>
<length>233013</length>
<first-release-date>2006-08-25</first-release-date>
</recording>
</track>
XML

it 'contains track attributes' do
expect(parse).to include(
id: '0501cf38-48b7-3026-80d2-717d574b3d6a', position: '1', length: '233013',
recording_id: 'b3015bab-1540-4d4e-9f30-14872a1525f7', title: 'Empire'
)
end
end
end

0 comments on commit 45ca1f7

Please sign in to comment.