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