rbrainz 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGES +13 -1
  2. data/LICENSE +1 -1
  3. data/README +2 -2
  4. data/Rakefile +2 -2
  5. data/TODO +9 -2
  6. data/doc/README.rdoc +5 -5
  7. data/examples/getartist.rb +3 -2
  8. data/examples/getlabel.rb +3 -2
  9. data/examples/getrelease.rb +5 -2
  10. data/examples/getreleasegroup.rb +53 -0
  11. data/examples/gettrack.rb +3 -2
  12. data/examples/getuser.rb +2 -1
  13. data/examples/rate.rb +44 -0
  14. data/examples/searchartists.rb +3 -2
  15. data/examples/searchcdstubs.rb +41 -0
  16. data/examples/searchlabels.rb +3 -2
  17. data/examples/searchreleasegroups.rb +36 -0
  18. data/examples/searchreleases.rb +6 -4
  19. data/examples/searchtracks.rb +3 -2
  20. data/examples/submit_isrcs.rb +52 -0
  21. data/examples/tag.rb +3 -2
  22. data/lib/rbrainz.rb +2 -1
  23. data/lib/rbrainz/core_ext.rb +2 -1
  24. data/lib/rbrainz/core_ext/mbid.rb +2 -1
  25. data/lib/rbrainz/core_ext/net_http_digest.rb +3 -2
  26. data/lib/rbrainz/core_ext/range.rb +3 -2
  27. data/lib/rbrainz/core_ext/range/equality.rb +2 -1
  28. data/lib/rbrainz/data/countrynames.rb +6 -3
  29. data/lib/rbrainz/data/languagenames.rb +3 -2
  30. data/lib/rbrainz/data/releasetypenames.rb +3 -2
  31. data/lib/rbrainz/data/scriptnames.rb +3 -2
  32. data/lib/rbrainz/model.rb +3 -2
  33. data/lib/rbrainz/model/alias.rb +3 -2
  34. data/lib/rbrainz/model/artist.rb +11 -3
  35. data/lib/rbrainz/model/collection.rb +3 -2
  36. data/lib/rbrainz/model/default_factory.rb +18 -6
  37. data/lib/rbrainz/model/disc.rb +3 -2
  38. data/lib/rbrainz/model/entity.rb +2 -102
  39. data/lib/rbrainz/model/incomplete_date.rb +3 -2
  40. data/lib/rbrainz/model/individual.rb +11 -2
  41. data/lib/rbrainz/model/isrc.rb +100 -0
  42. data/lib/rbrainz/model/label.rb +5 -2
  43. data/lib/rbrainz/model/mbid.rb +28 -9
  44. data/lib/rbrainz/model/rateable.rb +34 -0
  45. data/lib/rbrainz/model/rating.rb +56 -0
  46. data/lib/rbrainz/model/relateable.rb +118 -0
  47. data/lib/rbrainz/model/relation.rb +2 -1
  48. data/lib/rbrainz/model/release.rb +17 -3
  49. data/lib/rbrainz/model/release_event.rb +3 -2
  50. data/lib/rbrainz/model/release_group.rb +97 -0
  51. data/lib/rbrainz/model/scored_collection.rb +3 -2
  52. data/lib/rbrainz/model/tag.rb +5 -4
  53. data/lib/rbrainz/model/taggable.rb +27 -0
  54. data/lib/rbrainz/model/track.rb +15 -2
  55. data/lib/rbrainz/model/user.rb +3 -2
  56. data/lib/rbrainz/utils.rb +2 -1
  57. data/lib/rbrainz/utils/data.rb +3 -2
  58. data/lib/rbrainz/utils/helper.rb +8 -2
  59. data/lib/rbrainz/version.rb +3 -2
  60. data/lib/rbrainz/webservice.rb +12 -7
  61. data/lib/rbrainz/webservice/filter.rb +53 -4
  62. data/lib/rbrainz/webservice/includes.rb +72 -11
  63. data/lib/rbrainz/webservice/mbxml.rb +129 -67
  64. data/lib/rbrainz/webservice/query.rb +156 -16
  65. data/lib/rbrainz/webservice/webservice.rb +104 -116
  66. data/test/lib/mock_webservice.rb +9 -2
  67. data/test/lib/test_entity.rb +2 -97
  68. data/test/lib/test_factory.rb +9 -1
  69. data/test/lib/test_rateable.rb +31 -0
  70. data/test/lib/test_relateable.rb +103 -0
  71. data/test/lib/test_taggable.rb +36 -0
  72. data/test/lib/testing_helper.rb +17 -2
  73. data/test/test-data/invalid/artist/ratings_1.xml +6 -0
  74. data/test/test-data/invalid/artist/ratings_2.xml +6 -0
  75. data/test/test-data/valid/artist/Tchaikovsky-2.xml +6 -0
  76. data/test/test-data/valid/label/Atlantic_Records_3.xml +6 -0
  77. data/test/test-data/valid/release-group/The_Cure_1.xml +36 -0
  78. data/test/test-data/valid/release/Highway_61_Revisited_2.xml +6 -0
  79. data/test/test-data/valid/track/Silent_All_These_Years_4.xml +3 -0
  80. data/test/test-data/valid/track/Silent_All_These_Years_6.xml +8 -0
  81. data/test/test_alias.rb +2 -1
  82. data/test/test_artist.rb +24 -2
  83. data/test/test_artist_filter.rb +2 -1
  84. data/test/test_artist_includes.rb +13 -3
  85. data/test/test_collection.rb +3 -2
  86. data/test/test_default_factory.rb +8 -1
  87. data/test/test_disc.rb +2 -1
  88. data/test/test_incomplete_date.rb +2 -1
  89. data/test/test_isrc.rb +87 -0
  90. data/test/test_label.rb +8 -1
  91. data/test/test_label_filter.rb +2 -1
  92. data/test/test_label_includes.rb +10 -3
  93. data/test/test_mbid.rb +2 -1
  94. data/test/test_mbxml.rb +93 -2
  95. data/test/test_query.rb +68 -5
  96. data/test/test_range_equality.rb +2 -1
  97. data/test/test_rating.rb +46 -0
  98. data/test/test_relation.rb +2 -1
  99. data/test/test_release.rb +37 -2
  100. data/test/test_release_event.rb +2 -1
  101. data/test/test_release_filter.rb +15 -2
  102. data/test/test_release_group.rb +104 -0
  103. data/test/test_release_group_filter.rb +61 -0
  104. data/test/test_release_group_includes.rb +46 -0
  105. data/test/test_release_includes.rb +16 -3
  106. data/test/test_scored_collection.rb +3 -2
  107. data/test/test_tag.rb +2 -1
  108. data/test/test_track.rb +28 -1
  109. data/test/test_track_filter.rb +2 -1
  110. data/test/test_track_includes.rb +13 -3
  111. data/test/test_utils.rb +2 -1
  112. data/test/test_webservice.rb +11 -1
  113. metadata +38 -20
  114. data/debian/changelog +0 -11
  115. data/debian/compat +0 -1
  116. data/debian/control +0 -13
  117. data/debian/copyright +0 -25
  118. data/debian/rules +0 -48
