From: Arthur Axel 'fREW' Schmidt Date: Sat, 20 Mar 2010 19:27:04 +0000 (-0500) Subject: VersionHandler no longer needs access to other components, *much* cleaner tests for... X-Git-Tag: v0.001000_01~78 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b539a2166a39a25bb3d1d91b47909500b55b3ee6;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git VersionHandler no longer needs access to other components, *much* cleaner tests for VersionHandlers --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index 76d48e0..9431c0d 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -25,6 +25,7 @@ has schema => ( isa => 'DBIx::Class::Schema', is => 'ro', required => 1, + handles => ['schema_version'], ); has upgrade_directory => ( # configuration @@ -46,6 +47,8 @@ has to_version => ( # configuration # which is... probably not how we want it ); +sub _build_to_version { $_[0]->schema->schema_version } + has databases => ( # configuration coerce => 1, isa => 'DBIx::Class::DeploymentHandler::Databases', diff --git a/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm b/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm index f203066..7cfbd71 100644 --- a/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm +++ b/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm @@ -3,27 +3,6 @@ use Moose::Role; requires 'next_version_set'; -has schema => ( - isa => 'DBIx::Class::Schema', - is => 'ro', - required => 1, - handles => [qw( schema_version )], -); - -has version_storage => ( - does => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage', - is => 'ro', - required => 1, - handles => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage', -); - -has to_version => ( - is => 'ro', - lazy_build => 1, -); - -sub _build_to_version { $_[0]->schema->schema_version } - 1; __END__ diff --git a/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm index c02d52f..7be88f4 100644 --- a/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm @@ -4,6 +4,26 @@ use Method::Signatures::Simple; with 'DBIx::Class::DeploymentHandler::HandlesVersioning'; +has schema_version => ( + isa => 'Str', + is => 'ro', + required => 1, +); + +has database_version => ( + isa => 'Str', + is => 'ro', + required => 1, +); + +has to_version => ( # configuration + is => 'ro', + lazy_build => 1, # builder comes from another role... + # which is... probably not how we want it +); + +sub _build_to_version { $_[0]->schema_version } + has once => ( is => 'rw', isa => 'Bool', diff --git a/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm b/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm index 191ac1a..fd20600 100644 --- a/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm @@ -5,6 +5,26 @@ use Carp 'croak'; with 'DBIx::Class::DeploymentHandler::HandlesVersioning'; +has schema_version => ( + isa => 'Str', + is => 'ro', + required => 1, +); + +has database_version => ( + isa => 'Str', + is => 'ro', + required => 1, +); + +has to_version => ( # configuration + is => 'ro', + lazy_build => 1, # builder comes from another role... + # which is... probably not how we want it +); + +sub _build_to_version { $_[0]->schema_version } + has ordered_versions => ( is => 'ro', isa => 'ArrayRef', diff --git a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm index 9d307bc..6c086c1 100644 --- a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm @@ -16,8 +16,8 @@ sub _build_version_handler { my $self = shift; my $args = { - schema => $self->schema, - version_storage => $self->version_storage, + database_version => $self->database_version, + schema_version => $self->schema_version, }; $args->{to_version} = $self->to_version if $self->has_to_version; diff --git a/t/version_handlers/db_schema_versions.t b/t/version_handlers/db_schema_versions.t index 1c5d394..7a5e62a 100644 --- a/t/version_handlers/db_schema_versions.t +++ b/t/version_handlers/db_schema_versions.t @@ -6,79 +6,64 @@ use Test::Exception; use lib 't/lib'; use DBICDHTest; use DBICTest; -use DBIx::Class::DeploymentHandler; -use DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions; -my $db = 'dbi:SQLite:db.db'; -my @connection = ($db, '', '', { ignore_version => 1 }); -my $sql_dir = 't/sql'; +use aliased + 'DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions'; -DBICDHTest::ready; - -use DBICVersion_v1; -my $s = DBICVersion::Schema->connect(@connection); - -my $handler = DBIx::Class::DeploymentHandler->new({ - upgrade_directory => $sql_dir, - schema => $s, - databases => 'SQLite', - sqltargs => { add_drop_table => 0 }, -}); -my $v_storage = $handler->version_storage; -my $version = $s->schema_version(); -$handler->prepare_install(); - -$handler->install; { - my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({ - schema => $s, - ordered_versions => $versions, + my $vh = DatabaseToSchemaVersions->new({ to_version => '5.0', - version_storage => $v_storage, + database_version => '1.0', + schema_version => '1.0', }); ok( $vh, 'VersionHandler gets instantiated' ); - ok( eq_array( $vh->next_version_set, [qw( 1.0 5.0 )] ), 'db version and to_version get correctly put into version set'); + ok( + eq_array( $vh->next_version_set, [qw( 1.0 5.0 )] ), + 'db version and to_version get correctly put into version set' + ); ok( !$vh->next_version_set, 'next_version_set only works once'); ok( !$vh->next_version_set, 'seriously.'); } { - my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({ - schema => $s, - ordered_versions => $versions, - version_storage => $v_storage, + my $vh = DatabaseToSchemaVersions->new({ + database_version => '1.0', + schema_version => '1.0', }); ok( $vh, 'VersionHandler gets instantiated' ); - ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' ); + ok( + !$vh->next_version_set, + 'VersionHandler is null when schema_version and db_verison are the same' + ); } { - my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({ - schema => $s, - ordered_versions => $versions, - version_storage => $v_storage, + my $vh = DatabaseToSchemaVersions->new({ + database_version => '1.0', + schema_version => '1.0', }); ok( $vh, 'VersionHandler gets instantiated' ); - ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' ); + ok( + !$vh->next_version_set, + 'VersionHandler is null when schema_version and db_verison are the same' + ); } { - $DBICVersion::Schema::VERSION = '10.0'; - - my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({ - schema => $s, - ordered_versions => $versions, - version_storage => $v_storage, + my $vh = DatabaseToSchemaVersions->new({ + database_version => '1.0', + schema_version => '10.0', }); ok( $vh, 'VersionHandler gets instantiated' ); - ok( eq_array( $vh->next_version_set, [qw( 1.0 10.0 )] ), 'db version and schema version get correctly put into version set'); + ok( + eq_array( $vh->next_version_set, [qw( 1.0 10.0 )] ), + 'db version and schema version get correctly put into version set' + ); ok( !$vh->next_version_set, 'VersionHandler is null on next try' ); } done_testing; -__END__ - -vim: ts=2 sw=2 expandtab +# vim: ts=2 sw=2 expandtab diff --git a/t/version_handlers/explict_versions.t b/t/version_handlers/explict_versions.t index 0c98a9a..0d28f3b 100644 --- a/t/version_handlers/explict_versions.t +++ b/t/version_handlers/explict_versions.t @@ -4,75 +4,64 @@ use Test::More; use Test::Exception; use lib 't/lib'; -use DBICDHTest; -use DBICTest; -use DBIx::Class::DeploymentHandler; -use DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions; -my $db = 'dbi:SQLite:db.db'; -my @connection = ($db, '', '', { ignore_version => 1 }); -my $sql_dir = 't/sql'; - -DBICDHTest::ready; - -use DBICVersion_v1; -my $s = DBICVersion::Schema->connect(@connection); - -my $handler = DBIx::Class::DeploymentHandler->new({ - upgrade_directory => $sql_dir, - schema => $s, - databases => 'SQLite', - sqltargs => { add_drop_table => 0 }, -}); - -my $v_storage = $handler->version_storage; - -my $version = $s->schema_version(); -$handler->prepare_install(); - -$handler->install; +use aliased + 'DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions'; my $versions = [map "$_.0", 0..100]; { - my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({ - schema => $s, + my $vh = ExplicitVersions->new({ ordered_versions => $versions, to_version => '1.0', - version_storage => $v_storage, + schema_version => '1.0', + database_version => '1.0', }); ok $vh, 'VersionHandler gets instantiated'; - ok( !$vh->next_version_set, 'next version set returns undef if we are at the version requested' ); + ok( + !$vh->next_version_set, + 'next version set returns undef if we are at the version requested' + ); } { - my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({ - schema => $s, + my $vh = ExplicitVersions->new({ ordered_versions => $versions, to_version => '5.0', - version_storage => $v_storage, + schema_version => '1.0', + database_version => '1.0', }); ok $vh, 'VersionHandler gets instantiated'; - ok( eq_array($vh->next_version_set, [qw( 1.0 2.0 )]), 'first version pair works' ); - ok( eq_array($vh->next_version_set, [qw( 2.0 3.0 )]), 'second version pair works' ); - ok( eq_array($vh->next_version_set, [qw( 3.0 4.0 )]), 'third version pair works' ); - ok( eq_array($vh->next_version_set, [qw( 4.0 5.0 )]), 'fourth version pair works' ); + ok( + eq_array($vh->next_version_set, [qw( 1.0 2.0 )]), + 'first version pair works' + ); + ok( + eq_array($vh->next_version_set, [qw( 2.0 3.0 )]), + 'second version pair works' + ); + ok( + eq_array($vh->next_version_set, [qw( 3.0 4.0 )]), + 'third version pair works' + ); + ok( + eq_array($vh->next_version_set, [qw( 4.0 5.0 )]), + 'fourth version pair works' + ); ok( !$vh->next_version_set, 'no more versions after final pair' ); ok( !$vh->next_version_set, 'still no more versions after final pair' ); } dies_ok { - my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({ - schema => $s, + my $vh = ExplicitVersions->new({ ordered_versions => $versions, to_version => '0.0', - version_storage => $v_storage, + schema_version => '1.0', + database_version => '1.0', }); } 'cannot request a version before the current version'; done_testing; -__END__ - -vim: ts=2 sw=2 expandtab +#vim: ts=2 sw=2 expandtab