X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi%2F04-lazy.t;h=96d57433538114ea613bf32a412e52636f23b583;hb=12e7015aa9372aeaf1aaa7e125b8ac8da216deb5;hp=bb1f288b056fc076a821304b15e7ca09eb21c9ac;hpb=50891152d0b24649bfd67bdba97feec86b11c064;p=dbsrgits%2FDBIx-Class.git diff --git a/t/cdbi/04-lazy.t b/t/cdbi/04-lazy.t index bb1f288..96d5743 100644 --- a/t/cdbi/04-lazy.t +++ b/t/cdbi/04-lazy.t @@ -1,6 +1,9 @@ -#!/usr/bin/perl -w +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } +use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat'; use strict; +use warnings; + use Test::More; use Test::Warn; @@ -8,20 +11,8 @@ use Test::Warn; # Test lazy loading #---------------------------------------------------------------------- -BEGIN { - eval "use DBIx::Class::CDBICompat;"; - if ($@) { - plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required'); - next; - } - eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 36); -} - -INIT { - use lib 't/cdbi/testlib'; - use Lazy; -} +use lib 't/cdbi/testlib'; +use Lazy; is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri"; is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential"; @@ -31,13 +22,13 @@ is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical"; is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All"; { - my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this')); - is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)"; + my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this')); + is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)"; } { - my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that')); - is_deeply \@groups, [qw/things/], "that (@groups)"; + my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that')); + is_deeply \@groups, [qw/things/], "that (@groups)"; } Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 }); @@ -56,35 +47,35 @@ ok(!$obj->_attribute_exists('oop'), 'But still not oop'); ok(!$obj->_attribute_exists('that'), 'nor that'); { - Lazy->columns(All => qw/this that eep orp oop opop/); - ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary'); - ok !$obj->_attribute_exists('oop'), " Don't have oop"; - my $null = $obj->eep; - ok !$obj->_attribute_exists('oop'), - " Don't have oop - even after getting eep"; + Lazy->columns(All => qw/this that eep orp oop opop/); + ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary'); + ok !$obj->_attribute_exists('oop'), " Don't have oop"; + my $null = $obj->eep; + ok !$obj->_attribute_exists('oop'), + " Don't have oop - even after getting eep"; } # Test contructor breaking. eval { # Need a hashref - Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50); + Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50); }; ok($@, $@); eval { # False column - Lazy->create({ this => 10, that => 20, theother => 30 }); + Lazy->create({ this => 10, that => 20, theother => 30 }); }; ok($@, $@); eval { # Multiple false columns - Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 }); + Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 }); }; ok($@, $@); -warning_is { +warning_like { Lazy->columns( TEMP => qw(that) ); -} "Declaring column that as TEMP but it already exists"; +} qr/Declaring column that as TEMP but it already exists/; # Test that create() and update() throws out columns that changed { @@ -113,20 +104,20 @@ warning_is { }, undef, 23, $l->this); is $l->oop, 23; - + $l->delete; } # Now again for inflated values SKIP: { - skip "Requires Date::Simple", 5 unless eval "use Date::Simple; 1; "; + DBIx::Class::Optional::Dependencies->skip_without( 'Date::Simple>=3.03' ); Lazy->has_a( orp => 'Date::Simple', inflate => sub { Date::Simple->new($_[0] . '-01-01') }, deflate => 'format' ); - + my $l = Lazy->create({ this => 89, that => 2, @@ -138,13 +129,13 @@ SKIP: { SET orp = ? WHERE this = ? }, undef, 1987, $l->this); - + is $l->orp, '1987-01-01'; $l->orp(2007); is $l->orp, '2007-01-01'; # make sure it's inflated $l->update; - + ok $l->db_Main->do(qq{ UPDATE @{[ $l->table ]} SET orp = ? @@ -152,7 +143,7 @@ SKIP: { }, undef, 1942, $l->this); is $l->orp, '1942-01-01'; - + $l->delete; } @@ -166,19 +157,21 @@ SKIP: { oop => 3, opop => 4, }); - + # Delete the object without it knowing. Lazy->db_Main->do(qq[ DELETE FROM @{[ Lazy->table ]} WHERE this = 99 ]); - + $l->eep; - + # The problem was when an object had an inflated object # loaded. _flesh() would set _column_data to undef and # get_column() would think nothing was there. # I'm too lazy to set up the proper inflation test. ok !exists $l->{_column_data}{orp}; } + +done_testing;