From: Luke Saunders Date: Thu, 31 Jan 2008 19:59:21 +0000 (+0000) Subject: better populate test X-Git-Tag: v1.001002~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c5282523430b124143cbc5d98f33cb149e9806d;p=dbsrgits%2FDBIx-Class-Fixtures.git better populate test --- diff --git a/t/12-populate-basic.t b/t/12-populate-basic.t index 1ebf6c3..ddeeec3 100644 --- a/t/12-populate-basic.t +++ b/t/12-populate-basic.t @@ -1,22 +1,37 @@ #!perl use DBIx::Class::Fixtures; -use Test::More tests => 6; +use Test::More tests => 47; use lib qw(t/lib); use DBICTest; use Path::Class; -use Data::Dumper; +use Data::Dumper; # set up and populate schema ok(my $schema = DBICTest->init_schema(), 'got schema'); - my $config_dir = 't/var/configs'; # do dump ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); -ok($fixtures->dump({ config => 'simple.json', schema => $schema, directory => 't/var/fixtures' }), 'simple dump executed okay'); -$fixtures->populate({ ddl => 't/lib/sqlite.sql', connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''], directory => 't/var/fixtures' }); -is($schema->resultset('Artist')->count, 1, 'correct number of artists'); -is($schema->resultset('CD')->count, 0, 'correct number of cds'); -is($schema->resultset('Track')->count, 0, 'correct number of tracks'); +foreach my $set ('simple', 'quantity', 'fetch', 'rules') { + no warnings 'redefine'; + DBICTest->clear_schema($schema); + DBICTest->populate_schema($schema); + ok($fixtures->dump({ config => "$set.json", schema => $schema, directory => 't/var/fixtures' }), "$set dump executed okay"); + $fixtures->populate({ ddl => 't/lib/sqlite.sql', connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''], directory => 't/var/fixtures' }); + + my $fixture_dir = dir('t/var/fixtures'); + foreach my $class ($schema->sources) { + my $source_dir = dir($fixture_dir, lc($class)); + is($schema->resultset($class)->count, (-e $source_dir) ? scalar($source_dir->children) : 0, "correct number of $set " . lc($class) . 's ' . $schema->resultset($class)->count); + next unless (-e $source_dir); + + my $rs = $schema->resultset($class); + foreach my $row ($rs->all) { + my $file = file($source_dir, $row->id . '.fix'); + my $HASH1; eval($file->slurp()); + is_deeply($HASH1, {$row->get_columns}, "$set " . lc($class) . " row " . $row->id . " imported okay") + } + } +} diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 27d6ad6..c3059ce 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -91,6 +91,23 @@ sub deploy_schema { close IN; ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql); } + + +=head2 clear_schema + + DBICTest->clear_schema( $schema ); + +=cut + +sub clear_schema { + my $self = shift; + my $schema = shift; + + foreach my $class ($schema->sources) { + $schema->resultset($class)->delete; + } +} + =head2 populate_schema