added dbi_options attribute
|
1 |
use Test::More tests => 12; |
packaging one directory
|
2 |
use strict; |
3 |
use warnings; |
|
4 | ||
5 |
use DBIx::Custom; |
|
fixed tests
|
6 |
use DBIx::Custom::QueryBuilder; |
packaging one directory
|
7 | |
8 |
# Function for test name |
|
9 |
my $test; |
|
10 |
sub test { |
|
11 |
$test = shift; |
|
12 |
} |
|
13 | ||
14 |
# Variables for test |
|
15 |
my $dbi; |
|
removed DBIx::Custom::Query ...
|
16 |
my $query_builder; |
packaging one directory
|
17 | |
18 |
test 'Constructor'; |
|
removed DBIx::Custom::Query ...
|
19 |
$query_builder = DBIx::Custom::QueryBuilder->new; |
packaging one directory
|
20 |
$dbi = DBIx::Custom->new( |
21 |
user => 'a', |
|
22 |
password => 'b', |
|
23 |
data_source => 'c', |
|
24 |
filters => { |
|
25 |
f => 3, |
|
26 |
}, |
|
cleanup
|
27 |
default_bind_filter => 'f', |
28 |
default_fetch_filter => 'g', |
|
packaging one directory
|
29 |
result_class => 'g', |
removed DBIx::Custom::Query ...
|
30 |
query_builder => $query_builder, |
packaging one directory
|
31 |
); |
added dbi_options attribute
|
32 |
is_deeply($dbi,{user => 'a', password => 'b', data_source => 'c', |
update document
|
33 |
filters => {f => 3}, default_bind_filter => 'f', |
cleanup
|
34 |
default_fetch_filter => 'g', result_class => 'g', |
removed DBIx::Custom::Query ...
|
35 |
query_builder => $query_builder}, $test); |
packaging one directory
|
36 |
isa_ok($dbi, 'DBIx::Custom'); |
37 | ||
38 | ||
39 |
test 'Sub class constructor'; |
|
40 |
{ |
|
41 |
package DBIx::Custom::T1; |
|
42 |
use base 'DBIx::Custom'; |
|
43 |
|
|
44 |
} |
|
45 |
$dbi = DBIx::Custom::T1->new( |
|
46 |
filters => { |
|
47 |
fo => 30, |
|
48 |
}, |
|
49 |
); |
|
50 |
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); |
|
51 | ||
52 |
test 'Sub sub class constructor default'; |
|
53 |
{ |
|
54 |
package DBIx::Custom::T1_2; |
|
55 |
use base 'DBIx::Custom::T1'; |
|
56 |
} |
|
57 |
$dbi = DBIx::Custom::T1_2->new; |
|
58 |
isa_ok($dbi, 'DBIx::Custom::T1_2'); |
|
59 | ||
60 | ||
61 |
test 'Customized sub class constructor default'; |
|
62 |
{ |
|
63 |
package DBIx::Custom::T1_3; |
|
64 |
use base 'DBIx::Custom::T1'; |
|
65 |
|
|
66 |
} |
|
67 |
$dbi = DBIx::Custom::T1_3->new; |
|
68 |
isa_ok($dbi, 'DBIx::Custom::T1_3'); |
|
69 | ||
70 | ||
71 |
test 'Customized sub class constructor'; |
|
72 |
$dbi = DBIx::Custom::T1_3->new( |
|
73 |
filters => { |
|
74 |
f => 3, |
|
75 |
}, |
|
76 |
); |
|
catch up with Object::Simple...
|
77 |
is_deeply($dbi->filters, {f => 3}, "$test : filters"); |
packaging one directory
|
78 |
isa_ok($dbi, 'DBIx::Custom'); |
79 | ||
80 | ||
some changed
|
81 |
test 'register_filters'; |
packaging one directory
|
82 |
$dbi = DBIx::Custom->new; |
some changed
|
83 |
$dbi->register_filter(a => sub {1}); |
packaging one directory
|
84 |
is($dbi->filters->{a}->(), 1, $test); |
changed argument of tag proc...
|
85 |
$dbi->register_filter({b => sub {2}}); |
86 |
is($dbi->filters->{b}->(), 2, $test); |
|
87 | ||
88 | ||
added experimental expand me...
|
89 |
test 'expand'; |
90 |
{ |
|
91 |
$dbi = DBIx::Custom->new; |
|
92 |
my $source = {books => {title => 'Perl', author => 'Ken'}}; |
|
93 |
is_deeply({$dbi->expand($source)}, |
|
94 |
{'books.title' => 'Perl', 'books.author' => 'Ken'}); |
|
95 |
} |
|
96 |
{ |
|
97 |
$dbi = DBIx::Custom->new; |
|
98 |
my %source = (books => {title => 'Perl', author => 'Ken'}); |
|
99 |
is_deeply({$dbi->expand(%source)}, |
|
100 |
{'books.title' => 'Perl', 'books.author' => 'Ken'}); |
|
101 |
} |
|
102 | ||
added dbi_options attribute
|
103 |
test 'invalid attribute name'; |
104 |
eval {$dbi = DBIx::Custom->new(a => 1) }; |
|
105 |
like ($@, qr/"a" is invalid attribute name/, $test); |