From: Arthur Axel 'fREW' Schmidt Date: Tue, 23 Feb 2010 03:25:21 +0000 (-0600) Subject: some real tests for goodness sakes! X-Git-Tag: v0.001000_01~151 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=commitdiff_plain;h=e0743c250735642baadec89ffc28b045a5eb9476 some real tests for goodness sakes! --- diff --git a/t/02-instantiation.t b/t/02-instantiation.t index 4943e3c..3af52c0 100644 --- a/t/02-instantiation.t +++ b/t/02-instantiation.t @@ -6,10 +6,57 @@ use lib 't/lib'; use DBICTest; use DBIx::Class::DeploymentHandler; -my $handler = DBIx::Class::DeploymentHandler->new({ - schema => DBICTest->init_schema() -}); +my $sql_dir = 't/sql'; -ok($handler, 'DBIx::Class::DeploymentHandler instantiates correctly'); +VERSION1: { + use_ok 'DBICVersion_v1'; + my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:'); + ok($s, 'DBICVersion::Schema 1.0 instantiates correctly'); + my $handler = DBIx::Class::DeploymentHandler->new({ + schema => $s, + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly'); + + my $version = $s->schema_version(); + $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0); + ok(-e 't/sql/DBICVersion-Schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully'); +} + +VERSION2: { + use_ok 'DBICVersion_v2'; + my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:'); + ok($s, 'DBICVersion::Schema 2.0 instantiates correctly'); + my $handler = DBIx::Class::DeploymentHandler->new({ + schema => $s, + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly'); + + $version = $s->schema_version(); + $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0); + $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0'); + ok(-e 't/sql/DBICVersion-Schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully'); + ok(-e 't/sql/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully'); +} + +VERSION3: { + use_ok 'DBICVersion_v3'; + my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:'); + ok($s, 'DBICVersion::Schema 3.0 instantiates correctly'); + my $handler = DBIx::Class::DeploymentHandler->new({ + schema => $s, + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly'); + + $version = $s->schema_version(); + $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0); + $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0'); + $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '2.0'); + ok(-e 't/sql/DBICVersion-Schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully'); + ok(-e 't/sql/DBICVersion-Schema-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully'); + ok(-e 't/sql/DBICVersion-Schema-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully'); +} done_testing; diff --git a/t/lib/DBICVersion_v1.pm b/t/lib/DBICVersion_v1.pm new file mode 100644 index 0000000..9063d26 --- /dev/null +++ b/t/lib/DBICVersion_v1.pm @@ -0,0 +1,32 @@ +package DBICVersion::Foo; + +use base 'DBIx::Class::Core'; +use strict; +use warnings; + +__PACKAGE__->table('Foo'); + +__PACKAGE__->add_columns( + foo => { + data_type => 'INTEGER', + is_auto_increment => 1, + }, + bar => { + data_type => 'VARCHAR', + size => '10' + }, +); + +__PACKAGE__->set_primary_key('foo'); + +package DBICVersion::Schema; +use base 'DBIx::Class::Schema'; +use strict; +use warnings; + +our $VERSION = '1.0'; + +__PACKAGE__->register_class('Foo', 'DBICVersion::Foo'); +__PACKAGE__->load_components('DeploymentHandler::Component'); + +1; diff --git a/t/lib/DBICVersion_v2.pm b/t/lib/DBICVersion_v2.pm new file mode 100644 index 0000000..fa7932b --- /dev/null +++ b/t/lib/DBICVersion_v2.pm @@ -0,0 +1,36 @@ +package DBICVersion::Foo; + +use base 'DBIx::Class::Core'; +use strict; +use warnings; + +__PACKAGE__->table('Foo'); + +__PACKAGE__->add_columns( + foo => { + data_type => 'INTEGER', + is_auto_increment => 1, + }, + bar => { + data_type => 'VARCHAR', + size => '10' + }, + baz => { + data_type => 'VARCHAR', + size => '10' + }, +); + +__PACKAGE__->set_primary_key('foo'); + +package DBICVersion::Schema; +use base 'DBIx::Class::Schema'; +use strict; +use warnings; + +our $VERSION = '2.0'; + +__PACKAGE__->register_class('Foo', 'DBICVersion::Foo'); +__PACKAGE__->load_components('DeploymentHandler::Component'); + +1; diff --git a/t/lib/DBICVersion_v3.pm b/t/lib/DBICVersion_v3.pm new file mode 100644 index 0000000..eb11caa --- /dev/null +++ b/t/lib/DBICVersion_v3.pm @@ -0,0 +1,40 @@ +package DBICVersion::Foo; + +use base 'DBIx::Class::Core'; +use strict; +use warnings; + +__PACKAGE__->table('Foo'); + +__PACKAGE__->add_columns( + foo => { + data_type => 'INTEGER', + is_auto_increment => 1, + }, + bar => { + data_type => 'VARCHAR', + size => '10' + }, + baz => { + data_type => 'VARCHAR', + size => '10' + }, + biff => { + data_type => 'VARCHAR', + size => '10' + }, +); + +__PACKAGE__->set_primary_key('foo'); + +package DBICVersion::Schema; +use base 'DBIx::Class::Schema'; +use strict; +use warnings; + +our $VERSION = '3.0'; + +__PACKAGE__->register_class('Foo', 'DBICVersion::Foo'); +__PACKAGE__->load_components('DeploymentHandler::Component'); + +1;