musicbrainz 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +26 -0
  3. data/.gitignore +2 -2
  4. data/Gemfile +11 -0
  5. data/Gemfile.lock +54 -0
  6. data/LICENSE +2 -2
  7. data/README.md +21 -10
  8. data/lib/musicbrainz/bindings/artist.rb +0 -1
  9. data/lib/musicbrainz/bindings/artist_search.rb +0 -1
  10. data/lib/musicbrainz/bindings/discid_releases.rb +13 -0
  11. data/lib/musicbrainz/bindings/recording.rb +19 -0
  12. data/lib/musicbrainz/bindings/{track_search.rb → recording_search.rb} +1 -2
  13. data/lib/musicbrainz/bindings/relations.rb +1 -2
  14. data/lib/musicbrainz/bindings/release_group_search.rb +0 -1
  15. data/lib/musicbrainz/client_modules/caching_proxy.rb +27 -13
  16. data/lib/musicbrainz/models/base_model.rb +12 -2
  17. data/lib/musicbrainz/models/recording.rb +20 -0
  18. data/lib/musicbrainz/models/release.rb +8 -1
  19. data/lib/musicbrainz/models/track.rb +0 -4
  20. data/lib/musicbrainz/version.rb +1 -1
  21. data/lib/musicbrainz.rb +4 -1
  22. data/musicbrainz.gemspec +3 -6
  23. data/spec/bindings/recording_search_spec.rb +48 -0
  24. data/spec/bindings/relations_spec.rb +45 -26
  25. data/spec/bindings/release_group_search_spec.rb +24 -6
  26. data/spec/bindings/release_spec.rb +94 -18
  27. data/spec/client_modules/cache_spec.rb +18 -17
  28. data/spec/deprecated/cache_config_spec.rb +4 -6
  29. data/spec/deprecated/proxy_config_spec.rb +4 -6
  30. data/spec/fixtures/artist/find_69b39eab-6577-46a4-a9f5-817839092033.xml +168 -0
  31. data/spec/fixtures/artist/release_groups_69b39eab-6577-46a4-a9f5-817839092033.xml +412 -0
  32. data/spec/fixtures/artist/search_kasabian.xml +104 -0
  33. data/spec/fixtures/recording/find_b3015bab-1540-4d4e-9f30-14872a1525f7.xml +8 -0
  34. data/spec/fixtures/recording/search_bound_for_the_floor_local_h.xml +647 -0
  35. data/spec/fixtures/release/find_2225dd4c-ae9a-403b-8ea0-9e05014c778f.xml +44 -0
  36. data/spec/fixtures/release/find_2225dd4c-ae9a-403b-8ea0-9e05014c778f_tracks.xml +151 -0
  37. data/spec/fixtures/release/find_b94cb547-cf7a-4357-894c-53c3bf33b093.xml +52 -0
  38. data/spec/fixtures/release/find_by_discid_pmzhT6ZlFiwSRCdVwV0eqire5_Y-.xml +141 -0
  39. data/spec/fixtures/release/list_6f33e0f0-cde2-38f9-9aee-2c60af8d1a61.xml +344 -0
  40. data/spec/fixtures/release_group/search_kasabian_empire_album.xml +117 -0
  41. data/spec/models/artist_spec.rb +77 -46
  42. data/spec/models/base_model_spec.rb +50 -22
  43. data/spec/models/recording_spec.rb +42 -0
  44. data/spec/models/release_group_spec.rb +61 -55
  45. data/spec/models/release_spec.rb +63 -28
  46. data/spec/models/track_spec.rb +19 -15
  47. data/spec/spec_helper.rb +7 -7
  48. data/spec/support/mock_helpers.rb +13 -0
  49. metadata +55 -93
  50. data/.rspec +0 -1
  51. data/.travis.yml +0 -4
  52. data/spec/bindings/track_search_spec.rb +0 -17
  53. data/spec/fixtures/artist/search.xml +0 -67
  54. data/spec/fixtures/kasabian.xml +0 -1
  55. data/spec/fixtures/release/list.xml +0 -344
  56. /data/spec/fixtures/release_group/{entity.xml → find_6f33e0f0-cde2-38f9-9aee-2c60af8d1a61.xml} +0 -0
  57. /data/spec/fixtures/release_group/{search.xml → search_kasabian_empire.xml} +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7229772a6c7a6856ce99aac9911bb4730ca5ceddfc77609fde69fbdefa8b9ab2
