Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support annotations over release, tracks and labels as well

  • Loading branch information...
commit 5b4e8b6f2ac1318b5bdf978374337479d470805c 1 parent 548446e
Oliver authored
View
8 lib/MusicBrainz/Schema/Result/Label.pm
@@ -9,7 +9,7 @@ __PACKAGE__->load_components(qw/ PK::Auto Core /);
__PACKAGE__->table('label');
__PACKAGE__->add_columns(qw/
id gid name modpending labelcode sortname resolution
- begindate enddate type
+ begindate enddate type page
/);
__PACKAGE__->set_primary_key('id');
@@ -19,4 +19,10 @@ __PACKAGE__->many_to_many(
{ order_by => [ 'releasedate', 'catno', 'release.name' ] }
);
+sub annotations {
+ my ($self) = @_;
+ my $schema = $self->result_source->schema;
+ $schema->resultset('Annotation')->for_label($self);
+}
+
1;
View
6 lib/MusicBrainz/Schema/Result/Release.pm
@@ -88,4 +88,10 @@ sub release_status_name
return exists $album_attribute_mapping{$release_status} ? $album_attribute_mapping{$release_status}->[0] : 'Unknown';
}
+sub annotations {
+ my ($self) = @_;
+ my $schema = $self->result_source->schema;
+ $schema->resultset('Annotation')->for_release($self);
+}
+
1;
View
6 lib/MusicBrainz/Schema/Result/Track.pm
@@ -15,4 +15,10 @@ __PACKAGE__->set_primary_key('id');
__PACKAGE__->belongs_to('artist' => 'MusicBrainz::Schema::Result::Artist');
__PACKAGE__->has_many('track_releases' => 'MusicBrainz::Schema::Result::ReleaseTrack');
+sub annotations {
+ my ($self) = @_;
+ my $schema = $self->result_source->schema;
+ $schema->resultset('Annotation')->for_track($self);
+}
+
1;
View
90 t/annotations.t
@@ -2,7 +2,7 @@ use strict;
use warnings;
use Data::UUID;
-use Test::More tests => 7;
+use Test::More tests => 29;
BEGIN { use_ok('MusicBrainz::Schema'); }
my $schema = MusicBrainz::Schema->connect('DBI:Pg:dbname=musicbrainz_db_test', 'musicbrainz_user');
@@ -10,11 +10,12 @@ my $schema = MusicBrainz::Schema->connect('DBI:Pg:dbname=musicbrainz_db_test', '
# Integrity
my $annotations_rs = $schema->resultset('Annotation');
my $artist_rs = $schema->resultset('Artist');
+my $label_rs = $schema->resultset('Label');
+my $release_rs = $schema->resultset('Release');
+my $track_rs = $schema->resultset('Track');
my $editor_rs = $schema->resultset('Editor');
-$editor_rs->delete;
-$annotations_rs->delete;
-$artist_rs->delete;
+clean_up();
my $artist = $artist_rs->create({
name => 'Foo',
@@ -23,33 +24,72 @@ my $artist = $artist_rs->create({
gid => lc Data::UUID->new->create_str,
});
+my $release = $artist->create_related('releases', {
+ name => 'Test Release',
+ gid => lc Data::UUID->new->create_str,
+ page => 0,
+});
+
+my $label = $label_rs->create({
+ name => 'Test label',
+ sortname => 'Test Label',
+ gid => lc Data::UUID->new->create_str,
+ page => 0,
+});
+
my $editor = $editor_rs->create({
name => 'Test Editor',
password => 'foo',
});
-my $annotation = $annotations_rs->create_artist_annotation({
- artist => $artist,
- text => 'My annotation',
- editor => $editor,
- moderation => 1
+my $track = $track_rs->create({
+ name => 'Test Track',
+ gid => lc Data::UUID->new->create_str,
+ artist => $artist->id,
});
-is($annotation->type, 1, 'not an artist annotation');
-my $newer_annotation = $annotations_rs->create_artist_annotation({
- artist => $artist,
- text => 'My annotation',
- editor => $editor,
- moderation => 2
-});
-is($newer_annotation->type, 1, 'not an artist annotation');
+my $mod_counter = 0;
+
+annotate($artist, 'artist', 1);
+annotate($release, 'release', 2);
+annotate($label, 'label', 3);
+annotate($track, 'track', 4);
+
+clean_up();
+
+sub annotate {
+ my ($object, $type, $t) = @_;
+
+ my $create = "create_${type}_annotation";
+ can_ok($annotations_rs, $create);
+ my $annotation = $annotations_rs->$create({
+ $type => $object,
+ text => 'My annotation',
+ editor => $editor,
+ moderation => $mod_counter++
+ });
+ is($annotation->type, $t, "not a $type annotation");
+
+ my $newer_annotation = $annotations_rs->$create({
+ $type => $object,
+ text => 'My annotation',
+ editor => $editor,
+ moderation => $mod_counter++
+ });
+ is($newer_annotation->type, $t, "not a $type annotation");
-# Helper methods
-can_ok($artist, 'annotations');
-isa_ok($artist->annotations, 'MusicBrainz::Schema::ResultSet::Annotation');
-is($artist->annotations->count, 2, 'should have 2 annotations');
-is($artist->annotations->latest->id, $newer_annotation->id, 'latest no worky');
+ # Helper methods
+ can_ok($object, 'annotations');
+ isa_ok($object->annotations, 'MusicBrainz::Schema::ResultSet::Annotation');
+ is($object->annotations->count, 2, "$type should have 2 annotations");
+ is($object->annotations->latest->id, $newer_annotation->id, "$type latest is incorrect");
+}
-$editor_rs->delete;
-$annotations_rs->delete;
-$artist_rs->delete;
+sub clean_up {
+ $editor_rs->delete;
+ $annotations_rs->delete;
+ $label_rs->delete;
+ $track_rs->delete;
+ $release_rs->delete;
+ $artist_rs->delete;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.