1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
9 #----------------------------------------------------------------------
11 #----------------------------------------------------------------------
13 use lib 't/cdbi/testlib';
16 is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri";
17 is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential";
18 is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things";
19 is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon";
20 is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical";
21 is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All";
24 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this'));
25 is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)";
29 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that'));
30 is_deeply \@groups, [qw/things/], "that (@groups)";
33 Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 });
35 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
36 ok($obj->_attribute_exists('this'), "Gets primary");
37 ok($obj->_attribute_exists('opop'), "Gets other essential");
38 ok(!$obj->_attribute_exists('that'), "But other things");
39 ok(!$obj->_attribute_exists('eep'), " nor eep");
40 ok(!$obj->_attribute_exists('orp'), " nor orp");
41 ok(!$obj->_attribute_exists('oop'), " nor oop");
43 ok(my $val = $obj->eep, 'Fetch eep');
44 ok($obj->_attribute_exists('orp'), 'Gets orp too');
45 ok(!$obj->_attribute_exists('oop'), 'But still not oop');
46 ok(!$obj->_attribute_exists('that'), 'nor that');
49 Lazy->columns(All => qw/this that eep orp oop opop/);
50 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
51 ok !$obj->_attribute_exists('oop'), " Don't have oop";
53 ok !$obj->_attribute_exists('oop'),
54 " Don't have oop - even after getting eep";
57 # Test contructor breaking.
59 eval { # Need a hashref
60 Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50);
65 Lazy->create({ this => 10, that => 20, theother => 30 });
69 eval { # Multiple false columns
70 Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 });
76 Lazy->columns( TEMP => qw(that) );
77 } qr/Declaring column that as TEMP but it already exists/;
79 # Test that create() and update() throws out columns that changed
81 my $l = Lazy->create({
88 ok $l->db_Main->do(qq{
89 UPDATE @{[ $l->table ]}
92 }, undef, 87, $l->this);
99 ok $l->db_Main->do(qq{
100 UPDATE @{[ $l->table ]}
103 }, undef, 23, $l->this);
111 # Now again for inflated values
113 DBIx::Class::Optional::Dependencies->skip_without( 'Date::Simple>=3.03' );
115 orp => 'Date::Simple',
116 inflate => sub { Date::Simple->new($_[0] . '-01-01') },
120 my $l = Lazy->create({
126 ok $l->db_Main->do(qq{
127 UPDATE @{[ $l->table ]}
130 }, undef, 1987, $l->this);
132 is $l->orp, '1987-01-01';
135 is $l->orp, '2007-01-01'; # make sure it's inflated
138 ok $l->db_Main->do(qq{
139 UPDATE @{[ $l->table ]}
142 }, undef, 1942, $l->this);
144 is $l->orp, '1942-01-01';
150 # Test that a deleted object works
152 Lazy->search()->delete_all;
153 my $l = Lazy->create({
160 # Delete the object without it knowing.
161 Lazy->db_Main->do(qq[
163 FROM @{[ Lazy->table ]}
169 # The problem was when an object had an inflated object
170 # loaded. _flesh() would set _column_data to undef and
171 # get_column() would think nothing was there.
172 # I'm too lazy to set up the proper inflation test.
173 ok !exists $l->{_column_data}{orp};