4
+ data.tar.gz: 5a9cab7520265b089cbc380148c99fc8144e3debd34670e0c96f9437a6a24e8e
5
+ SHA512:
6
+ metadata.gz: c28ed7913d03641380d8491db8820f8ea31e2b8bb2969950b838de09805df395cb48c5cc95c21a1d647f00a48ea88c7ffc2218e714b26dfcea892f5851720aac
7
+ data.tar.gz: 469d7cce11dcecadd2f1abd2a16f23266f295edf523f3d6757b1760bd297ef2e86efeb3b00cb2a3c38301d8c3a9cc9d55df04e0246b289083affde999cfca1a8
@@ -0,0 +1,26 @@
1
+ # Adopted from
2
+ # https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-ruby
3
+ name: Ruby CI
4
+
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: [ master ]
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ['3.3']
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - name: Set up Ruby ${{ matrix.ruby-version }}
20
+ uses: ruby/setup-ruby@v1.173.0
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ - name: Install dependencies
24
+ run: bundle install
25
+ - name: Run tests
26
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -1,7 +1,7 @@
1
+ .ruby-version
1
2
  coverage
2
3
  .bundle
3
4
  tmp
4
- Gemfile.lock
5
5
  .gem
6
- *.swp
7
6
  pkg/*
7
+ /vendor
data/Gemfile CHANGED
@@ -1,2 +1,13 @@
1
1
  source 'https://rubygems.org'
2
+
2
3
  gemspec
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ end
8
+
9
+ group :development, :test do
10
+ gem 'rake', '~> 13.1.0'
11
+ gem 'pry'
12
+ gem 'awesome_print'
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ musicbrainz (0.8.0)
5
+ faraday
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ awesome_print (1.9.2)
12
+ coderay (1.1.3)
13
+ diff-lcs (1.5.1)
14
+ faraday (2.9.0)
15
+ faraday-net_http (>= 2.0, < 3.2)
16
+ faraday-net_http (3.1.0)
17
+ net-http
18
+ method_source (1.0.0)
19
+ net-http (0.4.1)
20
+ uri
21
+ nokogiri (1.16.3-x86_64-linux)
22
+ racc (~> 1.4)
23
+ pry (0.14.2)
24
+ coderay (~> 1.1)
25
+ method_source (~> 1.0)
26
+ racc (1.7.3)
27
+ rake (13.1.0)
28
+ rspec (3.13.0)
29
+ rspec-core (~> 3.13.0)
30
+ rspec-expectations (~> 3.13.0)
31
+ rspec-mocks (~> 3.13.0)
32
+ rspec-core (3.13.0)
33
+ rspec-support (~> 3.13.0)
34
+ rspec-expectations (3.13.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.13.0)
37
+ rspec-mocks (3.13.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.13.0)
40
+ rspec-support (3.13.1)
41
+ uri (0.13.0)
42
+
43
+ PLATFORMS
44
+ x86_64-linux
45
+
46
+ DEPENDENCIES
47
+ awesome_print
48
+ musicbrainz!
49
+ pry
50
+ rake (~> 13.1.0)
51
+ rspec
52
+
53
+ BUNDLED WITH
54
+ 2.3.26
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Gregory Eremin
1
+ Copyright (c) 2024 Gregory Eremin
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,9 +1,4 @@
1
- ## MusicBrainz Web Service wrapper [![Travis CI](https://secure.travis-ci.org/magnolia-fan/musicbrainz.png)](http://travis-ci.org/magnolia-fan/musicbrainz)
2
-
3
- ### Ruby Version
4
- **IMPORTANT!**
5
-
6
- Ruby version 1.9+ required. No support for 1.8.7 anymore, if you still on 1.8 consider using gem [version 0.5.2](https://github.com/magnolia-fan/musicbrainz/tree/v0.5.2#musicbrainz-web-service-wrapper-) and bundle it like this:
1
+ ## MusicBrainz Web Service wrapper
7
2
 
8
3
  ```ruby
9
4
  gem 'musicbrainz', '0.5.2'
@@ -121,11 +116,10 @@ MusicBrainz::Release.find(id)
121
116
  }
122
117
  ```
123
118
 
124
- MusicBrainz::Track
119
+ MusicBrainz::Track (depreciated, now called Recording)
125
120
  ```ruby
126
121
  # Class Methods
127
122
  MusicBrainz::Track.find(id)
128
- MusicBrainz::ReleaseGroup.search(artist_name, track_name)
129
123
 
130
124
  # Fields
131
125
  {
@@ -136,6 +130,23 @@ MusicBrainz::ReleaseGroup.search(artist_name, track_name)
136
130
  }
137
131
  ```
138
132
 
133
+ MusicBrainz::Recording
134
+ ```ruby
135
+ # Class Methods
136
+ MusicBrainz::Recording.find(id)
137
+ MusicBrainz::Recording.search(track_name, artist_name)
138
+
139
+ # Fields
140
+ {
141
+ :id => Integer,
142
+ :mbid => Integer,
143
+ :title => String,
144
+ :artist => String,
145
+ :releases => String,
146
+ :score => Integer
147
+ }
148
+ ```
149
+
139
150
  ### Testing
140
151
  ```
141
152
  bundle exec rspec
@@ -156,6 +167,6 @@ bundle exec irb -r musicbrainz
156
167
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
157
168
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
158
169
 
159
- ### Copyright
170
+ ### License
160
171
 
161
- Copyright (c) 2014 Gregory Eremin. See [LICENSE](https://raw.github.com/magnolia-fan/musicbrainz/master/LICENSE) for further details.
172
+ [MIT](https://raw.github.com/localhots/musicbrainz/master/LICENSE)
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module MusicBrainz
3
2
  module Bindings
4
3
  module Artist
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module MusicBrainz
3
2
  module Bindings
4
3
  module ArtistSearch
@@ -0,0 +1,13 @@
1
+ module MusicBrainz
2
+ module Bindings
3
+ module DiscidReleases
4
+ def parse(xml)
5
+ xml.xpath('./disc/release-list/release').map do |xml|
6
+ MusicBrainz::Bindings::Release.parse(xml)
7
+ end
8
+ end
9
+
10
+ extend self
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module MusicBrainz
2
+ module Bindings
3
+ module Recording
4
+ def parse(xml)
5
+ xml = xml.xpath('./recording') unless xml.xpath('./recording').empty?
6
+ {
7
+ id: (xml.attribute('id').value rescue nil),
8
+ mbid: (xml.attribute('id').value rescue nil), # Old shit
9
+ title: (xml.xpath('./title').text.gsub(/[`’]/, "'") rescue nil),
10
+ artist: (xml.xpath('./artist-credit/name-credit/artist/name').text rescue nil),
11
+ releases: (xml.xpath('./release-list/release/title').map{ |xml| xml.text } rescue []),
12
+ score: (xml.attribute('score').value.to_i rescue nil)
13
+ }
14
+ end
15
+
16
+ extend self
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,6 @@
1
- # encoding: UTF-8
2
1
  module MusicBrainz
3
2
  module Bindings
4
- module TrackSearch
3
+ module RecordingSearch
5
4
  def parse(xml)
6
5
  xml.xpath('./recording-list/recording').map do |xml|
7
6
  {
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module MusicBrainz
3
2
  module Bindings
4
3
  module Relations
@@ -23,4 +22,4 @@ module MusicBrainz
23
22
  extend self
24
23
  end
25
24
  end
26
- end
25
+ end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module MusicBrainz
3
2
  module Bindings
4
3
  module ReleaseGroupSearch
@@ -19,28 +19,42 @@ module MusicBrainz
19
19
  response = { body: nil, status: 500 }
20
20
 
21
21
  if File.exist?(file_path)
22
- response = {
23
- body: File.open(file_path, 'rb').gets,
24
- status: 200
25
- }
22
+ get_cached_contents(file_path)
26
23
  else
27
- response = super
24
+ response = get_live_contents(file_path, url)
28
25
  if response[:status] == 200
29
- FileUtils.mkpath(dir_path)
30
- File.open(file_path, 'wb') do |f|
31
- f.puts(response[:body])
32
- f.chmod(0755)
33
- f.close
34
- end
26
+ cache_contents!(file_path, response[:body])
35
27
  end
28
+ response
36
29
  end
37
-
38
- response
39
30
  end
40
31
 
41
32
  def caching?
42
33
  MusicBrainz.config.perform_caching
43
34
  end
35
+
36
+ private
37
+
38
+ def get_cached_contents(file_path)
39
+ {
40
+ body: File.open(file_path, 'rb').gets,
41
+ status: 200
42
+ }
43
+ end
44
+
45
+ def get_live_contents(file_path, url)
46
+ http.get(url)
47
+ end
48
+
49
+ def cache_contents!(file_path, body)
50
+ dir_path = File.dirname(file_path)
51
+ FileUtils.mkpath(dir_path)
52
+ File.open(file_path, 'wb') do |f|
53
+ f.puts(body)
54
+ f.chmod(0755)
55
+ f.close
56
+ end
57
+ end
44
58
  end
45
59
  end
46
60
  end
@@ -24,11 +24,16 @@ module MusicBrainz
24
24
  MusicBrainz.client
25
25
  end
26
26
 
27
+ def find(hash)
28
+ underscored_name = underscore_name.to_sym
29
+ client.load(underscored_name, hash, { binding: underscored_name, create_model: underscored_name })
30
+ end
31
+
27
32
  def search(hash)
28
33
  hash = escape_strings(hash)
29
34
  query_val = build_query(hash)
30
- underscore_name = self.name[13..-1].underscore
31
- client.load(underscore_name.to_sym, { query: query_val, limit: 10 }, { binding: underscore_name.insert(-1,"_search").to_sym })
35
+ underscored_name = underscore_name
36
+ client.load(underscored_name.to_sym, { query: query_val, limit: 10 }, { binding: underscored_name.insert(-1,"_search").to_sym })
32
37
  end
33
38
 
34
39
  class ::String
@@ -53,6 +58,11 @@ module MusicBrainz
53
58
  hash
54
59
  end
55
60
 
61
+ def underscore_name
62
+ # self.name[13..-1] => removes MusicBrainz::
63
+ self.name[13..-1].underscore
64
+ end
65
+
56
66
  # these probably should be private... but I'm not sure how to get it to work in a module...
57
67
  # private_class_method :build_query, :escape_strings
58
68
  end
@@ -0,0 +1,20 @@
1
+ module MusicBrainz
2
+ class Recording < BaseModel
3
+ field :id, String
4
+ field :mbid, String
5
+ field :title, String
6
+ field :artist, String
7
+ field :releases, String
8
+ field :score, Integer
9
+
10
+ class << self
11
+ def find(id)
12
+ super({ id: id })
13
+ end
14
+
15
+ def search(track_name, artist_name)
16
+ super({recording: track_name, artist: artist_name})
17
+ end
18
+ end
19
+ end
20
+ end
@@ -10,7 +10,7 @@ module MusicBrainz
10
10
  field :asin, String
11
11
  field :barcode, String
12
12
  field :quality, String
13
-
13
+
14
14
  def tracks
15
15
  @tracks ||= client.load(:release, { id: id, inc: [:recordings, :media], limit: 100 }, {
16
16
  binding: :release_tracks,
@@ -26,6 +26,13 @@ module MusicBrainz
26
26
  create_model: :release
27
27
  })
28
28
  end
29
+
30
+ def find_by_discid(id)
31
+ client.load(:discid, { id: id }, {
32
+ binding: :discid_releases,
33
+ create_models: :release
34
+ })
35
+ end
29
36
  end
30
37
  end
31
38
  end
@@ -12,10 +12,6 @@ module MusicBrainz
12
12
  create_model: :track
13
13
  })
14
14
  end
15
-
16
- def search(artist_name, track_name)
17
- super({artist: artist_name, recording: track_name})
18
- end
19
15
  end
20
16
  end
21
17
  end
@@ -1,3 +1,3 @@
1
1
  module MusicBrainz
2
- VERSION = "0.7.7"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/musicbrainz.rb CHANGED
@@ -20,10 +20,12 @@ require "musicbrainz/models/artist"
20
20
  require "musicbrainz/models/release_group"
21
21
  require "musicbrainz/models/release"
22
22
  require "musicbrainz/models/track"
23
+ require "musicbrainz/models/recording"
23
24
 
24
25
  require "musicbrainz/bindings/artist"
25
26
  require "musicbrainz/bindings/artist_search"
26
27
  require "musicbrainz/bindings/artist_release_groups"
28
+ require "musicbrainz/bindings/discid_releases"
27
29
  require "musicbrainz/bindings/relations"
28
30
  require "musicbrainz/bindings/release_group"
29
31
  require "musicbrainz/bindings/release_group_search"
@@ -31,7 +33,8 @@ require "musicbrainz/bindings/release_group_releases"
31
33
  require "musicbrainz/bindings/release"
32
34
  require "musicbrainz/bindings/release_tracks"
33
35
  require "musicbrainz/bindings/track"
34
- require "musicbrainz/bindings/track_search"
36
+ require "musicbrainz/bindings/recording"
37
+ require "musicbrainz/bindings/recording_search"
35
38
 
36
39
  module MusicBrainz
37
40
  GH_PAGE_URL = "http://git.io/brainz"
data/musicbrainz.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
4
4
  gem.authors = ["Gregory Eremin"]
5
5
  gem.email = ["magnolia_fan@me.com"]
6
6
  gem.summary = %q{ MusicBrainz Web Service wrapper with ActiveRecord-style models }
7
- gem.homepage = "http://github.com/magnolia-fan/musicbrainz"
7
+ gem.homepage = "http://github.com/localhots/musicbrainz"
8
8
 
9
9
  gem.files = %x{ git ls-files }.split($\)
10
10
  gem.executables = []
@@ -14,9 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.version = MusicBrainz::VERSION
15
15
  gem.license = "MIT"
16
16
 
17
- gem.add_dependency('faraday')
18
- gem.add_dependency('nokogiri')
19
- gem.add_development_dependency('rspec')
20
- gem.add_development_dependency('awesome_print')
21
- gem.add_development_dependency('rake', '~> 10.4.0')
17
+ gem.add_runtime_dependency('faraday')
18
+ gem.add_runtime_dependency('nokogiri')
22
19
  end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe MusicBrainz::Bindings::RecordingSearch do
4
+ describe '.parse' do
5
+ let(:response) {
6
+ <<-XML
7
+ <metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
8
+ <recording-list count="1" offset="0">
9
+ <recording ext:score="100" id="0b382a13-32f0-4743-9248-ba5536a6115e">
10
+ <title>King Fred</title>
11
+ <artist-credit>
12
+ <name-credit>
13
+ <artist id="f52f7a92-d495-4d32-89e7-8b1e5b8541c8">
14
+ <name>Too Much Joy</name>
15
+ </artist>
16
+ </name-credit>
17
+ </artist-credit>
18
+ <release-list>
19
+ <release id="8442e42b-c40a-4817-89a0-dbe663c94d2d">
20
+ <title>Green Eggs and Crack</title>
21
+ </release>
22
+ </release-list>
23
+ </recording>
24
+ </recording-list>
25
+ </metadata>
26
+ XML
27
+ }
28
+ let(:xml) {
29
+ Nokogiri::XML.parse(response).remove_namespaces!
30
+ }
31
+ let(:metadata) {
32
+ described_class.parse(xml.xpath('/metadata'))
33
+ }
34
+
35
+ it "gets correct Recording data" do
36
+ expect(metadata).to eq [
37
+ {
38
+ id: '0b382a13-32f0-4743-9248-ba5536a6115e',
39
+ mbid: '0b382a13-32f0-4743-9248-ba5536a6115e',
40
+ title: 'King Fred',
41
+ artist: 'Too Much Joy',
42
+ releases: ['Green Eggs and Crack'],
43
+ score: 100,
44
+ }
45
+ ]
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "spec_helper"
4
2
 
5
3
  describe MusicBrainz::Bindings::Relations do
@@ -7,38 +5,59 @@ describe MusicBrainz::Bindings::Relations do
7
5
  describe 'attributes' do
8
6
  describe 'urls' do
9
7
  context '1 url for relation type' do
8
+ let(:response) {
9
+ <<-XML
10
+ <artist>
11
+ <relation-list target-type="url">
12
+ <relation type="social network" type-id="99429741-f3f6-484b-84f8-23af51991770">
13
+ <target id="4f4068cb-7001-47a3-a2fe-9146eb6b5d16">https://plus.google.com/+Madonna</target>
14
+ </relation>
15
+ </relation-list>
16
+ </artist>
17
+ XML
18
+ }
19
+ let(:xml) {
20
+ Nokogiri::XML.parse(response)
21
+ }
22
+ let(:artist) {
23
+ described_class.parse(xml.xpath('./artist'))
24
+ }
25
+
10
26
  it 'returns a string' do
11
- xml = Nokogiri::XML.parse(
12
- %Q{<artist><relation-list target-type="url">
13
- <relation type-id="99429741-f3f6-484b-84f8-23af51991770" type="social network">
14
- <target id="4f4068cb-7001-47a3-a2fe-9146eb6b5d16">https://plus.google.com/+Madonna</target>
15
- </relation>
16
- </relation-list></artist>}
17
- )
18
-
19
- described_class.parse(xml.xpath('./artist'))[:urls][:social_network].should == 'https://plus.google.com/+Madonna'
27
+ expect(artist[:urls][:social_network]).to eq 'https://plus.google.com/+Madonna'
20
28
  end
21
29
  end
22
-
30
+
23
31
  context 'multiple urls for relation types' do
24
- it 'returns an array' do
25
- xml = Nokogiri::XML.parse(
26
- %Q{<artist><relation-list target-type="url">
27
- <relation type-id="99429741-f3f6-484b-84f8-23af51991770" type="social network">
28
- <target id="4f4068cb-7001-47a3-a2fe-9146eb6b5d16">https://plus.google.com/+Madonna</target>
29
- </relation>
30
- <relation type-id="99429741-f3f6-484b-84f8-23af51991770" type="social network">
31
- <target id="1dc9e14d-ebfb-448c-a005-e3481d320595">https://www.facebook.com/madonna</target>
32
- </relation>
33
- </relation-list></artist>}
34
- )
32
+ let(:response) {
33
+ <<-XML
34
+ <artist>
35
+ <relation-list target-type="url">
36
+ <relation type="social network" type-id="99429741-f3f6-484b-84f8-23af51991770">
37
+ <target id="4f4068cb-7001-47a3-a2fe-9146eb6b5d16">https://plus.google.com/+Madonna</target>
38
+ </relation>
39
+ <relation type="social network" type-id="99429741-f3f6-484b-84f8-23af51991770">
40
+ <target id="1dc9e14d-ebfb-448c-a005-e3481d320595">https://www.facebook.com/madonna</target>
41
+ </relation>
42
+ </relation-list>
43
+ </artist>
44
+ XML
45
+ }
46
+ let(:xml) {
47
+ Nokogiri::XML.parse(response)
48
+ }
49
+ let(:artist) {
50
+ described_class.parse(xml.xpath('./artist'))
51
+ }
35
52
 
36
- described_class.parse(xml.xpath('./artist'))[:urls][:social_network].should == [
37
- 'https://plus.google.com/+Madonna', 'https://www.facebook.com/madonna'
53
+ it 'returns an array' do
54
+ expect(artist[:urls][:social_network]).to eq [
55
+ 'https://plus.google.com/+Madonna',
56
+ 'https://www.facebook.com/madonna',
38
57
  ]
39
58
  end
40
59
  end
41
60
  end
42
61
  end
43
62
  end
44
- end
63
+ end
@@ -1,15 +1,33 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "spec_helper"
4
2
 
5
3
  describe MusicBrainz::Bindings::ReleaseGroupSearch do
6
4
  describe '.parse' do
5
+ let(:response) {
6
+ <<-XML
7
+ <metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
8
+ <release-group-list>
9
+ <release-group ext:score="100" id="246bc928-2dc8-35ba-80ee-7a0079de1632" type="Single">
10
+ <title>Empire</title>
11
+ </release-group>
12
+ </release-group-list>
13
+ </metadata>
14
+ XML
15
+ }
16
+ let(:xml) {
17
+ Nokogiri::XML.parse(response)
18
+ }
19
+ let(:metadata) {
20
+ described_class.parse(xml.remove_namespaces!.xpath('/metadata'))
21
+ }
22
+
7
23
  it "gets correct release group data" do
8
- 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>'
9
- described_class.parse(Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')).should == [
24
+ expect(metadata).to eq [
10
25
  {
11
- id: '246bc928-2dc8-35ba-80ee-7a0079de1632', mbid: '246bc928-2dc8-35ba-80ee-7a0079de1632',
12
- title: 'Empire', type: 'Single', score: 100
26
+ id: '246bc928-2dc8-35ba-80ee-7a0079de1632',
27
+ mbid: '246bc928-2dc8-35ba-80ee-7a0079de1632',
28
+ title: 'Empire',
29
+ type: 'Single',
30
+ score: 100,
13
31
  }
14
32
  ]
15
33
  end