handle the throw_exception bit. Drop DBIx::Class::Exception
[dbsrgits/DBIx-Class.git] / t / cdbi-t / 04-lazy.t
CommitLineData
510ca912 1use strict;
2use Test::More;
3
4#----------------------------------------------------------------------
5# Test lazy loading
6#----------------------------------------------------------------------
7
8BEGIN {
9 eval "use DBD::SQLite";
10 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 25);
11}
12
13INIT {
14 use lib 't/testlib';
15 use Lazy;
16}
17
18is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri";
19is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential";
20is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things";
21is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon";
22is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical";
23is_deeply [ sort Lazy->columns('All') ], [qw/eep oop opop orp that this/], "All";
24
25{
26 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('this'));
27 is_deeply [ sort @groups ], [sort qw/things Essential Primary/], "this (@groups)";
28}
29
30{
31 my @groups = Lazy->__grouper->groups_for(Lazy->find_column('that'));
32 is_deeply \@groups, [qw/things/], "that (@groups)";
33}
34
35Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 });
36
37ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
38ok($obj->_attribute_exists('this'), "Gets primary");
39ok($obj->_attribute_exists('opop'), "Gets other essential");
40ok(!$obj->_attribute_exists('that'), "But other things");
41ok(!$obj->_attribute_exists('eep'), " nor eep");
42ok(!$obj->_attribute_exists('orp'), " nor orp");
43ok(!$obj->_attribute_exists('oop'), " nor oop");
44
45ok(my $val = $obj->eep, 'Fetch eep');
46ok($obj->_attribute_exists('orp'), 'Gets orp too');
47ok(!$obj->_attribute_exists('oop'), 'But still not oop');
48ok(!$obj->_attribute_exists('that'), 'nor that');
49
50{
51 Lazy->columns(All => qw/this that eep orp oop opop/);
52 ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary');
53 ok !$obj->_attribute_exists('oop'), " Don't have oop";
54 my $null = $obj->eep;
55 ok !$obj->_attribute_exists('oop'),
56 " Don't have oop - even after getting eep";
57}
58
59# Test contructor breaking.
60
61eval { # Need a hashref
62 Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50);
63};
64ok($@, $@);
65
66eval { # False column
67 Lazy->create({ this => 10, that => 20, theother => 30 });
68};
69ok($@, $@);
70
71eval { # Multiple false columns
72 Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 });
73};
74ok($@, $@);
75