DBIx-Custom / t / dbix-custom-core.t /
Newer Older
105 lines | 2.412kb
added dbi_options attribute
kimoto authored on 2010-12-20
1
use Test::More tests => 12;
packaging one directory
yuki-kimoto authored on 2009-11-16
2
use strict;
3
use warnings;
4

            
5
use DBIx::Custom;
fixed tests
yuki-kimoto authored on 2010-08-06
6
use DBIx::Custom::QueryBuilder;
packaging one directory
yuki-kimoto authored on 2009-11-16
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 ...
yuki-kimoto authored on 2010-08-12
16
my $query_builder;
packaging one directory
yuki-kimoto authored on 2009-11-16
17

            
18
test 'Constructor';
removed DBIx::Custom::Query ...
yuki-kimoto authored on 2010-08-12
19
$query_builder = DBIx::Custom::QueryBuilder->new;
packaging one directory
yuki-kimoto authored on 2009-11-16
20
$dbi = DBIx::Custom->new(
21
    user => 'a',
22
    password => 'b',
23
    data_source => 'c',
24
    filters => {
25
        f => 3,
26
    },
cleanup
yuki-kimoto authored on 2010-04-28
27
    default_bind_filter => 'f',
28
    default_fetch_filter => 'g',
packaging one directory
yuki-kimoto authored on 2009-11-16
29
    result_class => 'g',
removed DBIx::Custom::Query ...
yuki-kimoto authored on 2010-08-12
30
    query_builder => $query_builder,
packaging one directory
yuki-kimoto authored on 2009-11-16
31
);
added dbi_options attribute
kimoto authored on 2010-12-20
32
is_deeply($dbi,{user => 'a', password => 'b', data_source => 'c', 
update document
yuki-kimoto authored on 2010-05-27
33
                filters => {f => 3}, default_bind_filter => 'f',
cleanup
yuki-kimoto authored on 2010-04-28
34
                default_fetch_filter => 'g', result_class => 'g',
removed DBIx::Custom::Query ...
yuki-kimoto authored on 2010-08-12
35
                query_builder => $query_builder}, $test);
packaging one directory
yuki-kimoto authored on 2009-11-16
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...
yuki-kimoto authored on 2010-01-18
77
is_deeply($dbi->filters, {f => 3}, "$test : filters");
packaging one directory
yuki-kimoto authored on 2009-11-16
78
isa_ok($dbi, 'DBIx::Custom');
79

            
80

            
some changed
yuki-kimoto authored on 2010-05-02
81
test 'register_filters';
packaging one directory
yuki-kimoto authored on 2009-11-16
82
$dbi = DBIx::Custom->new;
some changed
yuki-kimoto authored on 2010-05-02
83
$dbi->register_filter(a => sub {1});
packaging one directory
yuki-kimoto authored on 2009-11-16
84
is($dbi->filters->{a}->(), 1, $test);
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
85
$dbi->register_filter({b => sub {2}});
86
is($dbi->filters->{b}->(), 2, $test);
87

            
88

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
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
kimoto authored on 2010-12-20
103
test 'invalid attribute name';
104
eval {$dbi = DBIx::Custom->new(a => 1) };
105
like ($@, qr/"a" is invalid attribute name/, $test);