Skip to content

Instantly share code, notes, and snippets.

@ocharles
Created January 24, 2009 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ocharles/51473 to your computer and use it in GitHub Desktop.
Save ocharles/51473 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Data::UUID;
use Test::More tests => 11;
use Test::Exception;
BEGIN { use_ok('MusicBrainz::Schema'); }
my $schema = MusicBrainz::Schema->connect('DBI:Pg:dbname=musicbrainz_db_test', 'musicbrainz_user');
my $artist_rs = $schema->resultset('Artist');
my $alias_rs = $schema->resultset('Alias::Artist');
# Integrity checks
$alias_rs->delete;
$artist_rs->delete;
# Test data
my $source = $artist_rs->create({
name => 'Source Artist',
sortname => 'Artist, Source',
gid => lc Data::UUID->new->create_str,
page => 0,
});
my $target = $artist_rs->create({
name => 'Dest Artist',
sortname => 'Artist, Dest',
gid => lc Data::UUID->new->create_str,
page => 0,
});
# Check this is moved
$source->create_related('aliases', { name => 'Source Alias 1' });
# Check this is retained
$target->create_related('aliases', { name => 'Dest Alias 1' });
# Check we have the correct data
is($artist_rs->count, 2, 'confused about artist count');
is($source->aliases->count, 1, 'confused about alias count');
is($target->aliases->count, 1, 'confused about alias count');
can_ok($source, 'merge_into');
# Do the merge
lives_ok { $source->merge_into($target) } 'could not merge';
# Check artists
is($artist_rs->count, 1, 'still have 2 aritsts');
ok(!defined $artist_rs->find($source->id), 'source still exists');
ok(defined $artist_rs->find($target->id), 'couldnt find target');
# Check aliases
is($alias_rs->count, 2, 'should have 2 aliases');
is($target->aliases->count, 2, 'should have 2 aliases');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment