X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F12-populate-basic.t;h=35ff4d27a12ff944c9557e8fddda0a7dba16f9ce;hb=7a8790e251730dd10c1da4731c227a5b65da1ec6;hp=1ebf6c390f58e4f7ec298d7b5e751e4bf22df82d;hpb=4fb695f45d20a6af0bf6bb8d81380c4e865d7c1e;p=dbsrgits%2FDBIx-Class-Fixtures.git diff --git a/t/12-populate-basic.t b/t/12-populate-basic.t index 1ebf6c3..35ff4d2 100644 --- a/t/12-populate-basic.t +++ b/t/12-populate-basic.t @@ -1,22 +1,101 @@ #!perl use DBIx::Class::Fixtures; -use Test::More tests => 6; +use Test::More no_plan; 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'); +ok(my $fixtures = DBIx::Class::Fixtures->new({ + config_dir => $config_dir, + debug => 0 + }), 'object created with correct config dir' +); + +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' + }); + + $schema = DBICTest->init_schema( no_deploy => 1); + + 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) + ); + + 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" + ); + } + } +} + +# use_create => 1 +$schema = DBICTest->init_schema(); +$fixtures = DBIx::Class::Fixtures->new({ + config_dir => $config_dir, + debug => 0 +}); +ok( $fixtures->dump({ + config => "use_create.json", + schema => $schema, + directory => 't/var/fixtures' + }), "use_create dump executed okay" +); +$schema = DBICTest->init_schema( no_populate => 1 ); +$fixtures->populate({ + directory => 't/var/fixtures', + connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''], + schema => $schema, + no_deploy => 1, + use_create => 1 +}); +$schema = DBICTest->init_schema( no_deploy => 1, no_populate => 1 ); +is( $schema->resultset( "Artist" )->find({ artistid => 4 })->name, "Test Name", "use_create => 1 ok" ); -$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'); +$schema = DBICTest->init_schema( no_populate => 1 ); +$fixtures->populate({ + directory => 't/var/fixtures', + connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''], + schema => $schema, + no_deploy => 1, + use_find_or_create => 1 +}); +is( $schema->resultset( "Artist" )->find({ artistid => 4 })->name, "Test Name", "use_find_or_create => 1 ok" ); +$fixtures->populate({ + directory => 't/var/fixtures', + connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''], + schema => $schema, + no_deploy => 1, + use_find_or_create => 1 +}); +is( $schema->resultset( "Artist" )->find({ artistid => 4 })->name, "Test Name", "idempotent use_find_or_create => 1 ok" );