metal_archives 2.2.0 → 2.2.3
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 +46 -0
- data/.github/workflows/release.yml +69 -0
- data/.gitignore +6 -6
- data/.overcommit.yml +35 -0
- data/.rspec +1 -0
- data/.rubocop.yml +54 -8
- data/.rubocop_todo.yml +92 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +1 -1
- data/LICENSE.md +1 -1
- data/README.md +35 -64
- data/Rakefile +8 -7
- data/bin/console +41 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +14 -0
- data/lib/metal_archives.rb +48 -29
- data/lib/metal_archives/{utils/collection.rb → collection.rb} +0 -0
- data/lib/metal_archives/configuration.rb +9 -33
- data/lib/metal_archives/{error.rb → errors.rb} +0 -0
- data/lib/metal_archives/http_client.rb +13 -8
- data/lib/metal_archives/{utils/lru_cache.rb → lru_cache.rb} +0 -0
- data/lib/metal_archives/middleware/cache_check.rb +2 -4
- data/lib/metal_archives/middleware/encoding.rb +2 -2
- data/lib/metal_archives/middleware/headers.rb +5 -5
- data/lib/metal_archives/middleware/rewrite_endpoint.rb +2 -2
- data/lib/metal_archives/models/artist.rb +40 -24
- data/lib/metal_archives/models/band.rb +47 -29
- data/lib/metal_archives/models/base_model.rb +64 -61
- data/lib/metal_archives/models/label.rb +11 -11
- data/lib/metal_archives/models/release.rb +17 -15
- data/lib/metal_archives/{utils/nil_date.rb → nil_date.rb} +10 -18
- data/lib/metal_archives/parsers/artist.rb +62 -31
- data/lib/metal_archives/parsers/band.rb +97 -74
- data/lib/metal_archives/parsers/label.rb +21 -21
- data/lib/metal_archives/parsers/parser.rb +23 -8
- data/lib/metal_archives/parsers/release.rb +77 -72
- data/lib/metal_archives/{utils/range.rb → range.rb} +5 -2
- data/lib/metal_archives/version.rb +12 -1
- data/metal_archives.env.example +7 -0
- data/metal_archives.gemspec +40 -28
- data/nginx/default.conf +60 -0
- metadata +126 -65
- data/.travis.yml +0 -12
- 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,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
|
@@ -1,219 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
##
|
5
|
-
# Sample model without :id property or :assemble method
|
6
|
-
#
|
7
|
-
class ModelOne < MetalArchives::BaseModel
|
8
|
-
property :property_one
|
9
|
-
end
|
10
|
-
|
11
|
-
##
|
12
|
-
# Sample model without :assemble method
|
13
|
-
#
|
14
|
-
class ModelTwo < MetalArchives::BaseModel
|
15
|
-
property :id
|
16
|
-
property :property_one
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# Sample complete model
|
21
|
-
#
|
22
|
-
class ModelThree < MetalArchives::BaseModel
|
23
|
-
property :id
|
24
|
-
property :property_one
|
25
|
-
|
26
|
-
def assemble
|
27
|
-
{ :property_one => 'Property One' }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
##
|
32
|
-
# Sample complete model
|
33
|
-
#
|
34
|
-
class ModelFour < MetalArchives::BaseModel
|
35
|
-
property :id
|
36
|
-
property :property_one
|
37
|
-
|
38
|
-
def assemble
|
39
|
-
{ :property_one => 'Property One' }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Sample invalid model
|
45
|
-
#
|
46
|
-
class ModelFive < MetalArchives::BaseModel
|
47
|
-
property :id
|
48
|
-
property :property_one
|
49
|
-
|
50
|
-
def assemble
|
51
|
-
raise MetalArchives::Errors::APIError
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
RSpec.describe MetalArchives::BaseModel do
|
56
|
-
it 'requires an :id property' do
|
57
|
-
expect(-> { ModelOne.new(:property_one => 'foo') }).to raise_error MetalArchives::Errors::NotImplementedError
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'requires an :assemble method' do
|
61
|
-
expect(-> { ModelTwo.new(:id => 'foo').property_one }).to raise_error MetalArchives::Errors::NotImplementedError
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'defines methods' do
|
65
|
-
model = ModelTwo.new :id => 'foo'
|
66
|
-
|
67
|
-
expect(model).to respond_to :id
|
68
|
-
expect(model).to respond_to :id=
|
69
|
-
expect(model).to respond_to :id?
|
70
|
-
expect(model).to respond_to :property_one
|
71
|
-
expect(model).to respond_to :property_one=
|
72
|
-
expect(model).to respond_to :property_one?
|
73
|
-
expect(model).not_to respond_to :property_two
|
74
|
-
expect(model).not_to respond_to :property_two=
|
75
|
-
expect(model).not_to respond_to :property_two?
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'returns properties' do
|
79
|
-
model = ModelThree.new :id => 'foo', :property_one => 'bar'
|
80
|
-
|
81
|
-
model.instance_eval { |m| @loaded = true }
|
82
|
-
expect(model.id).to eq 'foo'
|
83
|
-
expect(model.property_one).to eq 'bar'
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'sets properties' do
|
87
|
-
model = ModelThree.new :id => 'foo', :property_one => 'bar'
|
88
|
-
|
89
|
-
model.instance_eval { |m| @loaded = true }
|
90
|
-
model.id = 'baz'
|
91
|
-
model.property_one = 'bat'
|
92
|
-
|
93
|
-
expect(model.id).to eq 'baz'
|
94
|
-
expect(model.property_one).to eq 'bat'
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'checks properties' do
|
98
|
-
model = ModelThree.new :id => 'foo', :property_one => 'bar'
|
99
|
-
model2 = ModelThree.new :id => 'foo'
|
100
|
-
model2.load!
|
101
|
-
model2.property_one = nil
|
102
|
-
|
103
|
-
expect(model.id?).to be true
|
104
|
-
expect(model.property_one?).to be true
|
105
|
-
|
106
|
-
expect(model2.id?).to be true
|
107
|
-
expect(model2.property_one?).to be false
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'calls assemble' do
|
111
|
-
model = ModelThree.new :id => 'foo'
|
112
|
-
|
113
|
-
expect(model.id).to eq 'foo'
|
114
|
-
expect(model.property_one).to eq 'Property One'
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'lazily loads' do
|
118
|
-
model = ModelThree.new :id => 'foo'
|
119
|
-
|
120
|
-
expect(model).to be_instance_variable_defined '@id'
|
121
|
-
expect(model).not_to be_instance_variable_defined '@property_one'
|
122
|
-
|
123
|
-
model.property_one
|
124
|
-
|
125
|
-
expect(model).to be_instance_variable_defined '@id'
|
126
|
-
expect(model).to be_instance_variable_defined '@property_one'
|
127
|
-
expect(model.property_one).to eq 'Property One'
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
it 'implements the load! operation' do
|
132
|
-
model = ModelThree.new :id => 'foo'
|
133
|
-
|
134
|
-
expect(model).to be_instance_variable_defined '@id'
|
135
|
-
expect(model).not_to be_instance_variable_defined '@property_one'
|
136
|
-
|
137
|
-
model.load!
|
138
|
-
|
139
|
-
expect(model).to be_instance_variable_defined '@id'
|
140
|
-
expect(model).to be_instance_variable_defined '@property_one'
|
141
|
-
expect(model.property_one).to eq 'Property One'
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'implements the equal operator' do
|
145
|
-
m1 = ModelThree.new :id => 'id_one'
|
146
|
-
m2 = ModelThree.new :id => 'id_one'
|
147
|
-
m3 = ModelThree.new :id => 'id_two'
|
148
|
-
m4 = ModelFour.new :id => 'id_one'
|
149
|
-
|
150
|
-
expect(m1).to eq m2
|
151
|
-
expect(m2).not_to eq m3
|
152
|
-
expect(m1).not_to eq m3
|
153
|
-
expect(m1).not_to eq m4
|
154
|
-
expect(m2).not_to eq m4
|
155
|
-
end
|
156
|
-
|
157
|
-
describe 'loaded?' do
|
158
|
-
it 'has a :loaded? method' do
|
159
|
-
expect(ModelThree.new).to respond_to :loaded?
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'returns false on lazy load' do
|
163
|
-
m = ModelThree.new :id => 'id_one'
|
164
|
-
|
165
|
-
expect(m).not_to be_loaded
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'returns true on load!' do
|
169
|
-
m = ModelThree.new :id => 'id_one'
|
170
|
-
m.load!
|
171
|
-
|
172
|
-
expect(m).to be_loaded
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe 'cached?' do
|
177
|
-
context 'valid model' do
|
178
|
-
it 'has a :cached? method' do
|
179
|
-
expect(ModelThree.new).to respond_to :cached?
|
180
|
-
end
|
181
|
-
|
182
|
-
it "doesn't cache lazily loaded objects" do
|
183
|
-
m = ModelThree.new :id => 'id_one'
|
184
|
-
|
185
|
-
expect(m).not_to be_loaded
|
186
|
-
expect(m).not_to be_cached
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'caches loaded objects' do
|
190
|
-
m = ModelThree.new :id => 'id_one'
|
191
|
-
m.load!
|
192
|
-
|
193
|
-
expect(m).to be_loaded
|
194
|
-
expect(m).to be_cached
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'invalid model' do
|
199
|
-
it 'has a :cached? method' do
|
200
|
-
expect(ModelFive.new).to respond_to :cached?
|
201
|
-
end
|
202
|
-
|
203
|
-
it "doesn't cache lazily loaded objects" do
|
204
|
-
m = ModelFive.new :id => 'id_one'
|
205
|
-
|
206
|
-
expect(m).not_to be_loaded
|
207
|
-
expect(m).not_to be_cached
|
208
|
-
end
|
209
|
-
|
210
|
-
it "doesn't cache loaded invalid objects" do
|
211
|
-
m = ModelFive.new :id => 'id_one'
|
212
|
-
expect(-> { m.load! }).to raise_error MetalArchives::Errors::APIError
|
213
|
-
|
214
|
-
expect(m).not_to be_loaded
|
215
|
-
expect(m).not_to be_cached
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|