rbrainz 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data/CHANGES +31 -0
  2. data/LICENSE +1 -1
  3. data/README +3 -2
  4. data/Rakefile +40 -22
  5. data/TODO +6 -23
  6. data/doc/README.rdoc +50 -21
  7. data/examples/getartist.rb +6 -4
  8. data/examples/getuser.rb +30 -0
  9. data/examples/searchartists.rb +35 -0
  10. data/lib/rbrainz.rb +12 -7
  11. data/lib/rbrainz/core_ext.rb +8 -0
  12. data/lib/rbrainz/core_ext/mbid.rb +30 -0
  13. data/lib/rbrainz/core_ext/net_http_digest.rb +52 -0
  14. data/lib/rbrainz/core_ext/range.rb +28 -0
  15. data/lib/rbrainz/core_ext/range/equality.rb +232 -0
  16. data/lib/rbrainz/data/countrynames.rb +7 -5
  17. data/lib/rbrainz/data/languagenames.rb +8 -5
  18. data/lib/rbrainz/data/releasetypenames.rb +34 -0
  19. data/lib/rbrainz/data/scriptnames.rb +8 -5
  20. data/lib/rbrainz/model.rb +27 -35
  21. data/lib/rbrainz/model/alias.rb +31 -7
  22. data/lib/rbrainz/model/artist.rb +30 -41
  23. data/lib/rbrainz/model/collection.rb +102 -0
  24. data/lib/rbrainz/model/default_factory.rb +78 -0
  25. data/lib/rbrainz/model/disc.rb +45 -8
  26. data/lib/rbrainz/model/entity.rb +122 -53
  27. data/lib/rbrainz/model/incomplete_date.rb +31 -47
  28. data/lib/rbrainz/model/individual.rb +103 -0
  29. data/lib/rbrainz/model/label.rb +42 -33
  30. data/lib/rbrainz/model/mbid.rb +111 -40
  31. data/lib/rbrainz/model/relation.rb +78 -14
  32. data/lib/rbrainz/model/release.rb +119 -31
  33. data/lib/rbrainz/model/release_event.rb +38 -9
  34. data/lib/rbrainz/model/scored_collection.rb +99 -0
  35. data/lib/rbrainz/model/tag.rb +39 -0
  36. data/lib/rbrainz/model/track.rb +37 -13
  37. data/lib/rbrainz/model/user.rb +48 -0
  38. data/lib/rbrainz/utils.rb +9 -0
  39. data/lib/rbrainz/utils/data.rb +78 -0
  40. data/lib/rbrainz/utils/helper.rb +22 -0
  41. data/lib/rbrainz/version.rb +15 -0
  42. data/lib/rbrainz/webservice.rb +32 -6
  43. data/lib/rbrainz/webservice/filter.rb +124 -47
  44. data/lib/rbrainz/webservice/includes.rb +49 -10
  45. data/lib/rbrainz/webservice/mbxml.rb +228 -173
  46. data/lib/rbrainz/webservice/query.rb +312 -25
  47. data/lib/rbrainz/webservice/webservice.rb +164 -27
  48. data/test/lib/mock_webservice.rb +53 -0
  49. data/test/lib/test_entity.rb +27 -8
  50. data/test/lib/test_factory.rb +47 -0
  51. data/test/lib/testing_helper.rb +7 -5
  52. data/test/test-data/invalid/artist/tags_1.xml +6 -0
  53. data/test/test-data/valid/artist/Tchaikovsky-2.xml +12 -0
  54. data/test/test-data/valid/label/Atlantic_Records_2.xml +3 -0
  55. data/test/test-data/valid/label/Atlantic_Records_3.xml +11 -0
  56. data/test/test-data/valid/release/Highway_61_Revisited_2.xml +12 -0
  57. data/test/test-data/valid/track/Silent_All_These_Years_6.xml +8 -0
  58. data/test/test_alias.rb +13 -7
  59. data/test/test_artist.rb +26 -4
  60. data/test/test_artist_filter.rb +11 -6
  61. data/test/test_artist_includes.rb +11 -6
  62. data/test/test_collection.rb +66 -0
  63. data/test/test_default_factory.rb +75 -0
  64. data/test/test_disc.rb +9 -4
  65. data/test/test_incomplete_date.rb +21 -14
  66. data/test/test_label.rb +56 -18
  67. data/test/test_label_filter.rb +10 -5
  68. data/test/test_label_includes.rb +11 -6
  69. data/test/test_mbid.rb +34 -19
  70. data/test/test_mbxml.rb +242 -72
  71. data/test/test_query.rb +92 -7
  72. data/test/test_range_equality.rb +144 -0
  73. data/test/test_relation.rb +18 -7
  74. data/test/test_release.rb +15 -4
  75. data/test/test_release_event.rb +16 -4
  76. data/test/test_release_filter.rb +11 -5
  77. data/test/test_release_includes.rb +11 -6
  78. data/test/test_scored_collection.rb +86 -0
  79. data/test/test_tag.rb +39 -0
  80. data/test/test_track.rb +15 -4
  81. data/test/test_track_filter.rb +11 -5
  82. data/test/test_track_includes.rb +11 -6
  83. data/test/test_utils.rb +41 -0
  84. data/test/test_webservice.rb +16 -17
  85. metadata +93 -57
