Merge branch 'topic/parallelize-tests' of https://github.com/RsrchBoy/DBIx-Class...
John Napiorkowski [Tue, 21 Apr 2015 19:48:09 +0000 (14:48 -0500)]
t/07-dump-all.t
t/19-complex-hierarchy.t [new file with mode: 0644]
t/lib/DBICTest.pm
t/lib/DBICTest/Schema.pm
t/lib/DBICTest/Schema/Artist.pm
t/lib/DBICTest/Schema/Artist/WashedUp.pm [new file with mode: 0644]
t/lib/mysql.sql
t/lib/sqlite.sql
t/var/configs/washed-up.json [new file with mode: 0644]

index 482ad41..111bfd6 100644 (file)
@@ -11,7 +11,7 @@ use IO::All;
 
 my $tempdir = tempdir;
 use if $^O eq 'MSWin32','Devel::Confess';
-plan tests => 16;
+plan tests => 18;
 
 # set up and populate schema
 ok(my $schema = DBICTest->init_schema(db_dir => $tempdir, ), 'got schema');
diff --git a/t/19-complex-hierarchy.t b/t/19-complex-hierarchy.t
new file mode 100644 (file)
index 0000000..8fa5598
--- /dev/null
@@ -0,0 +1,49 @@
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 7;
+use lib qw(t/lib);
+use DBICTest;
+use Path::Class;
+use Data::Dumper;
+use IO::All;
+
+use if $^O eq 'MSWin32','Devel::Confess';
+# set up and populate schema
+ok(my $schema = DBICTest->init_schema(), 'got schema');
+
+my $config_dir = io->catfile(qw't var configs')->name;
+
+# Add washedup
+
+ok my $artist = $schema->resultset("Artist")->find(1);
+ok my $washed_up = $artist->create_related('washed_up', +{});
+ok $washed_up->fk_artistid;
+
+
+ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
+ok($fixtures->dump({
+        config => {
+            "might_have" => {
+                "fetch" => 0
+            },
+            "has_many" => {
+                "fetch" => 0
+            },
+            "sets" => [{
+                "class" => "Artist::WashedUp",
+                "quantity" => 1
+            }]
+        },
+        schema => $schema, 
+        directory => io->catfile(qw't var fixtures')->name,
+    }), 'simple dump executed okay');
+
+ok(
+  $fixtures->dump({
+    config => 'washed-up.json',
+    schema => $schema, 
+    directory => io->catfile(qw't var fixtures')->name,
+  }));
+
+
index 2bf19f8..db22971 100755 (executable)
@@ -156,6 +156,11 @@ sub populate_schema {
         [ 32948, 'Big PK' ],
     ]);
 
+    $schema->populate('Artist::WashedUp', [
+        [ qw/fk_artistid/ ],
+        [ 2 ],
+    ]);
+
     $schema->populate('CD', [
         [ qw/cdid artist title year/ ],
         [ 1, 1, "Spoonful of bees", 1999 ],
index 350eecc..23e03d6 100644 (file)
@@ -5,6 +5,6 @@ use base qw/DBIx::Class::Schema/;
 
 no warnings qw/qw/;
 
-__PACKAGE__->load_classes(qw/Artist CD Track Tag Producer CD_to_Producer/);
+__PACKAGE__->load_classes(qw/Artist Artist::WashedUp CD Track Tag Producer CD_to_Producer/);
 
 1;
index f6d8180..3925cd6 100644 (file)
@@ -22,6 +22,11 @@ __PACKAGE__->has_many(
     { order_by => 'year' },
 );
 
+__PACKAGE__->might_have(
+    washed_up => 'DBICTest::Schema::Artist::WashedUp',
+    {'foreign.fk_artistid' => 'self.artistid'},
+);
+
 sub new {
        my ( $class, $args ) = @_;
 
diff --git a/t/lib/DBICTest/Schema/Artist/WashedUp.pm b/t/lib/DBICTest/Schema/Artist/WashedUp.pm
new file mode 100644 (file)
index 0000000..998139f
--- /dev/null
@@ -0,0 +1,19 @@
+package # hide from PAUSE 
+    DBICTest::Schema::Artist::WashedUp;
+
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('artist_washed_up');
+__PACKAGE__->add_columns(
+  'fk_artistid' => {
+    data_type => 'integer',
+  },
+);
+
+__PACKAGE__->set_primary_key('fk_artistid');
+__PACKAGE__->belongs_to(
+  'artist', 'DBICTest::Schema::Artist',
+  { 'foreign.artistid' => 'self.fk_artistid' }
+);
+
+1;
index ca1b034..47bad04 100644 (file)
@@ -17,6 +17,13 @@ CREATE TABLE artist (
   name varchar(100)
 );
 
+--
+-- Table: artist_washed_up
+--
+DROP TABLE IF EXISTS artist_washed_up;
+CREATE TABLE artist_washed_up (
+  fk_artistid INTEGER PRIMARY KEY NOT NULL
+);
 
 --
 -- Table: cd
index 1e21627..f863b03 100644 (file)
@@ -21,6 +21,12 @@ CREATE TABLE artist (
   name varchar(100)
 );
 
+--
+-- Table: artist_washed_up
+--
+CREATE TABLE artist_washed_up (
+  fk_artistid INTEGER PRIMARY KEY NOT NULL
+);
 
 --
 -- Table: cd
diff --git a/t/var/configs/washed-up.json b/t/var/configs/washed-up.json
new file mode 100644 (file)
index 0000000..ffcdc50
--- /dev/null
@@ -0,0 +1,18 @@
+{
+   "might_have" : {
+      "fetch" : 0
+   },
+   "belongs_to" : {
+      "fetch" : 0
+   },
+   "sets" : [
+      {
+         "class" : "Artist::WashedUp",
+         "quantity" : "all"
+      }
+   ],
+   "has_many" : {
+      "fetch" : 0
+   }
+}
+