metal_archives 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +59 -7
- data/.rspec +1 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +11 -0
- data/Gemfile +2 -0
- data/{LICENSE → LICENSE.md} +0 -0
- data/README.md +77 -9
- data/Rakefile +5 -3
- data/lib/metal_archives.rb +8 -0
- data/lib/metal_archives/configuration.rb +28 -7
- data/lib/metal_archives/error.rb +37 -30
- data/lib/metal_archives/http_client.rb +21 -42
- data/lib/metal_archives/middleware/headers.rb +38 -0
- data/lib/metal_archives/middleware/rewrite_endpoint.rb +38 -0
- data/lib/metal_archives/models/artist.rb +51 -65
- data/lib/metal_archives/models/band.rb +41 -39
- data/lib/metal_archives/models/base_model.rb +88 -59
- data/lib/metal_archives/models/label.rb +7 -6
- data/lib/metal_archives/parsers/artist.rb +110 -99
- data/lib/metal_archives/parsers/band.rb +168 -156
- data/lib/metal_archives/parsers/label.rb +54 -52
- data/lib/metal_archives/parsers/parser.rb +73 -71
- data/lib/metal_archives/utils/collection.rb +7 -1
- data/lib/metal_archives/utils/lru_cache.rb +11 -4
- data/lib/metal_archives/utils/nil_date.rb +54 -0
- data/lib/metal_archives/utils/range.rb +16 -8
- data/lib/metal_archives/version.rb +3 -1
- data/metal_archives.gemspec +21 -11
- data/spec/configuration_spec.rb +101 -0
- data/spec/factories/artist_factory.rb +37 -0
- data/spec/factories/band_factory.rb +60 -0
- data/spec/factories/nil_date_factory.rb +9 -0
- data/spec/factories/range_factory.rb +8 -0
- data/spec/models/artist_spec.rb +142 -0
- data/spec/models/band_spec.rb +179 -0
- data/spec/models/base_model_spec.rb +217 -0
- data/spec/parser_spec.rb +19 -0
- data/spec/spec_helper.rb +111 -0
- data/spec/support/factory_girl.rb +5 -0
- data/spec/support/metal_archives.rb +26 -0
- data/spec/utils/collection_spec.rb +72 -0
- data/spec/utils/lru_cache_spec.rb +53 -0
- data/spec/utils/nil_date_spec.rb +98 -0
- data/spec/utils/range_spec.rb +62 -0
- metadata +142 -57
- data/test/base_model_test.rb +0 -111
- data/test/configuration_test.rb +0 -57
- data/test/parser_test.rb +0 -37
- data/test/property/artist_property_test.rb +0 -43
- data/test/property/band_property_test.rb +0 -94
- data/test/query/artist_query_test.rb +0 -109
- data/test/query/band_query_test.rb +0 -152
- data/test/test_helper.rb +0 -25
- data/test/utils/collection_test.rb +0 -51
- data/test/utils/lru_cache_test.rb +0 -22
- data/test/utils/range_test.rb +0 -42
data/test/parser_test.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'date'
|
4
|
-
require 'countries'
|
5
|
-
|
6
|
-
require 'metal_archives/parsers/parser.rb'
|
7
|
-
|
8
|
-
class ParserTest < Test::Unit::TestCase
|
9
|
-
def test_parse_country
|
10
|
-
assert_equal ISO3166::Country['US'], MetalArchives::Parsers::Parser.parse_country('United States')
|
11
|
-
assert_equal ISO3166::Country['DE'], MetalArchives::Parsers::Parser.parse_country('Germany')
|
12
|
-
assert_equal ISO3166::Country['BE'], MetalArchives::Parsers::Parser.parse_country('Belgium')
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_parse_genre
|
16
|
-
assert_equal ['Black', 'Death', 'Power'].sort,
|
17
|
-
MetalArchives::Parsers::Parser.parse_genre('Death, Power, Black').sort
|
18
|
-
|
19
|
-
assert_equal ['Black', 'Death', 'Power'].sort,
|
20
|
-
MetalArchives::Parsers::Parser.parse_genre('Death, Power, Black').sort
|
21
|
-
|
22
|
-
assert_equal ['Black', 'Death', 'Heavy', 'Power'].sort,
|
23
|
-
MetalArchives::Parsers::Parser.parse_genre('Death (early), Heavy/Power Metal, Black (later)').sort
|
24
|
-
|
25
|
-
assert_equal ['Death', 'Power'].sort,
|
26
|
-
MetalArchives::Parsers::Parser.parse_genre(' Death , Power Metal, Power, Power').sort
|
27
|
-
|
28
|
-
assert_equal ['Heavy Power', 'Speed Power'].sort,
|
29
|
-
MetalArchives::Parsers::Parser.parse_genre('Heavy/Speed Power Metal').sort
|
30
|
-
|
31
|
-
assert_equal ['Traditional Heavy', 'Traditional Power'].sort,
|
32
|
-
MetalArchives::Parsers::Parser.parse_genre('Traditional Heavy/Power Metal').sort
|
33
|
-
|
34
|
-
assert_equal ['Traditional Heavy', 'Traditional Power', 'Classical Heavy', 'Classical Power'].sort,
|
35
|
-
MetalArchives::Parsers::Parser.parse_genre('Traditional/Classical Heavy/Power Metal').sort
|
36
|
-
end
|
37
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
require 'metal_archives/parsers/band'
|
4
|
-
|
5
|
-
##
|
6
|
-
# Property testing
|
7
|
-
#
|
8
|
-
# If a test fails, please check the online results to make sure it's not
|
9
|
-
# the content itself that has changed.
|
10
|
-
#
|
11
|
-
class ArtistPropertyTest < Test::Unit::TestCase
|
12
|
-
def test_basic_attributes
|
13
|
-
artist = MetalArchives::Artist.find 60908
|
14
|
-
|
15
|
-
assert_instance_of MetalArchives::Artist, artist
|
16
|
-
assert_equal 60908, artist.id
|
17
|
-
assert_equal 'Alberto Rionda', artist.name
|
18
|
-
assert_empty artist.aliases
|
19
|
-
assert_equal ISO3166::Country['ES'], artist.country
|
20
|
-
assert_equal 'Oviedo, Asturias', artist.location
|
21
|
-
assert_equal Date.new(1972, 9, 2), artist.date_of_birth
|
22
|
-
assert_equal :male, artist.gender
|
23
|
-
assert_match 'Avalanch', artist.biography
|
24
|
-
assert_match 'Sanctuarium Estudios', artist.trivia
|
25
|
-
|
26
|
-
artist = MetalArchives::Artist.find 260
|
27
|
-
|
28
|
-
assert_instance_of MetalArchives::Artist, artist
|
29
|
-
assert_equal 'Ian Fraser Kilmister', artist.name
|
30
|
-
assert_equal ['Lemmy Kilmister'], artist.aliases
|
31
|
-
assert_equal Date.new(2015, 12, 28), artist.date_of_death
|
32
|
-
assert_equal 5, artist.links.length
|
33
|
-
assert_equal 1, artist.links.count { |l| l[:type] == :official }
|
34
|
-
assert_equal 2, artist.links.count { |l| l[:type] == :unofficial }
|
35
|
-
assert_equal 1, artist.links.count { |l| l[:type] == :unlisted_bands }
|
36
|
-
assert_equal 'https://www.facebook.com/OfficialLemmy', artist.links.select { |l| l[:type] == :official }.first[:url]
|
37
|
-
assert_equal 'Facebook', artist.links.select { |l| l[:type] == :official }.first[:title]
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_map_params
|
41
|
-
assert_equal 'name', MetalArchives::Parsers::Artist.map_params(:name => 'name')[:query]
|
42
|
-
end
|
43
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
require 'metal_archives/parsers/band'
|
4
|
-
|
5
|
-
##
|
6
|
-
# Property testing
|
7
|
-
#
|
8
|
-
# If a test fails, please check the online results to make sure it's not
|
9
|
-
# the content itself that has changed.
|
10
|
-
#
|
11
|
-
class BandPropertyTest < Test::Unit::TestCase
|
12
|
-
def test_basic_attributes
|
13
|
-
band = MetalArchives::Band.find 122302
|
14
|
-
|
15
|
-
assert_equal 'Pathfinder', band.name
|
16
|
-
assert_empty band.aliases
|
17
|
-
assert_equal ISO3166::Country['PL'], band.country
|
18
|
-
assert_equal 'Poznań', band.location
|
19
|
-
assert_equal Date.new(2006), band.date_formed
|
20
|
-
assert_equal [MetalArchives::Range.new(Date.new(2006), nil)], band.date_active
|
21
|
-
assert_equal :active, band.status
|
22
|
-
assert_equal ['Symphonic Power'], band.genres
|
23
|
-
assert_equal ['Fantasy', 'Battles', 'Glory', 'The Four Elements', 'Metal'].sort, band.lyrical_themes.sort
|
24
|
-
assert_match 'Pathfinder was founded by', band.comment
|
25
|
-
assert_equal 'http://www.metal-archives.com/images/1/2/2/3/122302_logo.jpg', band.logo
|
26
|
-
assert_equal 'http://www.metal-archives.com/images/1/2/2/3/122302_photo.jpg?5400', band.photo
|
27
|
-
assert !band.independent
|
28
|
-
assert_equal 19, band.similar.length
|
29
|
-
assert_equal 15, band.links.length
|
30
|
-
assert_equal 12, band.links.count { |l| l[:type] == :official }
|
31
|
-
assert_equal 3, band.links.count { |l| l[:type] == :merchandise }
|
32
|
-
assert_equal 'http://www.amazon.com/Fifth-Element-Pathfinder/dp/B007MNNCVW', band.links.select { |l| l[:type] == :merchandise }.first[:url]
|
33
|
-
assert_equal 'Amazon', band.links.select { |l| l[:type] == :merchandise }.first[:title]
|
34
|
-
|
35
|
-
|
36
|
-
band = MetalArchives::Band.find 32
|
37
|
-
|
38
|
-
assert_equal 'Rhapsody of Fire', band.name
|
39
|
-
assert_equal ['Thundercross', 'Rhapsody'].sort, band.aliases.sort
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_map_status
|
43
|
-
assert_equal '', MetalArchives::Parsers::Band.send(:map_status, nil)
|
44
|
-
assert_equal 'Active', MetalArchives::Parsers::Band.send(:map_status, :active)
|
45
|
-
assert_equal 'Split-up', MetalArchives::Parsers::Band.send(:map_status, :split_up)
|
46
|
-
assert_equal 'On hold', MetalArchives::Parsers::Band.send(:map_status, :on_hold)
|
47
|
-
assert_equal 'Unknown', MetalArchives::Parsers::Band.send(:map_status, :unknown)
|
48
|
-
assert_equal 'Changed name', MetalArchives::Parsers::Band.send(:map_status, :changed_name)
|
49
|
-
assert_equal 'Disputed', MetalArchives::Parsers::Band.send(:map_status, :disputed)
|
50
|
-
|
51
|
-
assert_raises MetalArchives::Errors::ParserError do
|
52
|
-
MetalArchives::Parsers::Band.send(:map_status, :invalid_status)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_map_params
|
57
|
-
assert_equal 'name', MetalArchives::Parsers::Band.map_params(:name => 'name')[:bandName]
|
58
|
-
|
59
|
-
assert_equal 1, MetalArchives::Parsers::Band.map_params(:exact => true)[:exactBandMatch]
|
60
|
-
assert_equal 1, MetalArchives::Parsers::Band.map_params(:exact => 'somevalue')[:exactBandMatch]
|
61
|
-
assert_equal 0, MetalArchives::Parsers::Band.map_params(:exact => false)[:exactBandMatch]
|
62
|
-
assert_equal 0, MetalArchives::Parsers::Band.map_params(:exact => nil)[:exactBandMatch]
|
63
|
-
|
64
|
-
assert_equal '', MetalArchives::Parsers::Band.map_params({})[:bandName]
|
65
|
-
assert_equal 0, MetalArchives::Parsers::Band.map_params({})[:exactBandMatch]
|
66
|
-
assert_equal 'genre', MetalArchives::Parsers::Band.map_params({ :genre => 'genre'})[:genre]
|
67
|
-
assert_equal '', MetalArchives::Parsers::Band.map_params({})[:genre]
|
68
|
-
|
69
|
-
range = Range.new Date.new(2016), Date.new(2017)
|
70
|
-
assert_equal 2016, MetalArchives::Parsers::Band.map_params({ :year => range })[:yearCreationFrom]
|
71
|
-
assert_equal 2017, MetalArchives::Parsers::Band.map_params({ :year => range })[:yearCreationTo]
|
72
|
-
assert_equal '', MetalArchives::Parsers::Band.map_params({})[:yearCreationFrom]
|
73
|
-
assert_equal '', MetalArchives::Parsers::Band.map_params({})[:yearCreationTo]
|
74
|
-
|
75
|
-
assert_equal 'comment', MetalArchives::Parsers::Band.map_params({ :comment => 'comment' })[:bandNotes]
|
76
|
-
# :status is tested in test_map_status
|
77
|
-
assert_equal 'themes', MetalArchives::Parsers::Band.map_params({ :lyrical_themes => 'themes' })[:themes]
|
78
|
-
assert_equal 'location', MetalArchives::Parsers::Band.map_params({ :location => 'location' })[:location]
|
79
|
-
assert_equal 'label', MetalArchives::Parsers::Band.map_params({ :label => 'label' })[:bandLabelName]
|
80
|
-
assert_equal 1, MetalArchives::Parsers::Band.map_params({ :independent => true })[:indieLabelBand]
|
81
|
-
assert_equal 1, MetalArchives::Parsers::Band.map_params({ :independent => 'some value' })[:indieLabelBand]
|
82
|
-
assert_equal 1, MetalArchives::Parsers::Band.map_params({ :independent => '' })[:indieLabelBand]
|
83
|
-
assert_equal 0, MetalArchives::Parsers::Band.map_params({ :independent => false })[:indieLabelBand]
|
84
|
-
assert_equal 0, MetalArchives::Parsers::Band.map_params({ :independent => nil })[:indieLabelBand]
|
85
|
-
|
86
|
-
country = ISO3166::Country['BE']
|
87
|
-
country2 = ISO3166::Country['NL']
|
88
|
-
assert_equal 'BE', MetalArchives::Parsers::Band.map_params({ :country => country })[:country]
|
89
|
-
assert_equal ['BE', 'NL'], MetalArchives::Parsers::Band.map_params({ :country => [country, country2] })[:country]
|
90
|
-
|
91
|
-
assert_equal 'BE', MetalArchives::Parsers::Band.map_params({ :country => ['BE'] })[:country]
|
92
|
-
assert_equal ['BE', 'NL'], MetalArchives::Parsers::Band.map_params({ :country => ['BE', 'NL'] })[:country]
|
93
|
-
end
|
94
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
##
|
4
|
-
# Query method testing
|
5
|
-
#
|
6
|
-
# If a test fails, please check the online results to make sure it's not
|
7
|
-
# the content itself that has changed.
|
8
|
-
#
|
9
|
-
class ArtistQueryTest < Test::Unit::TestCase
|
10
|
-
def test_find
|
11
|
-
artist = MetalArchives::Artist.find 60908
|
12
|
-
|
13
|
-
assert_not_nil artist
|
14
|
-
assert_instance_of MetalArchives::Artist, artist
|
15
|
-
assert_equal 60908, artist.id
|
16
|
-
assert_equal 'Alberto Rionda', artist.name
|
17
|
-
assert_equal ISO3166::Country['ES'], artist.country
|
18
|
-
|
19
|
-
artist = MetalArchives::Artist.find(999999)
|
20
|
-
|
21
|
-
assert_instance_of MetalArchives::Artist, artist
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_find!
|
25
|
-
artist = MetalArchives::Artist.find! 60908
|
26
|
-
|
27
|
-
assert_not_nil artist
|
28
|
-
assert_instance_of MetalArchives::Artist, artist
|
29
|
-
assert_equal 60908, artist.id
|
30
|
-
assert_equal 'Alberto Rionda', artist.name
|
31
|
-
assert_equal ISO3166::Country['ES'], artist.country
|
32
|
-
|
33
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
34
|
-
MetalArchives::Artist.find! nil
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
38
|
-
MetalArchives::Artist.find! 0
|
39
|
-
end
|
40
|
-
|
41
|
-
assert_raise MetalArchives::Errors::APIError do
|
42
|
-
MetalArchives::Artist.find!(-1)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_find_by
|
47
|
-
artist = MetalArchives::Artist.find_by :name => 'Alberto Rionda'
|
48
|
-
|
49
|
-
assert_not_nil artist
|
50
|
-
assert_instance_of MetalArchives::Artist, artist
|
51
|
-
assert_equal 'Alberto Rionda', artist.name
|
52
|
-
assert_equal 60908, artist.id
|
53
|
-
assert_equal ISO3166::Country['ES'], artist.country
|
54
|
-
|
55
|
-
|
56
|
-
artist = MetalArchives::Artist.find_by :name => 'SomeNonExistantName'
|
57
|
-
|
58
|
-
assert_nil artist
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_find_by!
|
62
|
-
artist = MetalArchives::Artist.find_by! :name => 'Alberto Rionda'
|
63
|
-
|
64
|
-
assert_instance_of MetalArchives::Artist, artist
|
65
|
-
|
66
|
-
artist = MetalArchives::Artist.find_by! :name => 'SomeNonExistantName'
|
67
|
-
|
68
|
-
assert_nil artist
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_search
|
72
|
-
assert_instance_of MetalArchives::Collection, MetalArchives::Artist.search('Alberto Rionda')
|
73
|
-
assert_equal 1, MetalArchives::Artist.search('Alberto Rionda').count
|
74
|
-
assert_equal 9, MetalArchives::Artist.search('Name').count
|
75
|
-
assert_equal 0, MetalArchives::Artist.search('SomeNonExistantName').count
|
76
|
-
assert_equal 296, MetalArchives::Artist.search('Filip').count
|
77
|
-
|
78
|
-
assert !MetalArchives::Artist.search('SomeNonExistantName').any?
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_all
|
82
|
-
assert_instance_of MetalArchives::Collection, MetalArchives::Artist.all
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_errors
|
86
|
-
assert_nothing_raised do
|
87
|
-
MetalArchives::Artist.new :id => nil
|
88
|
-
MetalArchives::Artist.new :id => 0
|
89
|
-
MetalArchives::Artist.new :id => -1
|
90
|
-
MetalArchives::Artist.find_by :name => 'SomeNonExistantName'
|
91
|
-
MetalArchives::Artist.search 'SomeNonExistantName'
|
92
|
-
end
|
93
|
-
|
94
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
95
|
-
MetalArchives::Artist.new(:id => nil).send :assemble
|
96
|
-
end
|
97
|
-
|
98
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
99
|
-
MetalArchives::Artist.new(:id => 0).send :assemble
|
100
|
-
end
|
101
|
-
|
102
|
-
assert_raise MetalArchives::Errors::APIError do
|
103
|
-
MetalArchives::Artist.new(:id => -1).send :assemble
|
104
|
-
end
|
105
|
-
|
106
|
-
assert_nil MetalArchives::Artist.find_by :name => 'SomeNonExistantName'
|
107
|
-
assert !MetalArchives::Artist.search('SomeNonExistantName').any?
|
108
|
-
end
|
109
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
##
|
4
|
-
# Query method testing
|
5
|
-
#
|
6
|
-
# If a test fails, please check the online results to make sure it's not
|
7
|
-
# the content itself that has changed.
|
8
|
-
#
|
9
|
-
class BandQueryTest < Test::Unit::TestCase
|
10
|
-
def test_find
|
11
|
-
band = MetalArchives::Band.find 3540361100
|
12
|
-
|
13
|
-
assert_not_nil band
|
14
|
-
assert_instance_of MetalArchives::Band, band
|
15
|
-
assert_equal 3540361100, band.id
|
16
|
-
assert_equal 'Alquimia', band.name
|
17
|
-
assert_equal ISO3166::Country['ES'], band.country
|
18
|
-
|
19
|
-
assert_match 'http', band.logo
|
20
|
-
assert_match 'http', band.photo
|
21
|
-
|
22
|
-
band = MetalArchives::Band.find(2)
|
23
|
-
|
24
|
-
assert_instance_of MetalArchives::Band, band
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_find!
|
28
|
-
band = MetalArchives::Band.find! 3540361100
|
29
|
-
|
30
|
-
assert_not_nil band
|
31
|
-
assert_instance_of MetalArchives::Band, band
|
32
|
-
assert_equal 3540361100, band.id
|
33
|
-
assert_equal 'Alquimia', band.name
|
34
|
-
assert_equal ISO3166::Country['ES'], band.country
|
35
|
-
|
36
|
-
assert_match 'http', band.logo
|
37
|
-
assert_match 'http', band.photo
|
38
|
-
|
39
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
40
|
-
MetalArchives::Band.find! nil
|
41
|
-
end
|
42
|
-
|
43
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
44
|
-
MetalArchives::Band.find! 0
|
45
|
-
end
|
46
|
-
|
47
|
-
assert_raise MetalArchives::Errors::APIError do
|
48
|
-
MetalArchives::Band.find!(-1)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_find_by
|
53
|
-
band = MetalArchives::Band.find_by :name => 'Falconer'
|
54
|
-
|
55
|
-
assert_not_nil band
|
56
|
-
assert_instance_of MetalArchives::Band, band
|
57
|
-
assert_equal 'Falconer', band.name
|
58
|
-
assert_equal 74, band.id
|
59
|
-
assert_equal ISO3166::Country['SE'], band.country
|
60
|
-
|
61
|
-
|
62
|
-
band = MetalArchives::Band.find_by :name => 'SomeNonExistantName'
|
63
|
-
|
64
|
-
assert_nil band
|
65
|
-
|
66
|
-
|
67
|
-
band = MetalArchives::Band.find_by(:name => 'Alquimia', :country => ISO3166::Country['ES'])
|
68
|
-
|
69
|
-
assert_not_nil band
|
70
|
-
assert_instance_of MetalArchives::Band, band
|
71
|
-
assert_equal 3540361100, band.id
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_find_by!
|
75
|
-
band = MetalArchives::Band.find_by! :name => 'Falconer'
|
76
|
-
|
77
|
-
assert_instance_of MetalArchives::Band, band
|
78
|
-
|
79
|
-
band = MetalArchives::Band.find_by! :name => 'SomeNonExistantName'
|
80
|
-
|
81
|
-
assert_nil band
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_search_by
|
85
|
-
assert_instance_of MetalArchives::Collection, MetalArchives::Band.search_by(:name => 'Alquimia')
|
86
|
-
|
87
|
-
assert_equal 5, MetalArchives::Band.search_by(:name => 'Alquimia').count
|
88
|
-
assert_equal 3, MetalArchives::Band.search_by(:name => 'Lost Horizon').count
|
89
|
-
assert_equal 2, MetalArchives::Band.search_by(:name => 'Lost Horizon', :exact => true).count
|
90
|
-
assert_equal 2, MetalArchives::Band.search_by(:name => 'Alquimia', :genre => 'Melodic Power').count
|
91
|
-
|
92
|
-
|
93
|
-
countries = MetalArchives::Band.search('Alquimia').map { |a| a.country }.sort
|
94
|
-
|
95
|
-
assert_equal 5, countries.size
|
96
|
-
assert countries.include? ISO3166::Country['AR']
|
97
|
-
assert countries.include? ISO3166::Country['ES']
|
98
|
-
assert countries.include? ISO3166::Country['CL']
|
99
|
-
|
100
|
-
assert_equal 5, MetalArchives::Band.search_by(
|
101
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(nil, nil)).count
|
102
|
-
assert_equal 1, MetalArchives::Band.search_by(
|
103
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2013), nil)).count
|
104
|
-
assert_equal 1, MetalArchives::Band.search_by(
|
105
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2008))).count
|
106
|
-
assert_equal 2, MetalArchives::Band.search_by(
|
107
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2013))).count
|
108
|
-
assert_equal 5, MetalArchives::Band.search_by(
|
109
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(nil, Date.new(2013))).count
|
110
|
-
|
111
|
-
assert_equal 1, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['ES']).count
|
112
|
-
assert_equal 3, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).count
|
113
|
-
assert_equal 3, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).count
|
114
|
-
assert_equal 1, MetalArchives::Band.search_by(:name => 'Alquimia', :label => 'Mutus Liber').count
|
115
|
-
|
116
|
-
assert_equal 0, MetalArchives::Band.search_by(:name => 'SomeNonExistantName').count
|
117
|
-
assert !MetalArchives::Band.search_by(:name => 'SomeNonExistantName').any?
|
118
|
-
|
119
|
-
assert_equal 279, MetalArchives::Band.search_by(:country => ISO3166::Country['CN']).count
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_all
|
123
|
-
assert_instance_of MetalArchives::Collection, MetalArchives::Band.all
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_errors
|
127
|
-
assert_nothing_raised do
|
128
|
-
MetalArchives::Band.new :id => nil
|
129
|
-
MetalArchives::Band.new :id => 0
|
130
|
-
MetalArchives::Band.new :id => -1
|
131
|
-
MetalArchives::Band.find_by :name => 'SomeNonExistantName'
|
132
|
-
MetalArchives::Band.search_by :name => 'SomeNonExistantName'
|
133
|
-
MetalArchives::Band.search 'SomeNonExistantName'
|
134
|
-
end
|
135
|
-
|
136
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
137
|
-
MetalArchives::Band.new(:id => nil).send :assemble
|
138
|
-
end
|
139
|
-
|
140
|
-
assert_raise MetalArchives::Errors::InvalidIDError do
|
141
|
-
MetalArchives::Band.new(:id => 0).send :assemble
|
142
|
-
end
|
143
|
-
|
144
|
-
assert_raise MetalArchives::Errors::APIError do
|
145
|
-
MetalArchives::Band.new(:id => -1).send :assemble
|
146
|
-
end
|
147
|
-
|
148
|
-
assert_nil MetalArchives::Band.find_by :name => 'SomeNonExistantName'
|
149
|
-
assert !MetalArchives::Band.search_by(:name => 'SomeNonExistantName').any?
|
150
|
-
assert !MetalArchives::Band.search('SomeNonExistantName').any?
|
151
|
-
end
|
152
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
require 'metal_archives'
|
5
|
-
|
6
|
-
# Configuration
|
7
|
-
puts "Debug log is written to /tmp/test-#{Process.pid}.log"
|
8
|
-
logger = Logger.new File.open('/tmp/test-#{Process.pid}.log', 'a')
|
9
|
-
logger.level = Logger::DEBUG
|
10
|
-
|
11
|
-
MetalArchives.configure do |c|
|
12
|
-
c.app_name = 'MetalArchivesGemTestSuite'
|
13
|
-
c.app_version = MetalArchives::VERSION
|
14
|
-
c.app_contact = `git config user.email`.chomp || 'user@example.com'
|
15
|
-
|
16
|
-
# Custom cache size per object class (optional, overrides defaults)
|
17
|
-
c.cache_size = 1
|
18
|
-
|
19
|
-
# Request throttling (optional, overrides defaults)
|
20
|
-
c.request_rate = 1
|
21
|
-
c.request_timeout = 3
|
22
|
-
|
23
|
-
# Custom logger (optional)
|
24
|
-
c.logger = logger
|
25
|
-
end
|