@@ -0,0 +1,53 @@
1
+ # $Id: mock_webservice.rb 147 2007-07-19 17:10:26Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
7
+
8
+ require 'rbrainz/webservice/webservice'
9
+
10
+ class MockWebservice < MusicBrainz::Webservice::IWebservice
11
+
12
+ DATA_PATH = 'test/test-data/'
13
+
14
+ def get(entity_type, options = {:id => nil, :include => nil, :filter => nil, :version => 1})
15
+ case entity_type
16
+ when :artist
17
+ if options[:id]
18
+ case options[:id]
19
+ when '00000000-0000-0000-0000-000000000000'
20
+ file = 'invalid/artist/basic_1.xml'
21
+ when '11111111-1111-1111-1111-111111111111'
22
+ file = 'valid/artist/empty_1.xml'
23
+ else
24
+ file = 'valid/artist/Tori_Amos_1.xml'
25
+ end
26
+ else
27
+ file = 'valid/artist/search_result_1.xml'
28
+ end
29
+ when :release
30
+ if options[:id]
31
+ file = 'valid/release/Under_the_Pink_1.xml'
32
+ else
33
+ file = 'valid/release/search_result_1.xml'
34
+ end
35
+ when :track
36
+ if options[:id]
37
+ file = 'valid/track/Silent_All_These_Years_1.xml'
38
+ else
39
+ file = 'valid/track/search_result_1.xml'
40
+ end
41
+ when :label
42
+ if options[:id]
43
+ file = 'valid/label/Atlantic_Records_1.xml'
44
+ else
45
+ file = 'valid/label/search_result_1.xml'
46
+ end
47
+ when :user
48
+ file = 'valid/user/User_1.xml'
49
+ end
50
+ return File.read(DATA_PATH + file)
51
+ end
52
+
53
+ end
@@ -1,7 +1,9 @@
1
- # $Id: test_entity.rb 29 2007-05-29 02:03:36Z phw $
2
- # Copyright (c) 2007, Philipp Wolfer
3
- # All rights reserved.
4
- # See LICENSE for permissions.
1
+ # $Id: test_entity.rb 118 2007-07-11 22:46:58Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
5
7
 
6
8
  require 'test/unit'
7
9
  require 'rbrainz/model'
@@ -15,7 +17,7 @@ module TestEntity
15
17
 
16
18
  def test_valid_mbid
17
19
  entity = @tested_class.new
18
- valid_mbid = Model::MBID.from_uuid(@tested_class.entity_type, '9d30e408-1559-448b-b491-2f8de1583ccf')
20
+ valid_mbid = Model::MBID.parse('9d30e408-1559-448b-b491-2f8de1583ccf', @tested_class.entity_type )
19
21
 
20
22
  assert_equal nil, entity.id
