[Jifty-commit] r3193 - in jifty/trunk/lib: .
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri May 4 06:49:42 EDT 2007
Author: clkao
Date: Fri May 4 06:49:18 2007
New Revision: 3193
Modified:
jifty/trunk/lib/Jifty.pm
jifty/trunk/lib/Jifty/Test.pm
Log:
fast test support: truncate tables rather than recreating database
when JIFTY_FAST_TEST is specified.
Modified: jifty/trunk/lib/Jifty.pm
==============================================================================
--- jifty/trunk/lib/Jifty.pm (original)
+++ jifty/trunk/lib/Jifty.pm Fri May 4 06:49:18 2007
@@ -416,7 +416,8 @@
Jifty::Util->require( $handle_class );
Jifty->handle( $handle_class->new );
Jifty->handle->connect();
- Jifty->handle->check_schema_version();
+ Jifty->handle->check_schema_version()
+ unless $args{'no_version_check'};
}
}
Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm (original)
+++ jifty/trunk/lib/Jifty/Test.pm Fri May 4 06:49:18 2007
@@ -202,6 +202,40 @@
sub setup_test_database {
my $class = shift;
+
+ if ($ENV{JIFTY_FAST_TEST}) {
+ local $SIG{__WARN__} = sub {};
+ eval { Jifty->new( no_version_check => 1 ); Jifty->handle->check_schema_version };
+ my $booted;
+ if (Jifty->handle && !$@) {
+ my $baseclass = Jifty->app_class;
+ my $schema = Jifty::Script::Schema->new;
+ $schema->prepare_model_classes;
+ for my $model_class ( grep {/^\Q$baseclass\E::Model::/} $schema->models ) {
+ # We don't want to get the Collections, for example.
+ next unless $model_class->isa('Jifty::DBI::Record');
+ Jifty->handle->simple_query('TRUNCATE '.$model_class->table );
+ Jifty->handle->simple_query('ALTER SEQUENCE '.$model_class->table.'_id_seq RESTART 1');
+ }
+ # Load initial data
+ eval {
+ my $bootstrapper = Jifty->app_class("Bootstrap");
+ Jifty::Util->require($bootstrapper);
+ $bootstrapper->run() if $bootstrapper->can('run');
+ };
+ die $@ if $@;
+ $booted = 1;
+ }
+ if (Jifty->handle) {
+ Jifty->handle->disconnect;
+ Jifty->handle(undef);
+ }
+ if ($booted) {
+ Jifty->new();
+ return;
+ }
+ }
+
Jifty->new( no_handle => 1 );
my $schema = Jifty::Script::Schema->new;
@@ -467,7 +501,7 @@
if Jifty->config and Jifty->bus;
# Remove testing db
- if (Jifty->handle) {
+ if (Jifty->handle && !$ENV{JIFTY_FAST_TEST}) {
Jifty->handle->disconnect();
my $schema = Jifty::Script::Schema->new;
$schema->{drop_database} = 1;
More information about the Jifty-commit
mailing list