Mercurial > pub > Impl
comparison _test/Test/SQL/Traits.pm @ 165:76515373dac0
Added Class::Template,
Rewritten SQL::Schema
'use parent' directive instead of 'use base'
author | wizard |
---|---|
date | Sat, 23 Apr 2011 23:06:48 +0400 |
parents | |
children | 1f7a6d762394 |
comparison
equal
deleted
inserted
replaced
164:eb3e9861a761 | 165:76515373dac0 |
---|---|
1 package Test::SQL::Traits; | |
2 use parent qw(IMPL::Test::Unit); | |
3 | |
4 __PACKAGE__->PassThroughArgs; | |
5 | |
6 use IMPL::lang; | |
7 use IMPL::Class::Property; | |
8 use IMPL::Test qw(test failed shared assert); | |
9 | |
10 use IMPL::SQL::Schema; | |
11 use IMPL::SQL::Schema::Traits; | |
12 use IMPL::SQL::Types qw(Integer Varchar DateTime); | |
13 | |
14 BEGIN { | |
15 shared public property schema => prop_all; | |
16 } | |
17 | |
18 sub StartUnit { | |
19 return { | |
20 schema => new IMPL::SQL::Schema( name => 'testTraits', version => 1 ) | |
21 }; | |
22 } | |
23 | |
24 test CreateTable => sub { | |
25 my ($this) = @_; | |
26 | |
27 my $table = $this->schema->AddTable( | |
28 new IMPL::SQL::Schema::Traits::Table( | |
29 'user' | |
30 ) | |
31 ) or failed "Failed to create table"; | |
32 | |
33 $this->schema->GetTable('user') or failed "Can't get a created table"; | |
34 | |
35 }; | |
36 | |
37 test InsertColumn => sub { | |
38 my ($this) = @_; | |
39 | |
40 my $table = $this->schema->GetTable('user'); | |
41 | |
42 $table->InsertColumn( | |
43 new IMPL::SQL::Schema::Traits::Column( | |
44 id => Integer, tag => { auto_increment => 1 } | |
45 ) | |
46 ); | |
47 | |
48 my $column = $table->Column('id') or failed "Column not found"; | |
49 | |
50 assert( $column->name eq 'id'); | |
51 assert( $column->type->isSame(Integer()) ); | |
52 assert( not $column->isNullable ); | |
53 assert( $column->tag->{auto_increment} ); | |
54 | |
55 $table->InsertColumn( | |
56 new IMPL::SQL::Schema::Traits::Column( | |
57 name => Varchar(255), isNullable => 1 | |
58 ) | |
59 ); | |
60 | |
61 $column = $table->Column('name'); | |
62 | |
63 assert($column); | |
64 assert($column->name eq 'name'); | |
65 assert($column->type->isSame(Varchar(255))); | |
66 assert($column->isNullable); | |
67 }; | |
68 | |
69 test CreateTableWithColumns => sub { | |
70 my ($this) = @_; | |
71 | |
72 my $table = $this->schema->AddTable( | |
73 new IMPL::SQL::Schema::Traits::Table( | |
74 session => [ | |
75 new IMPL::SQL::Schema::Traits::Column( id => Varchar(64)), | |
76 new IMPL::SQL::Schema::Traits::Column( expires => DateTime ), | |
77 new IMPL::SQL::Schema::Traits::Column( role => Varchar(64), defaultValue => 'user' ) | |
78 ] | |
79 ) | |
80 ) or failed "Failed to create table"; | |
81 | |
82 assert( $table->ColumnsCount == 3 ); | |
83 | |
84 assert( my $column = $table->Column('id') ); | |
85 assert($column->type->isSame(Varchar(64))); | |
86 assert(not $column->isNullable); | |
87 | |
88 assert( $column = $table->Column('role') ); | |
89 assert( $column->defaultValue eq 'user' ); | |
90 }; | |
91 | |
92 sub FinishUnit { | |
93 my ($self,$session) = @_; | |
94 | |
95 $self->supercall::FinishUnit(); | |
96 | |
97 $session->{schema}->Dispose(); | |
98 } | |
99 | |
100 1; |