21
23
  assert_nothing_raised {entity.id = valid_mbid}
@@ -24,7 +26,7 @@ module TestEntity
24
26
 
25
27
  def test_valid_mbid_from_uuid
26
28
  entity = @tested_class.new
27
- valid_mbid = Model::MBID.from_uuid(@tested_class.entity_type, '9d30e408-1559-448b-b491-2f8de1583ccf')
29
+ valid_mbid = Model::MBID.parse('9d30e408-1559-448b-b491-2f8de1583ccf', @tested_class.entity_type )
28
30
 
29
31
  assert_equal nil, entity.id
30
32
  assert_nothing_raised {entity.id = valid_mbid.uuid}
@@ -33,7 +35,7 @@ module TestEntity
33
35
 
34
36
  def test_valid_mbid_from_uri
35
37
  entity = @tested_class.new
36
- valid_mbid = Model::MBID.from_uuid(@tested_class.entity_type, '9d30e408-1559-448b-b491-2f8de1583ccf')
38
+ valid_mbid = Model::MBID.parse( '9d30e408-1559-448b-b491-2f8de1583ccf', @tested_class.entity_type )
37
39
 
38
40
  assert_equal nil, entity.id
39
41
  assert_nothing_raised {entity.id = valid_mbid.to_s}
@@ -43,7 +45,7 @@ module TestEntity
43
45
  def test_invalid_mbid_entity_type_not_matching
44
46
  entity = @tested_class.new
45
47
  @invalid_entity_types.each {|type|
46
- invalid_mbid = Model::MBID.from_uuid(type, '9d30e408-1559-448b-b491-2f8de1583ccf')
48
+ invalid_mbid = Model::MBID.parse( '9d30e408-1559-448b-b491-2f8de1583ccf', type )
47
49
  assert_raise(Model::EntityTypeNotMatchingError) {entity.id = invalid_mbid}
48
50
  assert_raise(Model::EntityTypeNotMatchingError) {entity.id = invalid_mbid.to_s}
49
51
  }
@@ -117,4 +119,21 @@ module TestEntity
117
119
  }
118
120
  end
119
121
 
122
+ def test_tags
123
+ entity = @tested_class.new
124
+ tag1 = Model::Tag.new('doom metal')
125
+ tag2 = Model::Tag.new
126
+
127
+ assert_equal 0, entity.tags.size
128
+ assert_nothing_raised {entity.tags << tag1}
129
+ assert_equal 1, entity.tags.size
130
+ assert_nothing_raised {entity.tags << tag2}
131
+ assert_equal 2, entity.tags.size
132
+
133
+ assert_nothing_raised {entity.tags.delete tag2}
134
+ assert_equal 1, entity.tags.size
135
+ assert_nothing_raised {entity.tags.delete tag1}
136
+ assert_equal 0, entity.tags.size
137
+ end
138
+
120
139
  end
@@ -0,0 +1,47 @@
1
+ # $Id: test_factory.rb 140 2007-07-17 13:27:54Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
7
+
8
+ class MyArtist < Model::Artist
9
+ end
10
+
11
+ class MyLabel < Model::Label
12
+ end
13
+
14
+ class MyRelease < Model::Release
15
+ end
16
+
17
+ class MyTrack < Model::Track
18
+ end
19
+
20
+ class MyAlias < Model::Alias
21
+ end
22
+
23
+ # An alternative model factory for testing purposes.
24
+ class MyFactory < Model::DefaultFactory
25
+
26
+ def new_artist
27
+ MyArtist.new
28
+ end
29
+
30
+ def new_label
31
+ MyLabel.new
32
+ end
33
+
34
+ def new_release
35
+ MyRelease.new
36
+ end
37
+
38
+ def new_track
39
+ MyTrack.new
40
+ end
41
+
42
+ def new_alias
43
+ MyAlias.new
44
+ end
45
+
46
+ end
47
+
@@ -1,9 +1,11 @@
1
- # $Id: testing_helper.rb 27 2007-05-28 23:15:21Z phw $
2
- # Copyright (c) 2007, Philipp Wolfer
3
- # All rights reserved.
4
- # See LICENSE for permissions.
5
-
1
+ # $Id: testing_helper.rb 78 2007-06-04 19:47:11Z phw $
2
+ #
6
3
  # Usefull helper methods which are used in different test classes.
