[Bast-commits] r4000 - in DBIx-Class-Fixtures/1.000/trunk/t: . lib
captainL at dev.catalyst.perl.org
captainL at dev.catalyst.perl.org
Thu Jan 31 19:59:23 GMT 2008
Author: captainL
Date: 2008-01-31 19:59:21 +0000 (Thu, 31 Jan 2008)
New Revision: 4000
Modified:
DBIx-Class-Fixtures/1.000/trunk/t/12-populate-basic.t
DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm
Log:
better populate test
Modified: DBIx-Class-Fixtures/1.000/trunk/t/12-populate-basic.t
===================================================================
--- DBIx-Class-Fixtures/1.000/trunk/t/12-populate-basic.t 2008-01-31 19:16:28 UTC (rev 3999)
+++ DBIx-Class-Fixtures/1.000/trunk/t/12-populate-basic.t 2008-01-31 19:59:21 UTC (rev 4000)
@@ -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")
+ }
+ }
+}
Modified: DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm
===================================================================
--- DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm 2008-01-31 19:16:28 UTC (rev 3999)
+++ DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm 2008-01-31 19:59:21 UTC (rev 4000)
@@ -91,7 +91,24 @@
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
DBICTest->populate_schema( $schema );
More information about the Bast-commits
mailing list