[Bast-commits] r3997 - in DBIx-Class-Fixtures/1.000/trunk: lib/DBIx/Class t t/lib

captainL at dev.catalyst.perl.org captainL at dev.catalyst.perl.org
Thu Jan 31 00:28:20 GMT 2008


Author: captainL
Date: 2008-01-31 00:28:19 +0000 (Thu, 31 Jan 2008)
New Revision: 3997

Added:
   DBIx-Class-Fixtures/1.000/trunk/t/03-dump-quantity.t
   DBIx-Class-Fixtures/1.000/trunk/t/04-dump-fetch.t
   DBIx-Class-Fixtures/1.000/trunk/t/05-dump-rules.t
Modified:
   DBIx-Class-Fixtures/1.000/trunk/lib/DBIx/Class/Fixtures.pm
   DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm
Log:
more dumper tests added

Modified: DBIx-Class-Fixtures/1.000/trunk/lib/DBIx/Class/Fixtures.pm
===================================================================
--- DBIx-Class-Fixtures/1.000/trunk/lib/DBIx/Class/Fixtures.pm	2008-01-30 23:11:12 UTC (rev 3996)
+++ DBIx-Class-Fixtures/1.000/trunk/lib/DBIx/Class/Fixtures.pm	2008-01-31 00:28:19 UTC (rev 3997)
@@ -269,7 +269,7 @@
         #		use Data::Dumper; print ' -- ' . Dumper($c_params{set}, $rule->{fetch}) if ($rule && $rule->{fetch});
         $c_params{set} = merge( $c_params{set}, $rule) if ($rule && $rule->{fetch});
         #		use Data::Dumper; print ' -- ' . Dumper(\%c_params) if ($rule && $rule->{fetch});
-        dump_object($_, \%c_params) foreach $related_rs->all;	  
+        $self->dump_object($_, \%c_params) foreach $related_rs->all;	  
       }	
     }
   }
@@ -297,7 +297,7 @@
     $related_rs = $related_rs->search($fetch->{cond}, { join => $fetch->{join} }) if ($fetch->{cond});
     $related_rs = $related_rs->search({}, { rows => $fetch->{quantity} }) if ($fetch->{quantity} && $fetch->{quantity} ne 'all');
     $related_rs = $related_rs->search({}, { order_by => $fetch->{order_by} }) if ($fetch->{order_by});
-    dump_object($_, { %{$params}, set => $fetch }) foreach $related_rs->all;
+    $self->dump_object($_, { %{$params}, set => $fetch }) foreach $related_rs->all;
   }
 }
 

Added: DBIx-Class-Fixtures/1.000/trunk/t/03-dump-quantity.t
===================================================================
--- DBIx-Class-Fixtures/1.000/trunk/t/03-dump-quantity.t	                        (rev 0)
+++ DBIx-Class-Fixtures/1.000/trunk/t/03-dump-quantity.t	2008-01-31 00:28:19 UTC (rev 3997)
@@ -0,0 +1,29 @@
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 10;
+use lib qw(t/lib);
+use DBICTest;
+use Path::Class;
+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 => 'quantity.json', schema => $schema, directory => 't/var/fixtures' }), 'quantity dump executed okay');
+
+# check dump is okay
+my $dir = dir('t/var/fixtures/cd');
+my @children = $dir->children;
+is(scalar(@children), 3, 'right number of cd fixtures created');
+
+foreach my $cd_fix_file (@children) {
+  my $HASH1; eval($cd_fix_file->slurp());
+  is(ref $HASH1, 'HASH', 'fixture evals into hash');
+  my $cd = $schema->resultset('CD')->find($HASH1->{cdid});
+  is_deeply({$cd->get_columns}, $HASH1, 'dumped fixture is equivalent to cd row');
+}