@@ -1,4 +1,5 @@
1
- # $Id: test_query.rb 147 2007-07-19 17:10:26Z phw $
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_query.rb 254 2009-05-13 20:04:36Z phw $
2
3
  #
3
4
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
5
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -22,7 +23,16 @@ class TestQuery < Test::Unit::TestCase
22
23
  def teardown
23
24
  end
24
25
 
25
- def test_get_artist
26
+ def test_get_artist_with_includes
27
+ id = 'c0b2500e-0cef-4130-869d-732b23ed9df5'
28
+ includes = Webservice::ArtistIncludes.new(:aliases => true)
29
+ entity = @query.get_artist_by_id(id, includes)
30
+ assert entity.is_a?(Model::Artist)
31
+ assert_equal id, entity.id.uuid
32
+ assert_equal 'Tori Amos', entity.name
33
+ end
34
+
35
+ def test_get_artist_without_includes
26
36
  id = 'c0b2500e-0cef-4130-869d-732b23ed9df5'
27
37
  entity = @query.get_artist_by_id(id)
28
38
  assert entity.is_a?(Model::Artist)
@@ -38,7 +48,42 @@ class TestQuery < Test::Unit::TestCase
38
48
  collection.entities.each {|e| assert e.is_a?(Model::Artist) }
39
49
  end