4
+ #
5
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
7
+ # License:: RBrainz is free software distributed under a BSD style license.
8
+ # See LICENSE[file:../LICENSE.html] for permissions.
7
9
 
8
10
  # Converts a query string into a hash.
9
11
  def query_string_to_hash query_string
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#">
3
+ <artist>
4
+ <tag-list><tag count="-1">foo</tag></tag-list>
5
+ </artist>
6
+ </metadata>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#">
3
+ <artist id="9ddd7abc-9e1b-471d-8031-583bc6bc8be9" type="Person">
4
+ <name>Пётр Ильич Чайковский</name>
5
+ <tag-list>
6
+ <tag count="100">classical</tag>
7
+ <tag count="60">russian</tag>
8
+ <tag count="40">romantic era</tag>
9
+ <tag count="120">composer</tag>
10
+ </tag-list>
11
+ </artist>
12
+ </metadata>
@@ -7,5 +7,8 @@
7
7
  <disambiguation>fake</disambiguation>
8
8
  <country>US</country>
9
9
  <life-span begin="1947" end="2047"/>
10
+ <alias-list>
11
+ <alias>Atlantic Rec.</alias>
12
+ </alias-list>
10
13
  </label>
11
14
  </metadata>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#">
3
+ <label id="50c384a2-0b44-401b-b893-8181173339c7" type="OriginalProduction">
4
+ <name>Atlantic Records</name>
5
+ <tag-list>
6
+ <tag>american</tag>
7
+ <tag>jazz</tag>
8
+ <tag>blues</tag>
9
+ </tag-list>
10
+ </label>
11
+ </metadata>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#">
3
+ <release id="d61a2bd9-81ac-4023-bd22-1c884d4a176c" type="Album Official">
4
+ <title>Highway 61 Revisited</title>
5
+ <tag-list>
6
+ <tag count="100">rock</tag>
7
+ <tag count="40">blues rock</tag>
8
+ <tag count="40">folk rock</tag>
9
+ <tag count="4">dylan</tag>
10
+ </tag-list>
11
+ </release>
12
+ </metadata>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#">
3
+ <track id="d6118046-407d-4e06-a1ba-49c399a4c42f">
4
+ <title>Silent All These Years</title>
5
+ <duration>253466</duration>
6
+ <tag-list></tag-list>
7
+ </track>
8
+ </metadata>
data/test/test_alias.rb CHANGED
@@ -1,7 +1,9 @@
1
- # $Id: test_alias.rb 27 2007-05-28 23:15:21Z phw $
2
- # Copyright (c) 2007, Philipp Wolfer
3
- # All rights reserved.
4
- # See LICENSE for permissions.
1
+ # $Id: test_alias.rb 139 2007-07-17 10:02:30Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
5
7
 
6
8
  require 'test/unit'
7
9
  require 'rbrainz/model'
@@ -18,6 +20,10 @@ class TestAlias < Test::Unit::TestCase
18
20
 
19
21
  def test_new_alias
20
22
  assert_nothing_raised {Model::Alias.new}
23
+ alias_ = Model::Alias.new('Dark Tranquility', Model::NS_MMD_1 + 'Misspelling', 'Latn')
24
+ assert_equal 'Dark Tranquility', alias_.name
25
+ assert_equal Model::NS_MMD_1 + 'Misspelling', alias_.type
26
+ alias_.script = 'Latn'
21
27
  end
22
28
 
23
29
  def test_name
@@ -28,8 +34,8 @@ class TestAlias < Test::Unit::TestCase
28
34
 
29
35
  def test_type
30
36
  alias_ = Model::Alias.new
31
- alias_.type = 'Misspelling'
32
- assert_equal 'Misspelling', alias_.type
37
+ alias_.type = Model::NS_MMD_1 + 'Misspelling'
38
+ assert_equal Model::NS_MMD_1 + 'Misspelling', alias_.type
33
39
  end
