1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
10 #----------------------------------------------------------------------
12 #----------------------------------------------------------------------
14 use lib 't/cdbi/testlib';
17 is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri";
18 is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential";
19 is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things";
20 is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon";
21 is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical";
22 is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All";
25 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this'));
26 is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)";
30 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that'));
31 is_deeply \@groups, [qw/things/], "that (@groups)";
34 Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 });
36 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
37 ok($obj->_attribute_exists('this'), "Gets primary");
38 ok($obj->_attribute_exists('opop'), "Gets other essential");
39 ok(!$obj->_attribute_exists('that'), "But other things");
40 ok(!$obj->_attribute_exists('eep'), " nor eep");
41 ok(!$obj->_attribute_exists('orp'), " nor orp");
42 ok(!$obj->_attribute_exists('oop'), " nor oop");
44 ok(my $val = $obj->eep, 'Fetch eep');
45 ok($obj->_attribute_exists('orp'), 'Gets orp too');
46 ok(!$obj->_attribute_exists('oop'), 'But still not oop');
47 ok(!$obj->_attribute_exists('that'), 'nor that');
50 Lazy->columns(All => qw/this that eep orp oop opop/);
51 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
52 ok !$obj->_attribute_exists('oop'), " Don't have oop";
54 ok !$obj->_attribute_exists('oop'),
55 " Don't have oop - even after getting eep";
58 # Test contructor breaking.
60 eval { # Need a hashref
61 Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50);
66 Lazy->create({ this => 10, that => 20, theother => 30 });
70 eval { # Multiple false columns
71 Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 });
77 Lazy->columns( TEMP => qw(that) );
78 } qr/Declaring column that as TEMP but it already exists/;
80 # Test that create() and update() throws out columns that changed
82 my $l = Lazy->create({
89 ok $l->db_Main->do(qq{
90 UPDATE @{[ $l->table ]}
93 }, undef, 87, $l->this);
100 ok $l->db_Main->do(qq{
101 UPDATE @{[ $l->table ]}
104 }, undef, 23, $l->this);
112 # Now again for inflated values
114 DBIx::Class::Optional::Dependencies->skip_without( 'Date::Simple>=3.03' );
116 orp => 'Date::Simple',
117 inflate => sub { Date::Simple->new($_[0] . '-01-01') },
121 my $l = Lazy->create({
127 ok $l->db_Main->do(qq{
128 UPDATE @{[ $l->table ]}
131 }, undef, 1987, $l->this);
133 is $l->orp, '1987-01-01';
136 is $l->orp, '2007-01-01'; # make sure it's inflated
139 ok $l->db_Main->do(qq{
140 UPDATE @{[ $l->table ]}
143 }, undef, 1942, $l->this);
145 is $l->orp, '1942-01-01';
151 # Test that a deleted object works
153 Lazy->search()->delete_all;
154 my $l = Lazy->create({
161 # Delete the object without it knowing.
162 Lazy->db_Main->do(qq[
164 FROM @{[ Lazy->table ]}
170 # The problem was when an object had an inflated object
171 # loaded. _flesh() would set _column_data to undef and
172 # get_column() would think nothing was there.
173 # I'm too lazy to set up the proper inflation test.
174 ok !exists $l->{_column_data}{orp};