40
50
 
41
- def test_get_release
51
+ def test_get_release_group_with_includes
52
+ id = 'c6a62b78-70f7-44f7-b159-064f6b7ba03a'
53
+ includes = Webservice::ReleaseGroupIncludes.new(:artist => true)
54
+ entity = @query.get_release_group_by_id(id, includes)
55
+ assert entity.is_a?(Model::ReleaseGroup)
56
+ assert_equal id, entity.id.uuid
57
+ assert_equal 'The Cure', entity.title
58
+ end
59
+
60
+ def test_get_release_group_without_includes
61
+ id = 'c6a62b78-70f7-44f7-b159-064f6b7ba03a'
62
+ entity = @query.get_release_group_by_id(id)
63
+ assert entity.is_a?(Model::ReleaseGroup)
64
+ assert_equal id, entity.id.uuid
65
+ assert_equal 'The Cure', entity.title
66
+ end
67
+
68
+ # TODO: Enable this test once there is a proper test file.
69
+ #def test_get_release_groups
70
+ # filter = Webservice::ReleaseGroupFilter.new(:title=>'The Cure')
71
+ # collection = @query.get_release_groups(filter)
72
+ # assert collection.is_a?(Model::Collection)
73
+ # assert_equal 2, collection.size
74
+ # collection.entities.each {|e| assert e.is_a?(Model::ReleaseGroup) }
75
+ #end
76
+
77
+ def test_get_release_with_includes
78
+ id = '290e10c5-7efc-4f60-ba2c-0dfc0208fbf5'
79
+ includes = Webservice::ReleaseIncludes.new(:artist => true)
80
+ entity = @query.get_release_by_id(id, includes)
81
+ assert entity.is_a?(Model::Release)
82
+ assert_equal id, entity.id.uuid
83
+ assert_equal 'Under the Pink', entity.title
84
+ end
85
+
86
+ def test_get_release_without_includes
42
87
  id = '290e10c5-7efc-4f60-ba2c-0dfc0208fbf5'
43
88
  entity = @query.get_release_by_id(id)
44
89
  assert entity.is_a?(Model::Release)
@@ -54,7 +99,16 @@ class TestQuery < Test::Unit::TestCase
54
99
  collection.entities.each {|e| assert e.is_a?(Model::Release) }
55
100
  end
56
101
 
57
- def test_get_track
102
+ def test_get_track_with_includes
103
+ id = 'd6118046-407d-4e06-a1ba-49c399a4c42f'
104
+ includes = Webservice::TrackIncludes.new(:releases => true)
105
+ entity = @query.get_track_by_id(id, includes)
106
+ assert entity.is_a?(Model::Track)
107
+ assert_equal id, entity.id.uuid
108
+ assert_equal 'Silent All These Years', entity.title
109
+ end
110
+
111
+ def test_get_track_without_includes
58
112
  id = 'd6118046-407d-4e06-a1ba-49c399a4c42f'
59
113
  entity = @query.get_track_by_id(id)
60
114
  assert entity.is_a?(Model::Track)
@@ -70,7 +124,16 @@ class TestQuery < Test::Unit::TestCase
70
124
  collection.entities.each {|e| assert e.is_a?(Model::Track) }
71
125
  end