34
40
 
35
41
  def test_script
@@ -42,7 +48,7 @@ class TestAlias < Test::Unit::TestCase
42
48
  alias_ = Model::Alias.new
43
49
  assert_equal '', alias_.to_s
44
50
  alias_.name = 'Dark Tranquility'
45
- alias_.type = 'Misspelling'
51
+ alias_.type = Model::NS_MMD_1 + 'Misspelling'
46
52
  alias_.script = 'Latn'
47
53
  assert_equal 'Dark Tranquility', alias_.to_s
48
54
  end
data/test/test_artist.rb CHANGED
@@ -1,7 +1,9 @@
1
- # $Id: test_artist.rb 30 2007-05-29 02:12:33Z phw $
2
- # Copyright (c) 2007, Philipp Wolfer
3
- # All rights reserved.
4
- # See LICENSE for permissions.
1
+ # $Id: test_artist.rb 138 2007-07-17 09:05:01Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
5
7
 
6
8
  require 'test_entity'
7
9
 
@@ -25,6 +27,18 @@ class TestArtist < Test::Unit::TestCase
25
27
  artist = nil
26
28
  assert_nothing_raised {artist = Model::Artist.new}
27
29
  assert artist.is_a?(Model::Entity)
30
+
31
+ mbid = Model::MBID.new('9d30e408-1559-448b-b491-2f8de1583ccf', artist.entity_type)
32
+ assert_nothing_raised {artist = Model::Artist.new(
33
+ mbid,
34
+ Model::Artist::TYPE_GROUP,
35
+ 'The White Stripes',
36
+ 'White Stripes, The'
37
+ )}
38
+ assert_equal mbid, artist.id
39
+ assert_equal Model::Artist::TYPE_GROUP, artist.type
40
+ assert_equal 'The White Stripes', artist.name
41
+ assert_equal 'White Stripes, The', artist.sort_name
28
42
  end
29
43
 
30
44
  def test_name
@@ -48,6 +62,14 @@ class TestArtist < Test::Unit::TestCase
48
62
  assert_equal 'Disambiguation comment', artist.disambiguation
49
63
  end
50
64
 
65
+ def test_unique_name
66
+ artist = Model::Artist.new
67
+ artist.name = 'Paradise Lost'
68
+ artist.disambiguation = 'British metal / hard rock band'
69
+ assert_equal 'Paradise Lost (British metal / hard rock band)', artist.unique_name
70
+ assert_equal 'Paradise Lost (British metal / hard rock band)', artist.to_s
71
+ end
72
+
51
73
  def test_type
52
74
  artist = Model::Artist.new
53
75
  assert artist.type.nil?
@@ -1,7 +1,9 @@
1
- # $Id: test_artist_filter.rb 27 2007-05-28 23:15:21Z phw $
2
- # Copyright (c) 2007, Philipp Wolfer
3
- # All rights reserved.
4
- # See LICENSE for permissions.
1
+ # $Id: test_artist_filter.rb 121 2007-07-12 08:56:19Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
5
7
 
6
8
  require 'test/unit'
7
9
  require 'testing_helper'
@@ -12,9 +14,10 @@ include MusicBrainz
12
14
  class TestArtistFilter < Test::Unit::TestCase
13
15
 
14
16
  def setup
15
- @filter_hash = {:name => 'Tori Amos', :limit => 10}
17
+ @filter_hash = {:name => 'Tori Amos', :limit => 10, :offset => 20,
18
+ :query => 'alias:Torie Amos AND artype:1'}
16
19
  end
17
-
20
+
18
21
  def teardown
19
22
  end
20
23
 
@@ -26,6 +29,8 @@ class TestArtistFilter < Test::Unit::TestCase
26
29
  result_hash = query_string_to_hash filter_string
27
30
  assert_equal @filter_hash[:name], result_hash['name'], filter_string
28
31
  assert_equal @filter_hash[:limit].to_s, result_hash['limit'], filter_string
