# write dir and gen filename
- my $source_dir = $params->{set_dir}->subdir(lc $src->from);
+ my $source_dir = $params->{set_dir}->subdir($self->_name_for_source($src));
$source_dir->mkpath(0, 0777);
# strip dir separators from file name
unless( $pre_schema ) {
return DBIx::Class::Exception->throw('connection details not valid');
}
- my @tables = map { $pre_schema->source($_)->from } $pre_schema->sources;
+ my @tables = map { $self->_name_for_source($pre_schema->source($_)) } $pre_schema->sources;
$self->msg("Tables to drop: [". join(', ', sort @tables) . "]");
my $dbh = $pre_schema->storage->dbh;
}
$self->msg("- creating temp dir");
$tmp_fixture_dir->mkpath();
- for ( map { $schema->source($_)->from } $schema->sources) {
+ for ( map { $self->_name_for_source($schema->source($_)) } $schema->sources) {
my $from_dir = $fixture_dir->subdir($_);
next unless -e $from_dir;
dircopy($from_dir, $tmp_fixture_dir->subdir($_) );
foreach my $source (sort $schema->sources) {
$self->msg("- adding " . $source);
my $rs = $schema->resultset($source);
- my $source_dir = $tmp_fixture_dir->subdir( lc $rs->result_source->from );
+ my $source_dir = $tmp_fixture_dir->subdir( $self->_name_for_source($rs->result_source) );
next unless (-e $source_dir);
my @rows;
while (my $file = $source_dir->next) {
}
}
+# Helper method for ensuring that the name used for a given source
+# is always the same (This is used to name the fixture directories
+# for example)
+
+sub _name_for_source {
+ my ($self, $source) = @_;
+
+ return ref $source->name ? $source->source_name : $source->name;
+}
+
=head1 AUTHOR
Luke Saunders <luke@shadowcatsystems.co.uk>
ok($fixtures->dump({ config => 'quantity.json', schema => $schema, directory => 't/var/fixtures' }), 'quantity dump executed okay');
# check dump is okay
-my $dir = dir('t/var/fixtures/cd');
+my $dir = dir('t/var/fixtures/CD');
my @children = $dir->children;
is(scalar(@children), 3, 'right number of cd fixtures created');
my $artist1 = $schema->resultset('Artist')->find(1);
my @artist1_cds = $artist1->cds->all;
foreach my $cd (@artist1_cds) {
- my $cd_fix_file = dir('t/var/fixtures', 'cd', $cd->id . '.fix');
+ my $cd_fix_file = dir('t/var/fixtures', 'CD', $cd->id . '.fix');
ok(-e $cd_fix_file, "artist1's cd rel dumped okay");
}
my $artist2 = $schema->resultset('Artist')->find(2);
my @artist2_cds = $artist2->cds->search({ year => { '>' => 2002 } });
foreach my $cd (@artist2_cds) {
- my $cd_fix_file = dir('t/var/fixtures', 'cd', $cd->id . '.fix');
+ my $cd_fix_file = dir('t/var/fixtures', 'CD', $cd->id . '.fix');
ok(-e $cd_fix_file, "artist2's cd rel dumped okay");
}
-my $cd_dir = dir('t/var/fixtures/cd');
+my $cd_dir = dir('t/var/fixtures/CD');
@children = $cd_dir->children;
is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped');
# check dump is okay
my $dir = dir('t/var/fixtures');
-my $cd_dir = dir($dir, 'cd');
+my $cd_dir = dir($dir, 'CD');
my $track_dir = dir($dir, 'track');
# check only artist1's cds that matched the rule were fetched
foreach my $source ($schema->sources) {
my $rs = $schema->resultset($source);
- my $dir = dir($fixture_dir, $rs->result_source->from);
+ my $dir = dir($fixture_dir, ref $rs->result_source->name ? $rs->result_source->source_name : $rs->result_source->name);
my @children = $dir->children;
is (scalar(@children), $rs->count, 'all objects from $source dumped');
}
foreach my $source ($schema->sources) {
my $rs = $schema->resultset($source);
next if $rs->result_source->from eq 'tags';
- my $dir = dir("$fixture_dir/excludes", $rs->result_source->from);
+ my $dir = dir("$fixture_dir/excludes", ref $rs->result_source->name ? $rs->result_source->source_name : $rs->result_source->name);
my @children = $dir->children;
is (scalar(@children), $rs->count, 'all objects from $source dumped');
}
{
# check dump is okay
- my $dir = dir('t/var/fixtures/cd');
+ my $dir = dir('t/var/fixtures/CD');
my @children = $dir->children;
is(scalar(@children), 1, 'right number of fixtures created');
ok( -e 't/var/fixtures/producer', "We fetched some producers" );
ok( -e 't/var/fixtures/cd_to_producer', "We fetched some cd/producer xrefs" );
-ok( -e 't/var/fixtures/cd', "We fetched some cds" );
+ok( -e 't/var/fixtures/CD', "We fetched some cds" );
ok( -e 't/var/fixtures/artist', "We fetched some artists" );
__END__
# check dump is okay
foreach my $test (
[ 'artist', 1, 'Artist', 'artistid' ],
- [ 'cd', 2, 'CD', 'cdid' ],
+ [ 'CD', 2, 'CD', 'cdid' ],
) {
my ($dirname, $count, $moniker, $id) = @$test;
my $dir = dir("t/var/fixtures/$dirname");
use base 'DBIx::Class::Core';
-__PACKAGE__->table('cd');
+__PACKAGE__->table(\'cd');
__PACKAGE__->add_columns(
'cdid' => {
data_type => 'integer',