72
126
 
73
- def test_get_label
127
+ def test_get_label_with_includes
128
+ id = '50c384a2-0b44-401b-b893-8181173339c7'
129
+ includes = Webservice::LabelIncludes.new(:aliases => true)
130
+ entity = @query.get_label_by_id(id, includes)
131
+ assert entity.is_a?(Model::Label)
132
+ assert_equal id, entity.id.uuid
133
+ assert_equal 'Atlantic Records', entity.name
134
+ end
135
+
136
+ def test_get_label_without_includes
74
137
  id = '50c384a2-0b44-401b-b893-8181173339c7'
75
138
  entity = @query.get_label_by_id(id)
76
139
  assert entity.is_a?(Model::Label)
@@ -1,4 +1,5 @@
1
- # $Id: test_range_equality.rb 154 2007-07-24 12:39:02Z phw $
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_range_equality.rb 254 2009-05-13 20:04:36Z phw $
2
3
  #
3
4
  # Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
4
5
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_rating.rb 254 2009-05-13 20:04:36Z phw $
3
+ #
4
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
5
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
6
+ # License:: RBrainz is free software distributed under a BSD style license.
7
+ # See LICENSE[file:../LICENSE.html] for permissions.
8
+
9
+ require 'test/unit'
10
+ require 'rbrainz/model'
11
+ include MusicBrainz
12
+
13
+ # Unit test for the Tag model.
14
+ class TestRating < Test::Unit::TestCase
15
+
16
+ def setup
17
+ end
18
+
19
+ def teardown
20
+ end
21
+
22
+ def test_rating
23
+ rating = nil
24
+ assert_nothing_raised {rating = Model::Rating.new}
25
+ assert rating.empty?
26
+ rating.value = 3.3
27
+ rating.count = 12
28
+ assert_equal 3.3, rating.value
29
+ assert_equal 3.3, rating.to_f
30
+ assert_equal 3, rating.to_i
31
+ assert_equal '3.3', rating.to_s
32
+ assert_equal 12, rating.count
33
+ assert_equal false, rating.empty?
34
+
35
+ assert_nothing_raised {rating = Model::Rating.new(5)}
36
+ assert_equal 5.0, rating.value
37
+ assert_equal nil, rating.count
38
+ assert_equal false, rating.empty?
39
+
40
+ assert_nothing_raised {rating = Model::Rating.new(1.0, 11)}
41
+ assert_equal 1.0, rating.value
42
+ assert_equal 11, rating.count
43
+ assert_equal false, rating.empty?
44
+ end
45
+
46
+ end
@@ -1,4 +1,5 @@
1
- # $Id: test_relation.rb 120 2007-07-12 08:28:11Z phw $
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_relation.rb 254 2009-05-13 20:04:36Z phw $
2
3
  #
3
4
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
5
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -1,11 +1,15 @@
1
- # $Id: test_release.rb 163 2007-07-29 17:52:22Z phw $
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_release.rb 278 2009-06-07 21:30:51Z phw $
2
3
  #
3
4
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
- # Copyright:: Copyright (c) 2007, Philipp Wolfer
5
+ # Copyright:: Copyright (c) 2007-2009, Philipp Wolfer
5
6
  # License:: RBrainz is free software distributed under a BSD style license.
6
7
  # See LICENSE[file:../LICENSE.html] for permissions.
7
8
 
8
9
  require 'test_entity'
10
+ require 'test_rateable'
11
+ require 'test_relateable'
12
+ require 'test_taggable'
9
13
 
10
14
  # Unit test for the Release model.
11
15
  class TestRelease < Test::Unit::TestCase
@@ -13,6 +17,8 @@ class TestRelease < Test::Unit::TestCase
13
17
  def setup
14
18
  @tested_class = Model::Release
15
19
  @invalid_entity_types = [:artist, :track, :label]
20
+
21
+ @release_groups = [Model::ReleaseGroup.new, Model::ReleaseGroup.new]
16
22
  @tracks = [Model::Track.new, Model::Track.new]
17
23
  @release_events = [Model::ReleaseEvent.new('DE', 2007), Model::ReleaseEvent.new('GB', 1996),
18
24
  Model::ReleaseEvent.new('GB', '1996-06-01'), Model::ReleaseEvent.new('GB', '1996-06')]
@@ -24,6 +30,9 @@ class TestRelease < Test::Unit::TestCase
24
30
 
25
31
  # Include the tests for Entity
26
32
  include TestEntity
33
+ include TestRateable
34
+ include TestRelateable
35
+ include TestTaggable
27
36
 
28
37
  def test_new_release
29
38
  release = nil
@@ -104,6 +113,14 @@ class TestRelease < Test::Unit::TestCase
104
113
  assert_equal 0, release.types.size
105
114
  end
106
115
 
116
+ def test_release_group
117
+ release = Model::Release.new
118
+ release_group = Model::ReleaseGroup.new
119
+ assert release.release_group.nil?
120
+ assert_nothing_raised {release.release_group = release_group}
121
+ assert_equal release_group, release.release_group
122
+ end
123
+
107
124
  # Many tracks can be added
108
125
  def test_add_and_remove_tracks
109
126
  release = Model::Release.new
@@ -164,4 +181,22 @@ class TestRelease < Test::Unit::TestCase
164
181
  assert_equal 0, release.discs.size
165
182
  end
166
183
 
184
+ def test_single_artist_release
185
+ release = Model::Release.new
186
+ assert_raise(RuntimeError) {release.single_artist_release?}
187
+
188
+ artist = Model::Artist.new('9d30e408-1559-448b-b491-2f8de1583ccf')
189
+ release.artist = artist
190
+ assert release.single_artist_release?
191
+
192
+ @tracks.each {|track| release.tracks << track}
193
+ assert release.single_artist_release?
194
+
195
+ release.tracks[0].artist = artist
196
+ assert release.single_artist_release?
197
+
198
+ release.tracks[1].artist = Model::Artist.new('10bf95b6-30e3-44f1-817f-45762cdc0de0')
199
+ assert release.single_artist_release? == false
200
+ end
201
+
167
202
  end
@@ -1,4 +1,5 @@
1
- # $Id: test_release_event.rb 189 2007-11-26 00:10:49Z phw $
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_release_event.rb 254 2009-05-13 20:04:36Z phw $
2
3
  #
3
4
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
5
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -1,4 +1,5 @@
1
- # $Id: test_release_filter.rb 159 2007-07-25 16:53:32Z phw $
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_release_filter.rb 264 2009-05-24 22:15:19Z phw $
2
3
  #
3
4
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
5
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -25,6 +26,7 @@ class TestReleaseFilter < Test::Unit::TestCase
25
26
  :asin => 'B00004VVW9',
26
27
  :lang => 'ENG',
27
28
  :script => 'Latn',
29
+ :cdstubs => false,
28
30
  :limit => 10,
29
31
  :offset => 20,
30
32
  :query => 'date:2000'
@@ -50,6 +52,7 @@ class TestReleaseFilter < Test::Unit::TestCase
50
52
  assert_equal @filter_hash[:asin], result_hash['asin'], filter_string
51
53
  assert_equal @filter_hash[:lang], result_hash['lang'], filter_string
52
54
  assert_equal @filter_hash[:script], result_hash['script'], filter_string
55
+ assert_equal 'no', result_hash['cdstubs'], filter_string
53
56
  assert_equal @filter_hash[:limit].to_s, result_hash['limit'], filter_string
54
57
  assert_equal @filter_hash[:offset].to_s, result_hash['offset'], filter_string
55
58
  assert_equal @filter_hash[:query].to_s, result_hash['query'], filter_string
@@ -66,7 +69,17 @@ class TestReleaseFilter < Test::Unit::TestCase
66
69
 
