6 #----------------------------------------------------------------------
8 #----------------------------------------------------------------------
11 eval "use DBIx::Class::CDBICompat;";
13 ? (skip_all => 'Class::Trigger and DBIx::ContextualFetch required')
19 use lib 't/cdbi/testlib';
23 is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri";
24 is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential";
25 is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things";
26 is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon";
27 is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical";
28 is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All";
31 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this'));
32 is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)";
36 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that'));
37 is_deeply \@groups, [qw/things/], "that (@groups)";
40 Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 });
42 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
43 ok($obj->_attribute_exists('this'), "Gets primary");
44 ok($obj->_attribute_exists('opop'), "Gets other essential");
45 ok(!$obj->_attribute_exists('that'), "But other things");
46 ok(!$obj->_attribute_exists('eep'), " nor eep");
47 ok(!$obj->_attribute_exists('orp'), " nor orp");
48 ok(!$obj->_attribute_exists('oop'), " nor oop");
50 ok(my $val = $obj->eep, 'Fetch eep');
51 ok($obj->_attribute_exists('orp'), 'Gets orp too');
52 ok(!$obj->_attribute_exists('oop'), 'But still not oop');
53 ok(!$obj->_attribute_exists('that'), 'nor that');
56 Lazy->columns(All => qw/this that eep orp oop opop/);
57 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
58 ok !$obj->_attribute_exists('oop'), " Don't have oop";
60 ok !$obj->_attribute_exists('oop'),
61 " Don't have oop - even after getting eep";
64 # Test contructor breaking.
66 eval { # Need a hashref
67 Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50);
72 Lazy->create({ this => 10, that => 20, theother => 30 });
76 eval { # Multiple false columns
77 Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 });
83 Lazy->columns( TEMP => qw(that) );
84 } qr/Declaring column that as TEMP but it already exists/;
86 # Test that create() and update() throws out columns that changed
88 my $l = Lazy->create({
95 ok $l->db_Main->do(qq{
96 UPDATE @{[ $l->table ]}
99 }, undef, 87, $l->this);
106 ok $l->db_Main->do(qq{
107 UPDATE @{[ $l->table ]}
110 }, undef, 23, $l->this);
118 # Now again for inflated values
120 skip "Requires Date::Simple 3.03", 5 unless eval "use Date::Simple 3.03; 1; ";
122 orp => 'Date::Simple',
123 inflate => sub { Date::Simple->new($_[0] . '-01-01') },
127 my $l = Lazy->create({
133 ok $l->db_Main->do(qq{
134 UPDATE @{[ $l->table ]}
137 }, undef, 1987, $l->this);
139 is $l->orp, '1987-01-01';
142 is $l->orp, '2007-01-01'; # make sure it's inflated
145 ok $l->db_Main->do(qq{
146 UPDATE @{[ $l->table ]}
149 }, undef, 1942, $l->this);
151 is $l->orp, '1942-01-01';
157 # Test that a deleted object works
159 Lazy->search()->delete_all;
160 my $l = Lazy->create({
167 # Delete the object without it knowing.
168 Lazy->db_Main->do(qq[
170 FROM @{[ Lazy->table ]}
176 # The problem was when an object had an inflated object
177 # loaded. _flesh() would set _column_data to undef and
178 # get_column() would think nothing was there.
179 # I'm too lazy to set up the proper inflation test.
180 ok !exists $l->{_column_data}{orp};