32
+ assert_equal @filter_hash[:offset].to_s, result_hash['offset'], filter_string
33
+ assert_equal @filter_hash[:query].to_s, result_hash['query'], filter_string
29
34
  end
30
35
 
31
36
  def test_empty_filter
@@ -1,7 +1,9 @@
1
- # $Id: test_artist_includes.rb 27 2007-05-28 23:15:21Z phw $
2
- # Copyright (c) 2007, Philipp Wolfer
3
- # All rights reserved.
4
- # See LICENSE for permissions.
1
+ # $Id: test_artist_includes.rb 118 2007-07-11 22:46:58Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
5
7
 
6
8
  require 'test/unit'
7
9
  require 'rbrainz'
@@ -25,7 +27,8 @@ class TestArtistIncludes < Test::Unit::TestCase
25
27
  :label_rels => true,
26
28
  :url_rels => true,
27
29
  :releases => ['Album', 'Official'],
28
- :va_releases => ['Album', 'Official']
30
+ :va_releases => ['Album', 'Official'],
31
+ :tags => true
29
32
  )
30
33
  result_string = includes.to_s
31
34
  assert_equal 'inc=', result_string[0..3]
@@ -41,6 +44,7 @@ class TestArtistIncludes < Test::Unit::TestCase
41
44
  assert result_array.include?('sa-Official')
42
45
  assert result_array.include?('va-Album')
43
46
  assert result_array.include?('va-Official')
47
+ assert result_array.include?('tags')
44
48
  end
45
49
 
46
50
  def test_empty_includes
@@ -52,7 +56,8 @@ class TestArtistIncludes < Test::Unit::TestCase
52
56
  :label_rels => false,
53
57
  :url_rels => false,
54
58
  :releases => [],
55
- :va_releases => []
59
+ :va_releases => [],
60
+ :tags => false
56
61
  )
57
62
  assert_equal '', includes.to_s
58
63
 
@@ -0,0 +1,66 @@
1
+ # $Id: test_collection.rb 117 2007-07-11 21:40:05Z phw $
2
+ #
3
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
5
+ # License:: RBrainz is free software distributed under a BSD style license.
6
+ # See LICENSE[file:../LICENSE.html] for permissions.
7
+
8
+ require 'test/unit'
9
+ require 'rbrainz'
10
+ include MusicBrainz
11
+
12
+ # Unit test for the Collection class.
13
+ class TestCollection < Test::Unit::TestCase
14
+
15
+ def setup
16
+ @artist_one = Model::Artist.new
17
+ @artist_two = Model::Artist.new
18
+ @artist_three = Model::Artist.new
19
+ end
20
+
21
+ def teardown
22
+ end
23
+
24
+ def test_collection
25
+ collection = Model::Collection.new(102, 8)
26
+ assert_equal 102, collection.count
27
+ assert_equal 8, collection.offset
28
+
29
+ collection.count = 99
30
+ collection.offset=15
31
+ assert_equal 99, collection.count
32
+ assert_equal 15, collection.offset
33
+
34
+ assert collection.empty?
35
+
36
+ # Fill the collection
37
+ assert_nothing_raised {
38
+ collection << @artist_one
39
+ collection << @artist_two
40
+ collection << @artist_three
41
+ }
42
+ assert_equal 3, collection.size
43
+ assert !collection.empty?
44
+
45
+ # Iterate over the collection
46
+ n = 0
47
+ collection.each {|artist|
48
+ assert artist.is_a?(Model::Artist), artist.inspect
49
+ n += 1
50
+ }
51
+ assert_equal collection.size, n
52
+
53
+ # Random access
54
+ assert_equal @artist_one, collection[0]
55
+ assert_equal @artist_two, collection[1]
56
+ assert_equal @artist_three, collection[2]
57
+
58
+ # Convert collection to array
59
+ array = collection.to_a
60
+ assert_equal Array, array.class
61
+ assert_equal @artist_one, array[0]
62
+ assert_equal @artist_two, array[1]
63
+ assert_equal @artist_three, array[2]
64
+ end
65
+
66
+ end