67
70
  def test_empty_filter
68
71
  filter = Webservice::ReleaseFilter.new({})
69
- assert_equal '', filter.to_s
72
+ assert_equal 'cdstubs=no', filter.to_s
73
+ end
74
+
75
+ def test_include_cdstubs
76
+ filter = Webservice::ReleaseFilter.new({ :cdstubs => true })
77
+ assert_equal 'cdstubs=yes', filter.to_s
78
+ end
79
+
80
+ def test_exclude_cdstubs
81
+ filter = Webservice::ReleaseFilter.new({ :cdstubs => false })
82
+ assert_equal 'cdstubs=no', filter.to_s
70
83
  end
71
84
 
72
85
  end
@@ -0,0 +1,104 @@
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_release_group.rb 271 2009-05-24 22:15:31Z phw $
3
+ #
4
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
5
+ # Copyright:: Copyright (c) 2009, Philipp Wolfer
6
+ # License:: RBrainz is free software distributed under a BSD style license.
7
+ # See LICENSE[file:../LICENSE.html] for permissions.
8
+
9
+ require 'test_entity'
10
+
11
+ # Unit test for the Release model.
12
+ class TestReleaseGroup < Test::Unit::TestCase
13
+
14
+ def setup
15
+ @tested_class = Model::ReleaseGroup
16
+ @invalid_entity_types = [:artist, :track, :label, :release]
17
+ @releases = [Model::Release.new, Model::Release.new]
18
+ end
19
+
20
+ def teardown
21
+ end
22
+
23
+ # Include the tests for Entity
24
+ include TestEntity
25
+
26
+ def test_new_release_group
27
+ release_group = nil
28
+ assert_nothing_raised {release_group = Model::ReleaseGroup.new}
29
+ assert release_group.is_a?(Model::Entity)
30
+
31
+ mbid = Model::MBID.new('a07cbaff-aa79-35a9-9932-af7335f306eb', :release_group)
32
+ assert_nothing_raised {release_group = Model::ReleaseGroup.new(
33
+ mbid,
34
+ 'In Requiem'
35
+ )}
36
+ assert_equal mbid, release_group.id
37
+ assert_equal 'In Requiem', release_group.title
38
+ end
39
+
40
+ def test_title
41
+ release_group = Model::ReleaseGroup.new
42
+ assert release_group.title.nil?
43
+ assert_nothing_raised {release_group.title = 'Draconian Times'}
44
+ assert_equal 'Draconian Times', release_group.title
45
+ assert_equal 'Draconian Times', release_group.to_s
46
+ end
47
+
48
+ def test_types
49
+ release_group = Model::ReleaseGroup.new
50
+ assert_equal 0, release_group.types.size
51
+ types = []
52
+ assert_nothing_raised {
53
+ types = [Model::ReleaseGroup::TYPE_NONE,
54
+ Model::ReleaseGroup::TYPE_NON_ALBUM_TRACKS,
55
+ Model::ReleaseGroup::TYPE_ALBUM,
56
+ Model::ReleaseGroup::TYPE_SINGLE,
57
+ Model::ReleaseGroup::TYPE_EP,
58
+ Model::ReleaseGroup::TYPE_SOUNDTRACK,
59
+ Model::ReleaseGroup::TYPE_SPOKENWORD,
60
+ Model::ReleaseGroup::TYPE_INTERVIEW,
61
+ Model::ReleaseGroup::TYPE_AUDIOBOOK,
62
+ Model::ReleaseGroup::TYPE_LIVE,
63
+ Model::ReleaseGroup::TYPE_REMIX,
64
+ Model::ReleaseGroup::TYPE_OTHER,
65
+ ]
66
+ }
67
+
68
+ # Adding all those types should be possible.
69
+ types.each {|type|
70
+ assert_nothing_raised {release_group.types << type}
71
+ }
72
+ assert_equal 12, release_group.types.size
73
+
74
+ # Removing the types again
75
+ types.each {|type|
76
+ assert_nothing_raised {release_group.types.delete type}
77
+ }
78
+ assert_equal 0, release_group.types.size
79
+ end
80
+
81
+ def test_artist
82
+ release_group = Model::ReleaseGroup.new
83
+ artist = Model::Artist.new
84
+ assert release_group.artist.nil?
85
+ assert_nothing_raised {release_group.artist = artist}
86
+ assert_equal artist, release_group.artist
87
+ end
88
+
89
+ # Many releases can be added
90
+ def test_add_and_remove_releases
91
+ release_group = Model::ReleaseGroup.new
92
+ assert_equal 0, release_group.releases.size
93
+ assert_nothing_raised {release_group.releases << @releases[0]}
94
+ assert_equal 1, release_group.releases.size
95
+ assert_nothing_raised {release_group.releases << @releases[1]}
96
+ assert_equal 2, release_group.releases.size
97
+
98
+ assert_nothing_raised {release_group.releases.delete @releases[1]}
99
+ assert_equal 1, release_group.releases.size
100
+ assert_nothing_raised {release_group.releases.delete @releases[0]}
101
+ assert_equal 0, release_group.releases.size
102
+ end
103
+
104
+ end
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: test_release_group_filter.rb 273 2009-05-24 22:29:04Z phw $
3
+ #
4
+ # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
5
+ # Copyright:: Copyright (c) 2007, Philipp Wolfer
6
+ # License:: RBrainz is free software distributed under a BSD style license.
7
+ # See LICENSE[file:../LICENSE.html] for permissions.
8
+
9
+ require 'test/unit'
10
+ require 'testing_helper'
11
+ require 'rbrainz'
12
+ include MusicBrainz
13
+
14
+ # Unit test for the ReleaseFilter class.
15
+ class TestReleaseGroupFilter < Test::Unit::TestCase
16
+
17
+ def setup
18
+ @filter_hash = {
19
+ :title => 'Haven',
20
+ :artist => 'Dark Tranquillity',
21
+ :artistid => '9d30e408-1559-448b-b491-2f8de1583ccf',
22
+ :releasetypes => 'Album Official',
23
+ :limit => 10,
24
+ :offset => 20,
25
+ :query => 'title:Haven'
26
+ }
27
+ end
28
+
29
+ def teardown
30
+ end
31
+
32
+ def test_filter
33
+ filter = Webservice::ReleaseGroupFilter.new(@filter_hash)
34
+ filter_string = filter.to_s
35
+ assert_not_equal '&', filter_string[0]
36
+
37
+ result_hash = query_string_to_hash filter_string
38
+ assert_equal @filter_hash[:title], result_hash['title'], filter_string
39
+ assert_equal @filter_hash[:artist], result_hash['artist'], filter_string
40
+ assert_equal @filter_hash[:artistid], result_hash['artistid'], filter_string
41
+ assert_equal @filter_hash[:releasetypes], result_hash['releasetypes'], filter_string
42
+ assert_equal @filter_hash[:limit].to_s, result_hash['limit'], filter_string
43
+ assert_equal @filter_hash[:offset].to_s, result_hash['offset'], filter_string
44
+ assert_equal @filter_hash[:query].to_s, result_hash['query'], filter_string
45
+ end
46
+
47
+ def test_release_types_as_array
48
+ filter = Webservice::ReleaseGroupFilter.new(:releasetypes => [Model::ReleaseGroup::TYPE_ALBUM, 'Official'])
49
+ filter_string = filter.to_s
50
+ assert_not_equal '&', filter_string[0]
51
+
52
+ result_hash = query_string_to_hash filter_string
53
+ assert_equal 'Album Official', result_hash['releasetypes'], filter_string
54
+ end
55
+
56
+ def test_empty_filter
57
+ filter = Webservice::ReleaseGroupFilter.new({})
58
+ assert_equal '', filter.to_s
59
+ end
60
+
61
+ end