6 #----------------------------------------------------------------------
8 #----------------------------------------------------------------------
11 use lib 't/cdbi/testlib';
15 is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri";
16 is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential";
17 is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things";
18 is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon";
19 is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical";
20 is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All";
23 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this'));
24 is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)";
28 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that'));
29 is_deeply \@groups, [qw/things/], "that (@groups)";
32 Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 });
34 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
35 ok($obj->_attribute_exists('this'), "Gets primary");
36 ok($obj->_attribute_exists('opop'), "Gets other essential");
37 ok(!$obj->_attribute_exists('that'), "But other things");
38 ok(!$obj->_attribute_exists('eep'), " nor eep");
39 ok(!$obj->_attribute_exists('orp'), " nor orp");
40 ok(!$obj->_attribute_exists('oop'), " nor oop");
42 ok(my $val = $obj->eep, 'Fetch eep');
43 ok($obj->_attribute_exists('orp'), 'Gets orp too');
44 ok(!$obj->_attribute_exists('oop'), 'But still not oop');
45 ok(!$obj->_attribute_exists('that'), 'nor that');
48 Lazy->columns(All => qw/this that eep orp oop opop/);
49 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
50 ok !$obj->_attribute_exists('oop'), " Don't have oop";
52 ok !$obj->_attribute_exists('oop'),
53 " Don't have oop - even after getting eep";
56 # Test contructor breaking.
58 eval { # Need a hashref
59 Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50);
64 Lazy->create({ this => 10, that => 20, theother => 30 });
68 eval { # Multiple false columns
69 Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 });
75 Lazy->columns( TEMP => qw(that) );
76 } qr/Declaring column that as TEMP but it already exists/;
78 # Test that create() and update() throws out columns that changed
80 my $l = Lazy->create({
87 ok $l->db_Main->do(qq{
88 UPDATE @{[ $l->table ]}
91 }, undef, 87, $l->this);
98 ok $l->db_Main->do(qq{
99 UPDATE @{[ $l->table ]}
102 }, undef, 23, $l->this);
110 # Now again for inflated values
112 skip "Requires Date::Simple 3.03", 5 unless eval "use Date::Simple 3.03; 1; ";
114 orp => 'Date::Simple',
115 inflate => sub { Date::Simple->new($_[0] . '-01-01') },
119 my $l = Lazy->create({
125 ok $l->db_Main->do(qq{
126 UPDATE @{[ $l->table ]}
129 }, undef, 1987, $l->this);
131 is $l->orp, '1987-01-01';
134 is $l->orp, '2007-01-01'; # make sure it's inflated
137 ok $l->db_Main->do(qq{
138 UPDATE @{[ $l->table ]}
141 }, undef, 1942, $l->this);
143 is $l->orp, '1942-01-01';
149 # Test that a deleted object works
151 Lazy->search()->delete_all;
152 my $l = Lazy->create({
159 # Delete the object without it knowing.
160 Lazy->db_Main->do(qq[
162 FROM @{[ Lazy->table ]}
168 # The problem was when an object had an inflated object
169 # loaded. _flesh() would set _column_data to undef and
170 # get_column() would think nothing was there.
171 # I'm too lazy to set up the proper inflation test.
172 ok !exists $l->{_column_data}{orp};