6 #----------------------------------------------------------------------
8 #----------------------------------------------------------------------
10 use lib 't/cdbi/testlib';
13 is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri";
14 is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential";
15 is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things";
16 is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon";
17 is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical";
18 is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All";
21 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this'));
22 is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)";
26 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that'));
27 is_deeply \@groups, [qw/things/], "that (@groups)";
30 Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 });
32 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
33 ok($obj->_attribute_exists('this'), "Gets primary");
34 ok($obj->_attribute_exists('opop'), "Gets other essential");
35 ok(!$obj->_attribute_exists('that'), "But other things");
36 ok(!$obj->_attribute_exists('eep'), " nor eep");
37 ok(!$obj->_attribute_exists('orp'), " nor orp");
38 ok(!$obj->_attribute_exists('oop'), " nor oop");
40 ok(my $val = $obj->eep, 'Fetch eep');
41 ok($obj->_attribute_exists('orp'), 'Gets orp too');
42 ok(!$obj->_attribute_exists('oop'), 'But still not oop');
43 ok(!$obj->_attribute_exists('that'), 'nor that');
46 Lazy->columns(All => qw/this that eep orp oop opop/);
47 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
48 ok !$obj->_attribute_exists('oop'), " Don't have oop";
50 ok !$obj->_attribute_exists('oop'),
51 " Don't have oop - even after getting eep";
54 # Test contructor breaking.
56 eval { # Need a hashref
57 Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50);
62 Lazy->create({ this => 10, that => 20, theother => 30 });
66 eval { # Multiple false columns
67 Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 });
73 Lazy->columns( TEMP => qw(that) );
74 } qr/Declaring column that as TEMP but it already exists/;
76 # Test that create() and update() throws out columns that changed
78 my $l = Lazy->create({
85 ok $l->db_Main->do(qq{
86 UPDATE @{[ $l->table ]}
89 }, undef, 87, $l->this);
96 ok $l->db_Main->do(qq{
97 UPDATE @{[ $l->table ]}
100 }, undef, 23, $l->this);
108 # Now again for inflated values
110 DBIx::Class::Optional::Dependencies->skip_without( 'Date::Simple>=3.03' );
112 orp => 'Date::Simple',
113 inflate => sub { Date::Simple->new($_[0] . '-01-01') },
117 my $l = Lazy->create({
123 ok $l->db_Main->do(qq{
124 UPDATE @{[ $l->table ]}
127 }, undef, 1987, $l->this);
129 is $l->orp, '1987-01-01';
132 is $l->orp, '2007-01-01'; # make sure it's inflated
135 ok $l->db_Main->do(qq{
136 UPDATE @{[ $l->table ]}
139 }, undef, 1942, $l->this);
141 is $l->orp, '1942-01-01';
147 # Test that a deleted object works
149 Lazy->search()->delete_all;
150 my $l = Lazy->create({
157 # Delete the object without it knowing.
158 Lazy->db_Main->do(qq[
160 FROM @{[ Lazy->table ]}
166 # The problem was when an object had an inflated object
167 # loaded. _flesh() would set _column_data to undef and
168 # get_column() would think nothing was there.
169 # I'm too lazy to set up the proper inflation test.
170 ok !exists $l->{_column_data}{orp};