From: Mike Francis Date: Thu, 27 Nov 2014 10:11:51 +0000 (+0000) Subject: Use source->name or source->source_name for naming of sources in a central method X-Git-Tag: v1.001026~1^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Fixtures.git;a=commitdiff_plain;h=dcdf675f7c1e751f53bce149fe7af49bf079771b Use source->name or source->source_name for naming of sources in a central method --- diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index 19a78e6..2443997 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -844,7 +844,7 @@ sub dump_object { # 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 @@ -1045,7 +1045,7 @@ sub _generate_schema { 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; @@ -1336,7 +1336,7 @@ sub populate { } $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($_) ); @@ -1368,7 +1368,7 @@ sub populate { 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) { @@ -1457,6 +1457,16 @@ sub msg { } } +# 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 diff --git a/t/03-dump-quantity.t b/t/03-dump-quantity.t index 011d0ee..2414697 100644 --- a/t/03-dump-quantity.t +++ b/t/03-dump-quantity.t @@ -17,7 +17,7 @@ ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug 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'); diff --git a/t/04-dump-fetch.t b/t/04-dump-fetch.t index e1e9a24..bb99e40 100644 --- a/t/04-dump-fetch.t +++ b/t/04-dump-fetch.t @@ -31,7 +31,7 @@ foreach my $id (1, 2) { 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"); } @@ -39,11 +39,11 @@ foreach my $cd (@artist1_cds) { 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'); diff --git a/t/05-dump-rules.t b/t/05-dump-rules.t index d2e94f6..f6a085f 100644 --- a/t/05-dump-rules.t +++ b/t/05-dump-rules.t @@ -18,7 +18,7 @@ ok($fixtures->dump({ config => 'rules.json', schema => $schema, directory => 't/ # 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 diff --git a/t/07-dump-all.t b/t/07-dump-all.t index 57b73d7..5d5caa9 100644 --- a/t/07-dump-all.t +++ b/t/07-dump-all.t @@ -22,7 +22,7 @@ my $fixture_dir = 't/var/fixtures'; 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'); } @@ -36,7 +36,7 @@ my $fixture_dir = 't/var/fixtures'; 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'); } diff --git a/t/09-dump-scalar-ref.t b/t/09-dump-scalar-ref.t index fe5450b..d7fa019 100644 --- a/t/09-dump-scalar-ref.t +++ b/t/09-dump-scalar-ref.t @@ -31,7 +31,7 @@ ok($fixtures->dump({ config => 'scalar_ref.json', schema => $schema, directory = { # 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'); diff --git a/t/15-multiple-belongs-to.t b/t/15-multiple-belongs-to.t index d52b5cf..803e600 100644 --- a/t/15-multiple-belongs-to.t +++ b/t/15-multiple-belongs-to.t @@ -21,7 +21,7 @@ my $dir = dir('t/var/fixtures'); 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__ diff --git a/t/16-rules-hasmany.t b/t/16-rules-hasmany.t index 7014e4f..ba1f3df 100644 --- a/t/16-rules-hasmany.t +++ b/t/16-rules-hasmany.t @@ -19,7 +19,7 @@ ok($fixtures->dump({ config => 'rules2.json', schema => $schema, directory => 't # 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"); diff --git a/t/lib/DBICTest/Schema/CD.pm b/t/lib/DBICTest/Schema/CD.pm index a6f084f..fb9cb89 100644 --- a/t/lib/DBICTest/Schema/CD.pm +++ b/t/lib/DBICTest/Schema/CD.pm @@ -3,7 +3,7 @@ package # hide from PAUSE use base 'DBIx::Class::Core'; -__PACKAGE__->table('cd'); +__PACKAGE__->table(\'cd'); __PACKAGE__->add_columns( 'cdid' => { data_type => 'integer',