metal_archives 2.2.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +93 -0
- data/.gitignore +6 -6
- data/.overcommit.yml +35 -0
- data/.rspec +2 -0
- data/.rubocop.yml +66 -6
- data/CHANGELOG.md +33 -0
- data/Gemfile +1 -1
- data/LICENSE.md +17 -4
- data/README.md +65 -86
- data/Rakefile +8 -7
- data/bin/console +38 -0
- data/bin/setup +8 -0
- data/config/inflections.rb +7 -0
- data/config/initializers/.keep +0 -0
- data/docker-compose.yml +23 -0
- data/lib/metal_archives.rb +82 -27
- data/lib/metal_archives/cache/base.rb +40 -0
- data/lib/metal_archives/cache/memory.rb +68 -0
- data/lib/metal_archives/cache/null.rb +22 -0
- data/lib/metal_archives/cache/redis.rb +49 -0
- data/lib/metal_archives/{utils/collection.rb → collection.rb} +3 -5
- data/lib/metal_archives/configuration.rb +33 -50
- data/lib/metal_archives/{error.rb → errors.rb} +9 -1
- data/lib/metal_archives/http_client.rb +45 -44
- data/lib/metal_archives/models/artist.rb +90 -45
- data/lib/metal_archives/models/band.rb +77 -52
- data/lib/metal_archives/models/base.rb +225 -0
- data/lib/metal_archives/models/label.rb +14 -15
- data/lib/metal_archives/models/release.rb +25 -29
- data/lib/metal_archives/parsers/artist.rb +86 -50
- data/lib/metal_archives/parsers/band.rb +155 -88
- data/lib/metal_archives/parsers/base.rb +14 -0
- data/lib/metal_archives/parsers/country.rb +21 -0
- data/lib/metal_archives/parsers/date.rb +31 -0
- data/lib/metal_archives/parsers/genre.rb +67 -0
- data/lib/metal_archives/parsers/label.rb +39 -31
- data/lib/metal_archives/parsers/parser.rb +18 -63
- data/lib/metal_archives/parsers/release.rb +98 -89
- data/lib/metal_archives/parsers/year.rb +31 -0
- data/lib/metal_archives/version.rb +12 -1
- data/metal_archives.env.example +10 -0
- data/metal_archives.gemspec +43 -28
- data/nginx/default.conf +60 -0
- metadata +179 -74
- data/.travis.yml +0 -12
- data/lib/metal_archives/middleware/cache_check.rb +0 -20
- data/lib/metal_archives/middleware/encoding.rb +0 -16
- data/lib/metal_archives/middleware/headers.rb +0 -38
- data/lib/metal_archives/middleware/rewrite_endpoint.rb +0 -38
- data/lib/metal_archives/models/base_model.rb +0 -215
- data/lib/metal_archives/utils/lru_cache.rb +0 -61
- data/lib/metal_archives/utils/nil_date.rb +0 -99
- data/lib/metal_archives/utils/range.rb +0 -66
- data/spec/configuration_spec.rb +0 -96
- data/spec/factories/artist_factory.rb +0 -37
- data/spec/factories/band_factory.rb +0 -60
- data/spec/factories/nil_date_factory.rb +0 -9
- data/spec/factories/range_factory.rb +0 -8
- data/spec/models/artist_spec.rb +0 -138
- data/spec/models/band_spec.rb +0 -164
- data/spec/models/base_model_spec.rb +0 -219
- data/spec/models/release_spec.rb +0 -133
- data/spec/parser_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -111
- data/spec/support/factory_girl.rb +0 -5
- data/spec/support/metal_archives.rb +0 -33
- data/spec/utils/collection_spec.rb +0 -72
- data/spec/utils/lru_cache_spec.rb +0 -53
- data/spec/utils/nil_date_spec.rb +0 -156
- data/spec/utils/range_spec.rb +0 -62
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MetalArchives
|
4
|
-
##
|
5
|
-
# Range which can start and/or end with +nil+
|
6
|
-
#
|
7
|
-
class Range
|
8
|
-
include Comparable
|
9
|
-
|
10
|
-
##
|
11
|
-
# Begin- and endpoint of range
|
12
|
-
#
|
13
|
-
attr_accessor :begin, :end
|
14
|
-
|
15
|
-
##
|
16
|
-
# Create a new range
|
17
|
-
#
|
18
|
-
# [+_begin+]
|
19
|
-
# Start of range
|
20
|
-
#
|
21
|
-
# Default: +nil+
|
22
|
-
#
|
23
|
-
# [+_end+]
|
24
|
-
# End of range
|
25
|
-
#
|
26
|
-
# Default: +nil+
|
27
|
-
#
|
28
|
-
def initialize(_begin = nil, _end = nil)
|
29
|
-
@begin = _begin
|
30
|
-
@end = _end
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# Whether start of range is present
|
35
|
-
#
|
36
|
-
def begin?
|
37
|
-
!!@begin
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# Whether end of range is present
|
42
|
-
#
|
43
|
-
def end?
|
44
|
-
!!@end
|
45
|
-
end
|
46
|
-
|
47
|
-
##
|
48
|
-
# Comparison operator
|
49
|
-
#
|
50
|
-
def <=>(other)
|
51
|
-
comp_begin = self.begin <=> other.begin
|
52
|
-
comp_end = self.end <=> other.end
|
53
|
-
# Return nil if begin or end is uncomparable
|
54
|
-
return nil if comp_begin.nil? || comp_end.nil?
|
55
|
-
|
56
|
-
# Compare end if begin is equal
|
57
|
-
return comp_end if comp_begin.zero?
|
58
|
-
|
59
|
-
# Compare begin if end is equal
|
60
|
-
return comp_begin if comp_begin.zero?
|
61
|
-
|
62
|
-
# Compare actual range
|
63
|
-
(self.end - self.begin) <=> (other.end - other.begin)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/spec/configuration_spec.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe MetalArchives::Configuration do
|
4
|
-
describe 'properties' do
|
5
|
-
it 'has the correct properties' do
|
6
|
-
expect(subject).to respond_to :app_name
|
7
|
-
expect(subject).to respond_to :app_name=
|
8
|
-
expect(subject).to respond_to :app_version
|
9
|
-
expect(subject).to respond_to :app_version=
|
10
|
-
expect(subject).to respond_to :app_contact
|
11
|
-
expect(subject).to respond_to :app_contact=
|
12
|
-
expect(subject).to respond_to :endpoint
|
13
|
-
expect(subject).to respond_to :endpoint=
|
14
|
-
expect(subject).to respond_to :default_endpoint
|
15
|
-
expect(subject).to respond_to :middleware
|
16
|
-
expect(subject).to respond_to :middleware=
|
17
|
-
expect(subject).to respond_to :request_rate
|
18
|
-
expect(subject).to respond_to :request_rate=
|
19
|
-
expect(subject).to respond_to :request_timeout
|
20
|
-
expect(subject).to respond_to :request_timeout=
|
21
|
-
expect(subject).to respond_to :logger
|
22
|
-
expect(subject).to respond_to :logger=
|
23
|
-
expect(subject).to respond_to :cache_size
|
24
|
-
expect(subject).to respond_to :cache_size=
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'has default properties' do
|
28
|
-
expect(subject.default_endpoint).to eq 'https://www.metal-archives.com/'
|
29
|
-
expect(subject.logger).not_to be_nil
|
30
|
-
expect(subject.cache_size).to be_an Integer
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'overrides defaults' do
|
34
|
-
subject.endpoint = 'http://my-proxy.com/'
|
35
|
-
logger = Logger.new STDERR
|
36
|
-
subject.logger = logger
|
37
|
-
subject.cache_size = 0
|
38
|
-
|
39
|
-
expect(subject.endpoint).to eq 'http://my-proxy.com/'
|
40
|
-
expect(subject.logger).to be logger
|
41
|
-
expect(subject.cache_size).to eq 0
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'configuration' do
|
46
|
-
after(:each) do
|
47
|
-
# Reset configuration
|
48
|
-
load 'support/metal_archives.rb'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'is invalid without app_name' do
|
52
|
-
proc = -> do
|
53
|
-
MetalArchives.configure do |c|
|
54
|
-
c.app_version = MetalArchives::VERSION
|
55
|
-
c.app_contact = 'user@example.com'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
expect(proc).to raise_error MetalArchives::Errors::InvalidConfigurationError
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'is invalid without app_version' do
|
63
|
-
proc = -> do
|
64
|
-
MetalArchives.configure do |c|
|
65
|
-
c.app_name = 'MetalArchivesGemTestSuite'
|
66
|
-
c.app_contact = 'user@example.com'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
expect(proc).to raise_error MetalArchives::Errors::InvalidConfigurationError
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'is invalid without app_contact' do
|
74
|
-
proc = -> do
|
75
|
-
MetalArchives.configure do |c|
|
76
|
-
c.app_name = 'MetalArchivesGemTestSuite'
|
77
|
-
c.app_version = MetalArchives::VERSION
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
expect(proc).to raise_error MetalArchives::Errors::InvalidConfigurationError
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'is valid' do
|
85
|
-
proc = -> do
|
86
|
-
MetalArchives.configure do |c|
|
87
|
-
c.app_name = 'MetalArchivesGemTestSuite'
|
88
|
-
c.app_version = MetalArchives::VERSION
|
89
|
-
c.app_contact = 'user@example.com'
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
expect(proc).not_to raise_error
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
FactoryGirl.define do
|
4
|
-
factory :artist, :class => MetalArchives::Artist do
|
5
|
-
id { Faker::Number.number [1, 2, 3, 4].sample }
|
6
|
-
name { Faker::Name.name }
|
7
|
-
gender { %i[male female].sample }
|
8
|
-
biography { Faker::Lorem.words(200).join ' ' }
|
9
|
-
trivia { Faker::Lorem.words(200).join ' ' }
|
10
|
-
|
11
|
-
country { ISO3166::Country[Faker::Address.country_code] }
|
12
|
-
location { Faker::Address.city }
|
13
|
-
|
14
|
-
date_of_birth { Faker::Date.birthday 18, 65 }
|
15
|
-
|
16
|
-
links do
|
17
|
-
3.times.collect do
|
18
|
-
{
|
19
|
-
:url => Faker::Internet.url,
|
20
|
-
:type => %i[official unofficial unlisted_bands].sample,
|
21
|
-
:title => Faker::Lorem.words(4).join(' ')
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
trait :has_died do
|
27
|
-
date_of_death { Faker::Date.between date_of_birth, Date.today }
|
28
|
-
cause_of_death { %w(Suicide N/A Accident Cancer Illness Murder).sample }
|
29
|
-
end
|
30
|
-
|
31
|
-
trait :with_aliases do
|
32
|
-
aliases do
|
33
|
-
3.times.collect { Faker::Name.name }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
FactoryGirl.define do
|
4
|
-
factory :band, :class => MetalArchives::Band do
|
5
|
-
id { Faker::Number.number [1, 2, 3, 4].sample }
|
6
|
-
name { Faker::Name.name }
|
7
|
-
status { %i[active split_up on_hold unknown changed_name disputed].sample }
|
8
|
-
|
9
|
-
comment { Faker::Lorem.words(200).join ' ' }
|
10
|
-
|
11
|
-
country { ISO3166::Country[Faker::Address.country_code] }
|
12
|
-
location { Faker::Address.city }
|
13
|
-
|
14
|
-
date_formed { Faker::Date.birthday 0, 50 }
|
15
|
-
date_active { build_list :range }
|
16
|
-
|
17
|
-
label { [build(:label), nil].sample }
|
18
|
-
independent { label.nil? }
|
19
|
-
|
20
|
-
logo { Faker::Internet.url }
|
21
|
-
photo { Faker::Internet.url }
|
22
|
-
|
23
|
-
genres do
|
24
|
-
3.times.collect do
|
25
|
-
"#{%w(Black Death Doom Power Progressive Speed Thrash).sample} Metal"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
lyrical_themes do
|
30
|
-
3.times.collect do
|
31
|
-
['Fantasy', 'Epic battles', 'Tales', 'Myths', 'Legends', 'Feelings', 'Life', 'Eden', 'Glory', 'the Four Elements', 'Metal'].sample
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
similar do
|
36
|
-
4.times.collect do
|
37
|
-
{
|
38
|
-
:band => build(:band),
|
39
|
-
:score => Faker::Number.between(1, 100)
|
40
|
-
}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
links do
|
45
|
-
3.times.collect do
|
46
|
-
{
|
47
|
-
:url => Faker::Internet.url,
|
48
|
-
:type => %i[official unofficial unlisted_bands].sample,
|
49
|
-
:title => Faker::Lorem.words(4).join(' ')
|
50
|
-
}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
trait :with_aliases do
|
55
|
-
aliases do
|
56
|
-
3.times.collect { Faker::Name.name }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/spec/models/artist_spec.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe MetalArchives::Artist do
|
4
|
-
describe 'properties' do
|
5
|
-
it 'Alberto Rionda has properties' do
|
6
|
-
artist = MetalArchives::Artist.find 60908
|
7
|
-
|
8
|
-
expect(artist).to be_instance_of MetalArchives::Artist
|
9
|
-
expect(artist.id).to eq 60908
|
10
|
-
expect(artist.name).to eq 'Alberto Rionda'
|
11
|
-
expect(artist.aliases).to be_empty
|
12
|
-
expect(artist.country).to eq ISO3166::Country['ES']
|
13
|
-
expect(artist.location).to eq 'Oviedo, Asturias'
|
14
|
-
expect(artist.date_of_birth).to eq MetalArchives::NilDate.new(1972, 9, 2)
|
15
|
-
expect(artist.gender).to eq :male
|
16
|
-
expect(artist.biography).to match 'Avalanch'
|
17
|
-
expect(artist.trivia).to match 'Sanctuarium Estudios'
|
18
|
-
expect(artist.photo).to be_instance_of URI::HTTPS
|
19
|
-
expect(artist.photo.path).to eq '/images/6/0/9/0/60908_artist.jpg'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'Lemmy Kilmister has properties' do
|
23
|
-
artist = MetalArchives::Artist.find 260
|
24
|
-
|
25
|
-
expect(artist).to be_instance_of MetalArchives::Artist
|
26
|
-
expect(artist.name).to eq 'Ian Fraser Kilmister'
|
27
|
-
expect(artist.aliases).to include 'Lemmy Kilmister'
|
28
|
-
expect(artist.date_of_death).to eq MetalArchives::NilDate.new(2015, 12, 28)
|
29
|
-
expect(artist.links.length).to eq 5
|
30
|
-
expect(artist.links.count { |l| l[:type] == :official }).to eq 1
|
31
|
-
expect(artist.links.count { |l| l[:type] == :unofficial }).to eq 2
|
32
|
-
expect(artist.links.count { |l| l[:type] == :unlisted_bands }).to eq 2
|
33
|
-
expect(artist.links.select { |l| l[:type] == :official }.first[:url]).to eq 'https://www.facebook.com/OfficialLemmy'
|
34
|
-
expect(artist.links.select { |l| l[:type] == :official }.first[:title]).to eq 'Facebook'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'maps query parameters' do
|
38
|
-
expect(MetalArchives::Parsers::Artist.map_params(:name => 'name')[:query]).to eq 'name'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'uses NilDate' do
|
42
|
-
artist = MetalArchives::Artist.find 35049
|
43
|
-
|
44
|
-
expect(artist.name).to eq 'Johan Johansson'
|
45
|
-
expect(artist.date_of_birth).to be_instance_of MetalArchives::NilDate
|
46
|
-
expect(artist.date_of_birth).to eq MetalArchives::NilDate.new(1975, nil, nil)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'methods' do
|
51
|
-
describe 'find' do
|
52
|
-
it 'finds an artist' do
|
53
|
-
artist = MetalArchives::Artist.find 60908
|
54
|
-
|
55
|
-
expect(artist).to be_instance_of MetalArchives::Artist
|
56
|
-
expect(artist.name).to eq 'Alberto Rionda'
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'lazily loads' do
|
60
|
-
artist = MetalArchives::Artist.find -1
|
61
|
-
|
62
|
-
expect(artist).to be_instance_of MetalArchives::Artist
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe 'find!' do
|
67
|
-
it 'finds an artist' do
|
68
|
-
artist = MetalArchives::Artist.find! 60908
|
69
|
-
|
70
|
-
expect(artist).to be_instance_of MetalArchives::Artist
|
71
|
-
expect(artist.name).to eq 'Alberto Rionda'
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'raises on invalid id' do
|
75
|
-
expect(-> { MetalArchives::Artist.find! -1 }).to raise_error MetalArchives::Errors::APIError
|
76
|
-
expect(-> { MetalArchives::Artist.find! 0 }).to raise_error MetalArchives::Errors::InvalidIDError
|
77
|
-
expect(-> { MetalArchives::Artist.find! nil }).to raise_error MetalArchives::Errors::InvalidIDError
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'find_by' do
|
82
|
-
it 'finds an artist' do
|
83
|
-
artist = MetalArchives::Artist.find_by :name => 'Alberto Rionda'
|
84
|
-
|
85
|
-
expect(artist).to be_instance_of MetalArchives::Artist
|
86
|
-
expect(artist.id).to eq 60908
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'returns nil on invalid id' do
|
90
|
-
artist = MetalArchives::Artist.find_by :name => 'SomeNonExistantName'
|
91
|
-
|
92
|
-
expect(artist).to be_nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'find_by!' do
|
97
|
-
it 'finds an artist' do
|
98
|
-
artist = MetalArchives::Artist.find_by! :name => 'Alberto Rionda'
|
99
|
-
|
100
|
-
expect(artist).to be_instance_of MetalArchives::Artist
|
101
|
-
expect(artist.id).to eq 60908
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'returns nil on invalid id' do
|
105
|
-
artist = MetalArchives::Artist.find_by! :name => 'SomeNonExistantName'
|
106
|
-
|
107
|
-
expect(artist).to be_nil
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe 'search' do
|
112
|
-
it 'returns a collection' do
|
113
|
-
collection = MetalArchives::Artist.search 'Alberto Rionda'
|
114
|
-
|
115
|
-
expect(collection).to be_instance_of MetalArchives::Collection
|
116
|
-
expect(collection.first).to be_instance_of MetalArchives::Artist
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'returns a collection' do
|
120
|
-
expect(MetalArchives::Artist.search('Alberto Rionda').count).to eq 1
|
121
|
-
expect(MetalArchives::Artist.search('Name').count).to eq 10
|
122
|
-
expect(MetalArchives::Artist.search('SomeNonExistantName').count).to eq 0
|
123
|
-
expect(MetalArchives::Artist.search 'SomeNonExistantName').to be_empty
|
124
|
-
expect(MetalArchives::Artist.search('Filip').count).to be > 200
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'returns an empty collection' do
|
128
|
-
expect(MetalArchives::Artist.search 'SomeNoneExistantName').to be_empty
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe 'all' do
|
133
|
-
it 'returns a collection' do
|
134
|
-
expect(MetalArchives::Artist.all).to be_instance_of MetalArchives::Collection
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
data/spec/models/band_spec.rb
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe MetalArchives::Band do
|
4
|
-
describe 'properties' do
|
5
|
-
it 'Pathfinder has properties' do
|
6
|
-
band = MetalArchives::Band.find 122302
|
7
|
-
|
8
|
-
expect(band).to be_instance_of MetalArchives::Band
|
9
|
-
expect(band.name).to eq 'Pathfinder'
|
10
|
-
expect(band.aliases).to be_empty
|
11
|
-
expect(band.country).to eq ISO3166::Country['PL']
|
12
|
-
expect(band.location).to eq 'Poznań'
|
13
|
-
expect(band.date_formed).to eq MetalArchives::NilDate.new(2006)
|
14
|
-
expect(band.date_active).to eq [MetalArchives::Range.new(Date.new(2006), nil)]
|
15
|
-
expect(band.status).to eq :active
|
16
|
-
expect(band.genres).to eq ['Symphonic Power']
|
17
|
-
expect(band.lyrical_themes.sort).to eq ['Fantasy', 'Battles', 'Glory', 'The Four Elements', 'Metal'].sort
|
18
|
-
expect(band.comment).to match 'Pathfinder was founded by'
|
19
|
-
expect(band.logo).to be_instance_of URI::HTTPS
|
20
|
-
expect(band.logo.path).to eq '/images/1/2/2/3/122302_logo.jpg'
|
21
|
-
expect(band.photo).to be_instance_of URI::HTTPS
|
22
|
-
expect(band.photo.path).to eq '/images/1/2/2/3/122302_photo.jpg'
|
23
|
-
expect(band.independent).not_to be true
|
24
|
-
expect(band.similar.length).to eq 19
|
25
|
-
expect(band.links.length).to eq 15
|
26
|
-
expect(band.links.count { |l| l[:type] == :official }).to eq 12
|
27
|
-
expect(band.links.count { |l| l[:type] == :merchandise }).to eq 3
|
28
|
-
expect(band.links.select { |l| l[:type] == :merchandise }.first[:url]).to eq 'http://www.amazon.com/Fifth-Element-Pathfinder/dp/B007MNNCVW'
|
29
|
-
expect(band.links.select { |l| l[:type] == :merchandise }.first[:title]).to eq 'Amazon'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'Lemmy Kilmister has properties' do
|
33
|
-
band = MetalArchives::Band.find 32
|
34
|
-
|
35
|
-
expect(band).to be_instance_of MetalArchives::Band
|
36
|
-
expect(band.name).to eq 'Rhapsody of Fire'
|
37
|
-
expect(band.aliases).to match %w(Thundercross Rhapsody)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'maps status' do
|
41
|
-
expect(MetalArchives::Parsers::Band.send(:map_status, nil)).to eq ''
|
42
|
-
expect(MetalArchives::Parsers::Band.send(:map_status, :active)).to eq 'Active'
|
43
|
-
expect(MetalArchives::Parsers::Band.send(:map_status, :split_up)).to eq 'Split-up'
|
44
|
-
expect(MetalArchives::Parsers::Band.send(:map_status, :on_hold)).to eq 'On hold'
|
45
|
-
expect(MetalArchives::Parsers::Band.send(:map_status, :unknown)).to eq 'Unknown'
|
46
|
-
expect(MetalArchives::Parsers::Band.send(:map_status, :changed_name)).to eq 'Changed name'
|
47
|
-
expect(MetalArchives::Parsers::Band.send(:map_status, :disputed)).to eq 'Disputed'
|
48
|
-
|
49
|
-
expect(-> { MetalArchives::Parsers::Band.send(:map_status, :invalid_status) }).to raise_error MetalArchives::Errors::ParserError
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'methods' do
|
54
|
-
describe 'find' do
|
55
|
-
it 'finds a band' do
|
56
|
-
band = MetalArchives::Band.find 3540361100
|
57
|
-
|
58
|
-
expect(band).not_to be_nil
|
59
|
-
expect(band).to be_instance_of MetalArchives::Band
|
60
|
-
expect(band.id).to eq 3540361100
|
61
|
-
expect(band.name).to eq 'Alquimia'
|
62
|
-
expect(band.country).to eq ISO3166::Country['ES']
|
63
|
-
|
64
|
-
expect(band.logo).to be_instance_of URI::HTTPS
|
65
|
-
expect(band.logo.path).to eq '/images/3/5/4/0/3540361100_logo.gif'
|
66
|
-
|
67
|
-
expect(band.photo).to be_instance_of URI::HTTPS
|
68
|
-
expect(band.photo.path).to eq '/images/3/5/4/0/3540361100_photo.jpg'
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'lazily loads' do
|
72
|
-
band = MetalArchives::Band.find -1
|
73
|
-
|
74
|
-
expect(band).to be_instance_of MetalArchives::Band
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'find!' do
|
79
|
-
it 'finds a band' do
|
80
|
-
band = MetalArchives::Band.find! 3540361100
|
81
|
-
|
82
|
-
expect(band).to be_instance_of MetalArchives::Band
|
83
|
-
expect(band.name).to eq 'Alquimia'
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'raises on invalid id' do
|
87
|
-
expect(-> { MetalArchives::Band.find! -1 }).to raise_error MetalArchives::Errors::APIError
|
88
|
-
expect(-> { MetalArchives::Band.find! 0 }).to raise_error MetalArchives::Errors::InvalidIDError
|
89
|
-
expect(-> { MetalArchives::Band.find! nil }).to raise_error MetalArchives::Errors::InvalidIDError
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe 'find_by' do
|
94
|
-
it 'finds a band' do
|
95
|
-
band = MetalArchives::Band.find_by :name => 'Falconer'
|
96
|
-
|
97
|
-
expect(band).to be_instance_of MetalArchives::Band
|
98
|
-
expect(band.id).to eq 74
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'returns nil on invalid id' do
|
102
|
-
band = MetalArchives::Band.find_by :name => 'SomeNonExistantName'
|
103
|
-
|
104
|
-
expect(band).to be_nil
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe 'find_by!' do
|
109
|
-
it 'finds a band' do
|
110
|
-
band = MetalArchives::Band.find_by! :name => 'Falconer'
|
111
|
-
|
112
|
-
expect(band).to be_instance_of MetalArchives::Band
|
113
|
-
expect(band.id).to eq 74
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'returns nil on invalid id' do
|
117
|
-
band = MetalArchives::Band.find_by! :name => 'SomeNonExistantName'
|
118
|
-
|
119
|
-
expect(band).to be_nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe 'search' do
|
124
|
-
it 'returns a collection' do
|
125
|
-
collection = MetalArchives::Band.search 'Alquimia'
|
126
|
-
|
127
|
-
expect(collection).to be_instance_of MetalArchives::Collection
|
128
|
-
expect(collection.first).to be_instance_of MetalArchives::Band
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'returns an empty collection' do
|
132
|
-
expect(MetalArchives::Band.search 'SomeNoneExistantName').to be_empty
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'searches by name' do
|
136
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia').count).to eq 5
|
137
|
-
expect(MetalArchives::Band.search_by(:name => 'Lost Horizon').count).to eq 3
|
138
|
-
expect(MetalArchives::Band.search_by(:name => 'Lost Horizon', :exact => true).count).to eq 2
|
139
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :genre => 'Melodic Power').count).to eq 2
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'searches by year' do
|
143
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :year => MetalArchives::Range.new(nil, nil)).count).to eq 5
|
144
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2013), nil)).count).to eq 1
|
145
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2008))).count).to eq 1
|
146
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2013))).count).to eq 2
|
147
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :year => MetalArchives::Range.new(nil, Date.new(2013))).count).to eq 5
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'searches by country' do
|
151
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['ES']).count).to eq 1
|
152
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).count).to eq 3
|
153
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).count).to eq 3
|
154
|
-
expect(MetalArchives::Band.search_by(:name => 'Alquimia', :label => 'Mutus Liber').count).to eq 1
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe 'all' do
|
159
|
-
it 'returns a collection' do
|
160
|
-
expect(MetalArchives::Band.all).to be_instance_of MetalArchives::Collection
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|