From 786c7081da7d0455b2302244f4e823281010611a Mon Sep 17 00:00:00 2001 From: vti Date: Fri, 31 Oct 2008 18:18:44 +0100 Subject: [PATCH] Tests with column types. --- Rose-DBx-Object-I18N/t/03aggregate.t | 28 ++++++++++++++++++++++++++++ Rose-DBx-Object-I18N/t/lib/DB.pm | 4 +++- Rose-DBx-Object-I18N/t/lib/Metadata.pm | 12 ++++++------ Rose-DBx-Object-I18N/t/lib/NewDB.pm | 18 +++++++++--------- Rose-DBx-Object-I18N/t/lib/User.pm | 3 ++- Rose-DBx-Object-I18N/t/lib/UserI18N.pm | 6 +++--- Rose-DBx-Object-I18N/t/zzcleanup.t | 2 +- 7 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 Rose-DBx-Object-I18N/t/03aggregate.t diff --git a/Rose-DBx-Object-I18N/t/03aggregate.t b/Rose-DBx-Object-I18N/t/03aggregate.t new file mode 100644 index 0000000..348d23e --- /dev/null +++ b/Rose-DBx-Object-I18N/t/03aggregate.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +use lib 'lib', 't/lib'; + +eval "use Test::Aggregate"; +plan skip_all => "Test::Aggregate is required for fast testing" if $@; + +my $dump = 'dump.t'; +my $tests = Test::Aggregate->new( + { verbose => 2, + dump => $dump, + shuffle => 1, + dirs => 'aggtests', + set_filenames => 1, + findbin => 1, + check_plan => 1, + test_nowarnings => 0, + } +); +$tests->run; + +ok -f $dump, '... and we should have written out a dump file'; +unlink $dump or warn "Cannot unlink ($dump): $!"; + diff --git a/Rose-DBx-Object-I18N/t/lib/DB.pm b/Rose-DBx-Object-I18N/t/lib/DB.pm index 8e16c81..6f8c0a1 100644 --- a/Rose-DBx-Object-I18N/t/lib/DB.pm +++ b/Rose-DBx-Object-I18N/t/lib/DB.pm @@ -11,7 +11,9 @@ __PACKAGE__->use_private_registry; __PACKAGE__->register_db( driver => 'sqlite', - database => File::Spec->catfile( File::Spec->tmpdir, 'rose-i18n.db' ) + database => File::Spec->catfile( File::Spec->tmpdir, 'rose-i18n.db' ), + post_connect_sql => + [ 'PRAGMA synchronous = OFF', 'PRAGMA temp_store = MEMORY', ], ); =head1 AUTHOR diff --git a/Rose-DBx-Object-I18N/t/lib/Metadata.pm b/Rose-DBx-Object-I18N/t/lib/Metadata.pm index 07cb94f..ff132ac 100644 --- a/Rose-DBx-Object-I18N/t/lib/Metadata.pm +++ b/Rose-DBx-Object-I18N/t/lib/Metadata.pm @@ -5,11 +5,11 @@ use warnings; use base 'Rose::DBx::Object::I18N::Metadata'; -#__PACKAGE__->column_type_class( - #i18n_language => - #'Rose::DBx::Object::I18N::Metadata::Column::Language', - #i18n_is_translation => - #'Rose::DBx::Object::I18N::Metadata::Column::IsTranslation' -#); +__PACKAGE__->column_type_class( + i18n_language => + 'Rose::DBx::Object::I18N::Metadata::Column::Language', + i18n_is_translation => + 'Rose::DBx::Object::I18N::Metadata::Column::IsTranslation' +); 1; diff --git a/Rose-DBx-Object-I18N/t/lib/NewDB.pm b/Rose-DBx-Object-I18N/t/lib/NewDB.pm index 5d836de..25d2a16 100644 --- a/Rose-DBx-Object-I18N/t/lib/NewDB.pm +++ b/Rose-DBx-Object-I18N/t/lib/NewDB.pm @@ -14,10 +14,16 @@ sub new { sub db { shift->{ db } } -sub dbname { +sub exists { my $self = shift; - return $self->db->database; + return -f $self->db->database && @{ $self->db->list_tables }; +} + +sub cleanup { + my $self = shift; + + unlink $self->db->database; } sub init { @@ -25,7 +31,7 @@ sub init { my $dbh = $self->db->retain_dbh; - unless ( -f $self->dbname && @{ $self->db->list_tables } ) { + unless ( $self->exists ) { warn 'Creating new db...'; $dbh->do( <dbname; -} - =head1 AUTHOR vti diff --git a/Rose-DBx-Object-I18N/t/lib/User.pm b/Rose-DBx-Object-I18N/t/lib/User.pm index 35e7172..ef1f2a7 100644 --- a/Rose-DBx-Object-I18N/t/lib/User.pm +++ b/Rose-DBx-Object-I18N/t/lib/User.pm @@ -11,7 +11,8 @@ __PACKAGE__->meta->setup( table => 'user', columns => [ - qw/ id name orig_lang / + qw/ id name /, + orig_lang => { type => 'i18n_language' } ], primary_key_columns => [ qw/ id / ], diff --git a/Rose-DBx-Object-I18N/t/lib/UserI18N.pm b/Rose-DBx-Object-I18N/t/lib/UserI18N.pm index 3079286..b64ef8d 100644 --- a/Rose-DBx-Object-I18N/t/lib/UserI18N.pm +++ b/Rose-DBx-Object-I18N/t/lib/UserI18N.pm @@ -14,10 +14,10 @@ __PACKAGE__->meta->setup( qw/ i18nid user_id - lang - istran signature - / + /, + lang => { type => 'i18n_language' }, + istran => { type => 'i18n_is_translation' } ], primary_key_columns => [ 'i18nid' ], diff --git a/Rose-DBx-Object-I18N/t/zzcleanup.t b/Rose-DBx-Object-I18N/t/zzcleanup.t index e84d227..5284695 100644 --- a/Rose-DBx-Object-I18N/t/zzcleanup.t +++ b/Rose-DBx-Object-I18N/t/zzcleanup.t @@ -13,4 +13,4 @@ my $db = NewDB->new(); $db->cleanup(); -ok( ! -f $db->dbname ); +ok( ! -f $db->db->database ); -- 2.11.4.GIT