[Bast-commits] r4130 - in
DBIx-Class-Fixtures/1.001/branches/includes: lib/DBIx/Class t
t/var/configs
captainL at dev.catalyst.perl.org
captainL at dev.catalyst.perl.org
Wed Mar 5 14:42:47 GMT 2008
Author: captainL
Date: 2008-03-05 14:42:44 +0000 (Wed, 05 Mar 2008)
New Revision: 4130
Added:
DBIx-Class-Fixtures/1.001/branches/includes/t/08-dump-includes.t
DBIx-Class-Fixtures/1.001/branches/includes/t/var/configs/includes.json
Modified:
DBIx-Class-Fixtures/1.001/branches/includes/lib/DBIx/Class/Fixtures.pm
Log:
test passes
Modified: DBIx-Class-Fixtures/1.001/branches/includes/lib/DBIx/Class/Fixtures.pm
===================================================================
--- DBIx-Class-Fixtures/1.001/branches/includes/lib/DBIx/Class/Fixtures.pm 2008-03-05 12:59:16 UTC (rev 4129)
+++ DBIx-Class-Fixtures/1.001/branches/includes/lib/DBIx/Class/Fixtures.pm 2008-03-05 14:42:44 UTC (rev 4130)
@@ -409,16 +409,40 @@
my $config_file;
my $config;
if ($params->{config}) {
+ #read config
$config_file = file($self->config_dir, $params->{config});
unless (-e $config_file) {
return DBIx::Class::Exception->throw('config does not exist at ' . $config_file);
}
+ $config = Config::Any::JSON->load($config_file);
- $config = Config::Any::JSON->load($config_file);
+ #process includes
+ if ($config->{includes}) {
+ $self->msg($config->{includes});
+ unless (ref $config->{includes} eq 'ARRAY') {
+ return DBIx::Class::Exception->throw('includes params of config must be an array ref of hashrefs');
+ }
+ foreach my $include_config (@{$config->{includes}}) {
+ unless ((ref $include_config eq 'HASH') && $include_config->{file}) {
+ return DBIx::Class::Exception->throw('includes params of config must be an array ref of hashrefs');
+ }
+
+ my $include_file = file($self->config_dir, $include_config->{file});
+ unless (-e $include_file) {
+ return DBIx::Class::Exception->throw('config does not exist at ' . $include_file);
+ }
+ my $include = Config::Any::JSON->load($include_file);
+ $self->msg($include);
+ $config = merge( $config, $include );
+ }
+ delete $config->{includes};
+ }
+
+ # validate config
unless ($config && $config->{sets} && ref $config->{sets} eq 'ARRAY' && scalar(@{$config->{sets}})) {
return DBIx::Class::Exception->throw('config has no sets');
}
-
+
$config->{might_have} = { fetch => 0 } unless (exists $config->{might_have});
$config->{has_many} = { fetch => 0 } unless (exists $config->{has_many});
$config->{belongs_to} = { fetch => 1 } unless (exists $config->{belongs_to});
@@ -793,7 +817,6 @@
my $self = shift;
my $subject = shift || return;
my $level = shift || 1;
-
return unless $self->debug >= $level;
if (ref $subject) {
print Dumper($subject);
Added: DBIx-Class-Fixtures/1.001/branches/includes/t/08-dump-includes.t
===================================================================
--- DBIx-Class-Fixtures/1.001/branches/includes/t/08-dump-includes.t (rev 0)
+++ DBIx-Class-Fixtures/1.001/branches/includes/t/08-dump-includes.t 2008-03-05 14:42:44 UTC (rev 4130)
@@ -0,0 +1,31 @@
+#!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 => 'includes.json', schema => $schema, directory => 't/var/fixtures' }), 'simple dump executed okay');
+
+# check dump is okay
+my $producer_dir = dir('t/var/fixtures/producer');
+ok(-e $producer_dir, 'producer directory created');
+
+my @producer_children = $producer_dir->children;
+is(scalar(@producer_children), 1, 'right number of fixtures created');
+
+my $artist_dir = dir('t/var/fixtures/artist');
+ok(-e $artist_dir, 'artist directory created');
+
+my @artist_children = $artist_dir->children;
+is(scalar(@artist_children), 1, 'right number of fixtures created');
+
Added: DBIx-Class-Fixtures/1.001/branches/includes/t/var/configs/includes.json
===================================================================
--- DBIx-Class-Fixtures/1.001/branches/includes/t/var/configs/includes.json (rev 0)
+++ DBIx-Class-Fixtures/1.001/branches/includes/t/var/configs/includes.json 2008-03-05 14:42:44 UTC (rev 4130)
@@ -0,0 +1,15 @@
+{
+ might_have: {
+ fetch: 0
+ },
+ has_many: {
+ fetch: 0
+ },
+ sets: [{
+ class: 'Producer',
+ quantity: 1
+ }],
+ includes: [{
+ file: 'simple.json'
+ }]
+}
More information about the Bast-commits
mailing list