2013-11-06 02:15:09 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-07-08 22:37:46 +00:00
|
|
|
|
2012-07-04 13:10:47 +00:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe MusicBrainz::ReleaseGroup do
|
2013-01-22 15:04:15 +00:00
|
|
|
describe '.find' do
|
|
|
|
it "gets no exception while loading release group info" do
|
2015-03-13 19:39:11 +00:00
|
|
|
expect {
|
2013-01-22 15:04:15 +00:00
|
|
|
MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
|
2015-03-13 19:39:11 +00:00
|
|
|
}.to_not raise_error(Exception)
|
2013-01-22 15:04:15 +00:00
|
|
|
end
|
2015-03-13 19:39:11 +00:00
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
it "gets correct instance" do
|
|
|
|
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
|
2015-03-13 19:39:11 +00:00
|
|
|
expect(release_group).to be_an_instance_of(MusicBrainz::ReleaseGroup)
|
2013-01-22 15:04:15 +00:00
|
|
|
end
|
2015-03-13 19:39:11 +00:00
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
it "gets correct release group data" do
|
|
|
|
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
|
2015-03-13 19:39:11 +00:00
|
|
|
expect(release_group.id).to eq "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
|
|
|
|
expect(release_group.type).to eq "Album"
|
|
|
|
expect(release_group.title).to eq "Empire"
|
|
|
|
expect(release_group.first_release_date).to eq Date.new(2006, 8, 28)
|
|
|
|
expect(release_group.urls[:wikipedia]).to eq 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
|
2013-01-22 15:04:15 +00:00
|
|
|
end
|
2012-07-04 13:10:47 +00:00
|
|
|
end
|
2015-03-13 19:39:11 +00:00
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
describe '.search' do
|
|
|
|
context 'without type filter' do
|
|
|
|
it "searches release group by artist name and title" do
|
2013-05-06 17:57:32 +00:00
|
|
|
response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/search.xml")).read
|
2015-03-13 19:39:11 +00:00
|
|
|
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
|
|
|
|
.with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10')
|
|
|
|
.and_return({ status: 200, body: response})
|
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire')
|
2015-03-13 19:39:11 +00:00
|
|
|
expect(matches.length).to be > 0
|
|
|
|
expect(matches.first[:title]).to eq 'Empire'
|
|
|
|
expect(matches.first[:type]).to eq 'Album'
|
2013-01-22 15:04:15 +00:00
|
|
|
end
|
|
|
|
end
|
2015-03-13 19:39:11 +00:00
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
context 'with type filter' do
|
|
|
|
it "searches release group by artist name and title" do
|
2013-05-05 23:14:44 +00:00
|
|
|
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', 'Album')
|
2015-03-13 19:39:11 +00:00
|
|
|
expect(matches.length).to be > 0
|
|
|
|
expect(matches.first[:title]).to eq 'Empire'
|
|
|
|
expect(matches.first[:type]).to eq 'Album'
|
2013-01-22 15:04:15 +00:00
|
|
|
end
|
|
|
|
end
|
2012-07-04 13:10:47 +00:00
|
|
|
end
|
2015-03-13 19:39:11 +00:00
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
describe '.find_by_artist_and_title' do
|
|
|
|
it "gets first release group by artist name and title" do
|
2013-05-06 17:57:32 +00:00
|
|
|
response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/search.xml")).read
|
2015-03-13 19:39:11 +00:00
|
|
|
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
|
|
|
|
.with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10')
|
|
|
|
.and_return({ status: 200, body: response})
|
|
|
|
|
2013-05-06 17:57:32 +00:00
|
|
|
response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read
|
2015-03-13 19:39:11 +00:00
|
|
|
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})
|
2013-01-22 15:04:15 +00:00
|
|
|
release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
|
2015-03-13 19:39:11 +00:00
|
|
|
expect(release_group.id).to eq '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
|
2013-01-22 15:04:15 +00:00
|
|
|
end
|
2012-07-04 13:10:47 +00:00
|
|
|
end
|
2015-03-13 19:39:11 +00:00
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
describe '#releases' do
|
|
|
|
it "gets correct release group's releases" do
|
2015-03-13 19:39:11 +00:00
|
|
|
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: File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read})
|
|
|
|
|
|
|
|
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
|
|
|
|
.with('http://musicbrainz.org/ws/2/release?release-group=6f33e0f0-cde2-38f9-9aee-2c60af8d1a61&inc=media+release-groups&limit=100')
|
|
|
|
.and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release/list.xml")).read})
|
|
|
|
|
2013-01-22 15:04:15 +00:00
|
|
|
releases = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61").releases
|
2015-03-13 19:39:11 +00:00
|
|
|
expect(releases.length).to be >= 5
|
|
|
|
expect(releases.first.id).to eq "30d5e730-ce0a-464d-93e1-7d76e4bb3e31"
|
|
|
|
expect(releases.first.status).to eq "Official"
|
|
|
|
expect(releases.first.title).to eq "Empire"
|
|
|
|
expect(releases.first.date).to eq Date.new(2006, 8, 28)
|
|
|
|
expect(releases.first.country).to eq "GB"
|
|
|
|
expect(releases.first.type).to eq "Album"
|
2013-01-22 15:04:15 +00:00
|
|
|
end
|
2012-07-04 13:10:47 +00:00
|
|
|
end
|
|
|
|
end
|