Commit | Line | Data |
510ca912 |
1 | use strict; |
2 | use Test::More; |
3 | |
289ba852 |
4 | BEGIN { |
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 | |
13 | BEGIN { |
14 | eval "use DBD::SQLite"; |
15 | plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 25); |
16 | } |
17 | |
18 | INIT { |
19 | use lib 't/testlib'; |
20 | use Lazy; |
21 | } |
22 | |
23 | is_deeply [ Lazy->columns('Primary') ], [qw/this/], "Pri"; |
24 | is_deeply [ sort Lazy->columns('Essential') ], [qw/opop this/], "Essential"; |
25 | is_deeply [ sort Lazy->columns('things') ], [qw/that this/], "things"; |
26 | is_deeply [ sort Lazy->columns('horizon') ], [qw/eep orp/], "horizon"; |
27 | is_deeply [ sort Lazy->columns('vertical') ], [qw/oop opop/], "vertical"; |
28 | is_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 | |
40 | Lazy->create({ this => 1, that => 2, oop => 3, opop => 4, eep => 5 }); |
41 | |
42 | ok(my $obj = Lazy->retrieve(1), 'Retrieve by Primary'); |
43 | ok($obj->_attribute_exists('this'), "Gets primary"); |
44 | ok($obj->_attribute_exists('opop'), "Gets other essential"); |
45 | ok(!$obj->_attribute_exists('that'), "But other things"); |
46 | ok(!$obj->_attribute_exists('eep'), " nor eep"); |
47 | ok(!$obj->_attribute_exists('orp'), " nor orp"); |
48 | ok(!$obj->_attribute_exists('oop'), " nor oop"); |
49 | |
50 | ok(my $val = $obj->eep, 'Fetch eep'); |
51 | ok($obj->_attribute_exists('orp'), 'Gets orp too'); |
52 | ok(!$obj->_attribute_exists('oop'), 'But still not oop'); |
53 | ok(!$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 | |
66 | eval { # Need a hashref |
67 | Lazy->create(this => 10, that => 20, oop => 30, opop => 40, eep => 50); |
68 | }; |
69 | ok($@, $@); |
70 | |
71 | eval { # False column |
72 | Lazy->create({ this => 10, that => 20, theother => 30 }); |
73 | }; |
74 | ok($@, $@); |
75 | |
76 | eval { # Multiple false columns |
77 | Lazy->create({ this => 10, that => 20, theother => 30, andanother => 40 }); |
78 | }; |
79 | ok($@, $@); |
80 | |