7 #----------------------------------------------------------------------
9 #----------------------------------------------------------------------
12 eval "use DBIx::Class::CDBICompat;";
14 plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
17 eval "use DBD::SQLite";
18 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 35);
26 is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri";
27 is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential";
28 is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things";
29 is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon";
30 is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical";
31 is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All";
34 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this'));
35 is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)";
39 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that'));
40 is_deeply \@groups, [qw/things/], "that (@groups)";
43 Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 });
45 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
46 ok($obj->_attribute_exists('this'), "Gets primary");
47 ok($obj->_attribute_exists('opop'), "Gets other essential");
48 ok(!$obj->_attribute_exists('that'), "But other things");
49 ok(!$obj->_attribute_exists('eep'), " nor eep");
50 ok(!$obj->_attribute_exists('orp'), " nor orp");
51 ok(!$obj->_attribute_exists('oop'), " nor oop");
53 ok(my $val = $obj->eep, 'Fetch eep');
54 ok($obj->_attribute_exists('orp'), 'Gets orp too');
55 ok(!$obj->_attribute_exists('oop'), 'But still not oop');
56 ok(!$obj->_attribute_exists('that'), 'nor that');
59 Lazy->columns(All => qw/this that eep orp oop opop/);
60 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
61 ok !$obj->_attribute_exists('oop'), " Don't have oop";
63 ok !$obj->_attribute_exists('oop'),
64 " Don't have oop - even after getting eep";
67 # Test contructor breaking.
69 eval { # Need a hashref
70 Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50);
75 Lazy->create({ this => 10, that => 20, theother => 30 });
79 eval { # Multiple false columns
80 Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 });
86 Lazy->columns( TEMP => qw(that) );
87 } "Declaring column that as TEMP but it already exists";
89 # Test that create() and update() throws out columns that changed
91 my $l = Lazy->create({
98 ok $l->db_Main->do(qq{
99 UPDATE @{[ $l->table ]}
102 }, undef, 87, $l->this);
109 ok $l->db_Main->do(qq{
110 UPDATE @{[ $l->table ]}
113 }, undef, 23, $l->this);
121 # Now again for inflated values
123 skip "Requires Date::Simple", 5 unless eval "use Date::Simple; 1; ";
125 orp => 'Date::Simple',
126 inflate => sub { Date::Simple->new($_[0] . '-01-01') },
130 my $l = Lazy->create({
136 ok $l->db_Main->do(qq{
137 UPDATE @{[ $l->table ]}
140 }, undef, 1987, $l->this);
142 is $l->orp, '1987-01-01';
145 is $l->orp, '2007-01-01'; # make sure it's inflated
148 ok $l->db_Main->do(qq{
149 UPDATE @{[ $l->table ]}
152 }, undef, 1942, $l->this);
154 is $l->orp, '1942-01-01';