~ubuntu-branches/ubuntu/precise/libjifty-dbi-perl/precise

« back to all changes in this revision

Viewing changes to t/case_sensitivity.t

  • Committer: Bazaar Package Importer
  • Author(s): AGOSTINI Yves
  • Date: 2008-04-17 08:11:44 UTC
  • Revision ID: james.westby@ubuntu.com-20080417081144-jcpvqplvkkh07s1g
Tags: upstream-0.49
ImportĀ upstreamĀ versionĀ 0.49

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl -w
 
2
 
 
3
use strict;
 
4
 
 
5
use Test::More;
 
6
BEGIN { require "t/utils.pl" }
 
7
our (@available_drivers);
 
8
 
 
9
use constant TESTS_PER_DRIVER => 9;
 
10
 
 
11
my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
 
12
plan tests => $total;
 
13
 
 
14
use DateTime ();
 
15
 
 
16
foreach my $d ( @available_drivers ) {
 
17
SKIP: {
 
18
        unless( has_schema( 'TestApp::User', $d ) ) {
 
19
                skip "No schema for '$d' driver", TESTS_PER_DRIVER;
 
20
        }
 
21
        unless( should_test( $d ) ) {
 
22
                skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
 
23
        }
 
24
        diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
 
25
 
 
26
        my $handle = get_handle( $d );
 
27
        connect_handle( $handle );
 
28
        isa_ok($handle->dbh, 'DBI::db');
 
29
 
 
30
        {my $ret = init_schema( 'TestApp::User', $handle );
 
31
        isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back" );}
 
32
 
 
33
        my $rec = TestApp::User->new( handle => $handle );
 
34
        isa_ok($rec, 'Jifty::DBI::Record');
 
35
 
 
36
        my ($id) = $rec->create( name => 'Foobar', interests => 'Slacking' );
 
37
        ok($id, "Successfuly created ticket");
 
38
 
 
39
        $rec->load_by_cols( name => 'foobar');
 
40
    TODO: {
 
41
        local $TODO = "How do we force mysql to be case sensitive?" if ( $d eq 'mysql' || $d eq 'mysqlPP' );
 
42
        is($rec->id, undef);
 
43
    }
 
44
 
 
45
        $rec->load_by_cols( name => { value => 'foobar', case_sensitive => 0, operator => '=' });
 
46
        is($rec->id, $id);
 
47
 
 
48
        $rec->load_by_cols( name => 'Foobar');
 
49
        is($rec->id, $id);
 
50
 
 
51
        $rec->load_by_cols( interests => 'slacking');
 
52
        is($rec->id, $id);;
 
53
 
 
54
        $rec->load_by_cols( interests => 'Slacking');
 
55
        is($rec->id, $id);;
 
56
 
 
57
        cleanup_schema( 'TestApp', $handle );
 
58
        disconnect_handle( $handle );
 
59
}
 
60
}
 
61
 
 
62
package TestApp::User;
 
63
use base qw/Jifty::DBI::Record/;
 
64
 
 
65
1;
 
66
 
 
67
sub schema_sqlite {
 
68
 
 
69
<<EOF;
 
70
CREATE table users (
 
71
        id integer primary key,
 
72
        name varchar,
 
73
        interests varchar
 
74
)
 
75
EOF
 
76
 
 
77
}
 
78
 
 
79
sub schema_mysql {
 
80
 
 
81
<<EOF;
 
82
CREATE TEMPORARY table users (
 
83
        id integer auto_increment primary key,
 
84
        name varchar(255),
 
85
        interests varchar(255)
 
86
)
 
87
EOF
 
88
 
 
89
}
 
90
 
 
91
sub schema_pg {
 
92
 
 
93
<<EOF;
 
94
CREATE TEMPORARY table users (
 
95
        id serial primary key,
 
96
        name varchar,
 
97
        interests varchar
 
98
)
 
99
EOF
 
100
 
 
101
}
 
102
 
 
103
use Jifty::DBI::Schema;
 
104
 
 
105
use Jifty::DBI::Record schema {
 
106
    column name      => type is 'varchar', label is 'Name', is case_sensitive;
 
107
    column interests => type is 'varchar';
 
108
};
 
109
 
 
110
 
 
111
1;
 
112