scalar refs now handled on set conds as well as related conds
Luke Saunders [Fri, 25 Apr 2008 16:15:50 +0000 (16:15 +0000)]
META.yml [deleted file]
lib/DBIx/Class/Fixtures.pm
t/09-dump-scalar-ref.t [new file with mode: 0644]
t/var/DBIxClass.db
t/var/configs/scalar_ref.json [new file with mode: 0644]
t/var/fixtures/_dumper_version [deleted file]
t/var/fixtures/artist/1.fix [deleted file]

diff --git a/META.yml b/META.yml
deleted file mode 100644 (file)
index b2b99d0..0000000
--- a/META.yml
+++ /dev/null
@@ -1,45 +0,0 @@
---- 
-abstract: ~
-author: 
-  - Luke Saunders <luke@shadowcatsystems.co.uk>
-build_requires: 
-  Test::More: 0.7
-distribution_type: module
-generated_by: Module::Install version 0.68
-license: perl
-meta-spec: 
-  url: http://module-build.sourceforge.net/META-spec-v1.3.html
-  version: 1.3
-name: DBIx-Class-Fixtures
-no_index: 
-  directory: 
-    - inc
-    - t
-provides: 
-  DBIx::Class::Fixtures: 
-    file: lib/DBIx/Class/Fixtures.pm
-    version: 1.000001
-  DBIx::Class::Fixtures::Schema: 
-    file: lib/DBIx/Class/Fixtures/Schema.pm
-  DBIx::Class::Fixtures::SchemaVersioned: 
-    file: lib/DBIx/Class/Fixtures/SchemaVersioned.pm
-    version: 0
-  DBIx::Class::Fixtures::Versioned: 
-    file: lib/DBIx/Class/Fixtures/Versioned.pm
-requires: 
-  Class::Accessor::Grouped: 0.06
-  Config::Any: 0.08
-  DBIx::Class: 0.08
-  DBIx::Class::Schema::Loader: 0.04004
-  Data::Dump::Streamer: 2.05
-  Data::Visitor: 0.15
-  DateTime: 0.41
-  DateTime::Format::MySQL: 0.04
-  File::Copy::Recursive: 0.35
-  File::Slurp: 999.13
-  Hash::Merge: 0.1
-  JSON::Syck: 0.26
-  Path::Class: 0.16
-  perl: 5.6.1
-tests: t/*.t
-version: 1.000001
index 94e3127..55f2341 100644 (file)
@@ -191,7 +191,7 @@ fixture is imported the field will be set to 5 days in the past relative to the
 Specifies whether to automatically dump might_have relationships. Should be a hash with one attribute - fetch. Set fetch to 1 or 0.
 
     {
-        might_have: [{
+        might_have: {
             fetch: 1
         },
         sets: [{
@@ -501,6 +501,13 @@ sub dump {
 
     # fetch objects
     my $rs = $schema->resultset($source->{class});
+
+    if ($source->{cond} and ref $source->{cond} eq 'HASH') {
+      # if value starts with / assume it's meant to be passed as a scalar ref to dbic
+      # ideally this would substitute deeply
+      $source->{cond} = { map { $_ => ($source->{cond}->{$_} =~ s/^\\//) ? \$source->{cond}->{$_} : $source->{cond}->{$_} } keys %{$source->{cond}} };
+    }
+
     $rs = $rs->search($source->{cond}, { join => $source->{join} }) if ($source->{cond});
     $self->msg("- dumping $source->{class}");
     my @objects;
diff --git a/t/09-dump-scalar-ref.t b/t/09-dump-scalar-ref.t
new file mode 100644 (file)
index 0000000..fe5450b
--- /dev/null
@@ -0,0 +1,44 @@
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 7;
+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 => 'scalar_ref.json', schema => $schema, directory => 't/var/fixtures' }), 'simple dump executed okay');
+
+{
+  # check dump is okay
+  my $dir = dir('t/var/fixtures/artist');
+  my @children = $dir->children;
+  is(scalar(@children), 1, 'right number of fixtures created');
+  
+  my $fix_file = $children[0];
+  my $HASH1; eval($fix_file->slurp());
+
+  is($HASH1->{name}, 'We Are Goth', 'correct artist dumped');
+}
+
+{
+  # check dump is okay
+  my $dir = dir('t/var/fixtures/cd');
+  my @children = $dir->children;
+  is(scalar(@children), 1, 'right number of fixtures created');
+  
+  my $fix_file = $children[0];
+  my $HASH1; eval($fix_file->slurp());
+
+  is($HASH1->{title}, 'Come Be Depressed With Us', 'correct cd dumped');
+}
+
+
index cb2ed5c..c591fb9 100644 (file)
Binary files a/t/var/DBIxClass.db and b/t/var/DBIxClass.db differ
diff --git a/t/var/configs/scalar_ref.json b/t/var/configs/scalar_ref.json
new file mode 100644 (file)
index 0000000..a1bd2f6
--- /dev/null
@@ -0,0 +1,17 @@
+{
+        might_have: {
+            fetch: 0
+        },
+        has_many: {
+            fetch: 0
+        },
+        sets: [{
+            class: 'Artist',
+            cond: { me.name: '\= "We Are Goth"' },
+            quantity: all,
+            fetch: [{ 
+                rel: 'cds',
+                cond: { 'me.title': '\LIKE "%with us"' }
+            }]
+        }]
+}
\ No newline at end of file
diff --git a/t/var/fixtures/_dumper_version b/t/var/fixtures/_dumper_version
deleted file mode 100644 (file)
index 3985b9c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-1.000001
\ No newline at end of file
diff --git a/t/var/fixtures/artist/1.fix b/t/var/fixtures/artist/1.fix
deleted file mode 100755 (executable)
index cd82bac..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-$HASH1 = {
-           artistid => 1,
-           name     => 'Caterwauler McCrae'
-         };