Added: DBIx-Class-Fixtures/1.000/trunk/t/04-dump-fetch.t
===================================================================
--- DBIx-Class-Fixtures/1.000/trunk/t/04-dump-fetch.t	                        (rev 0)
+++ DBIx-Class-Fixtures/1.000/trunk/t/04-dump-fetch.t	2008-01-31 00:28:19 UTC (rev 3997)
@@ -0,0 +1,51 @@
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 11;
+use lib qw(t/lib);
+use DBICTest;
+use Path::Class;
+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 => 'fetch.json', schema => $schema, directory => 't/var/fixtures' }), 'fetch dump executed okay');
+
+# check dump is okay
+my $dir = dir('t/var/fixtures/artist');
+my @children = $dir->children;
+is(scalar(@children), 2, 'right number of artist fixtures created');
+
+# check both artists dumped
+foreach my $id (1, 2) {
+  my $artist_fix_file = dir($dir, $id . '.fix');
+  ok(-e $artist_fix_file, "artist $id dumped okay");
+}
+
+# check all of artist1's cds were fetched
+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');
+  ok(-e $cd_fix_file, "artist1's cd rel dumped okay");
+}
+
+# check only cds matching artist2's cond were fetched
+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');
+  ok(-e $cd_fix_file, "artist2's cd rel dumped okay");
+}
+
+my $cd_dir = dir('t/var/fixtures/cd');
+ at children = $cd_dir->children;
+is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped');
+
+
+

Added: DBIx-Class-Fixtures/1.000/trunk/t/05-dump-rules.t
===================================================================
--- DBIx-Class-Fixtures/1.000/trunk/t/05-dump-rules.t	                        (rev 0)
+++ DBIx-Class-Fixtures/1.000/trunk/t/05-dump-rules.t	2008-01-31 00:28:19 UTC (rev 3997)
@@ -0,0 +1,50 @@
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 14;
+use lib qw(t/lib);
+use DBICTest;
+use Path::Class;
+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 => 'rules.json', schema => $schema, directory => 't/var/fixtures' }), 'fetch dump executed okay');
+
+# check dump is okay
+my $dir = dir('t/var/fixtures');
+my $cd_dir = dir($dir, 'cd');
+my $track_dir = dir($dir, 'track');
+
+# check only artist1's cds that matched the rule were fetched
+my $artist1 = $schema->resultset('Artist')->find(1);
+my $artist1_cds = $artist1->cds;
+while (my $a1_cd = $artist1_cds->next) {
+  my $cd_fix_file = file($cd_dir, $a1_cd->id . '.fix');
+  if ($a1_cd->tags->search({ tag => 'Cheesy' })->count) {
+    ok(-e $cd_fix_file, 'cd matching rule fetched');
+  } else {
+    isnt(-e $cd_fix_file, 1, 'cd not matching rule not fetched');
+  }
+}
+
+# check only cds' tracks that matched the rule were fetched
+foreach my $cd_fix_file ($cd_dir->children) {
+  my $HASH1; eval($cd_fix_file->slurp());
+  is(ref $HASH1, 'HASH', 'cd fixture evals into hash');
+
+  my $cd = $schema->resultset('CD')->find($HASH1->{cdid});
+  foreach my $track ($cd->tracks->all) {
+    my $track_fix_file = file($track_dir, $track->id . '.fix');
+    if ($track->get_column('position') eq 2) {
+      is(-e $track_fix_file, 1, 'track matching rule fetched');
+    } else {
+      isnt(-e $track_fix_file, 1, 'track not matching rule not fetched');
+    }
+  }
+}

Modified: DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm
===================================================================
--- DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm	2008-01-30 23:11:12 UTC (rev 3996)
+++ DBIx-Class-Fixtures/1.000/trunk/t/lib/DBICTest.pm	2008-01-31 00:28:19 UTC (rev 3997)
@@ -118,7 +118,8 @@
         [ 2, 1, "Forkful of bees", 2001 ],
         [ 3, 1, "Caterwaulin' Blues", 1997 ],
         [ 4, 2, "Generic Manufactured Singles", 2001 ],
-        [ 5, 3, "Come Be Depressed With Us", 1998 ],
+        [ 5, 2, "We like girls and stuff", 2003 ],
+        [ 6, 3, "Come Be Depressed With Us", 1998 ],
     ]);
 
     $schema->populate('Tag', [




More information about the Bast-commits mailing list