From: Peter Rabbitson Date: Sat, 7 Feb 2015 15:02:26 +0000 (+0100) Subject: Move some ICDT dependent (sub)tests around (no functional changes) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=8548e45cbaa8d8862ca78f675c73398ec2b0dc1d Move some ICDT dependent (sub)tests around (no functional changes) Read diff/blame with -C -C -M -w --- diff --git a/t/60core.t b/t/60core.t index 77ee4f9..595df62 100644 --- a/t/60core.t +++ b/t/60core.t @@ -206,41 +206,6 @@ $new = $schema->resultset("Track")->new( { $new->update_or_insert; ok($new->in_storage, 'update_or_insert insert ok'); -# test in update mode -$new->title('Insert or Update - updated'); -$new->update_or_insert; -is( $schema->resultset("Track")->find(100)->title, 'Insert or Update - updated', 'update_or_insert update ok'); - -SKIP: { - skip "Tests require " . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_sqlite'), 13 - unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt_sqlite'); - - # test get_inflated_columns with objects - my $event = $schema->resultset('Event')->search->first; - my %edata = $event->get_inflated_columns; - is($edata{'id'}, $event->id, 'got id'); - isa_ok($edata{'starts_at'}, 'DateTime', 'start_at is DateTime object'); - isa_ok($edata{'created_on'}, 'DateTime', 'create_on DateTime object'); - is($edata{'starts_at'}, $event->starts_at, 'got start date'); - is($edata{'created_on'}, $event->created_on, 'got created date'); - - - # get_inflated_columns w/relation and accessor alias - isa_ok($new->updated_date, 'DateTime', 'have inflated object via accessor'); - my %tdata = $new->get_inflated_columns; - is($tdata{'trackid'}, 100, 'got id'); - isa_ok($tdata{'cd'}, 'DBICTest::CD', 'cd is CD object'); - is($tdata{'cd'}->id, 1, 'cd object is id 1'); - is( - $tdata{'position'}, - $schema->resultset ('Track')->search ({cd => 1})->count, - 'Ordered assigned proper position', - ); - is($tdata{'title'}, 'Insert or Update - updated'); - is($tdata{'last_updated_on'}, '1973-07-19T12:01:02'); - isa_ok($tdata{'last_updated_on'}, 'DateTime', 'inflated accessored column'); -} - throws_ok (sub { $schema->class("Track")->load_components('DoesNotExist'); }, qr!Can't locate DBIx/Class/DoesNotExist.pm!, 'exception on nonexisting component'); diff --git a/t/72pg.t b/t/72pg.t index 384eee9..ec1cab0 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -22,28 +22,6 @@ DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_class ### pre-connect tests (keep each test separate as to make sure rebless() runs) { my $s = DBICTest::Schema->connect($dsn, $user, $pass); - - ok (!$s->storage->_dbh, 'definitely not connected'); - - # Check that datetime_parser returns correctly before we explicitly connect. - SKIP: { - skip ( - "Pg parser detection test needs " . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_pg'), - 2 - ) unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt_pg'); - - my $store = ref $s->storage; - is($store, 'DBIx::Class::Storage::DBI', 'Started with generic storage'); - - my $parser = $s->storage->datetime_parser; - is( $parser, 'DateTime::Format::Pg', 'datetime_parser is as expected'); - } - - ok (!$s->storage->_dbh, 'still not connected'); - } - - { - my $s = DBICTest::Schema->connect($dsn, $user, $pass); # make sure sqlt_type overrides work (::Storage::DBI::Pg does this) ok (!$s->storage->_dbh, 'definitely not connected'); is ($s->storage->sqlt_type, 'PostgreSQL', 'sqlt_type correct pre-connection'); diff --git a/t/inflate/core.t b/t/icdt/core.t similarity index 100% rename from t/inflate/core.t rename to t/icdt/core.t diff --git a/t/inflate/datetime_missing_deps.t b/t/icdt/datetime_missing_deps.t similarity index 100% rename from t/inflate/datetime_missing_deps.t rename to t/icdt/datetime_missing_deps.t diff --git a/t/inflate/datetime_firebird.t b/t/icdt/engine_specific/firebird.t similarity index 100% rename from t/inflate/datetime_firebird.t rename to t/icdt/engine_specific/firebird.t diff --git a/t/inflate/datetime_informix.t b/t/icdt/engine_specific/informix.t similarity index 100% rename from t/inflate/datetime_informix.t rename to t/icdt/engine_specific/informix.t diff --git a/t/inflate/datetime_msaccess.t b/t/icdt/engine_specific/msaccess.t similarity index 100% rename from t/inflate/datetime_msaccess.t rename to t/icdt/engine_specific/msaccess.t diff --git a/t/inflate/datetime_mssql.t b/t/icdt/engine_specific/mssql.t similarity index 100% rename from t/inflate/datetime_mssql.t rename to t/icdt/engine_specific/mssql.t diff --git a/t/inflate/datetime_oracle.t b/t/icdt/engine_specific/oracle.t similarity index 100% rename from t/inflate/datetime_oracle.t rename to t/icdt/engine_specific/oracle.t diff --git a/t/inflate/datetime_sqlanywhere.t b/t/icdt/engine_specific/sqlanywhere.t similarity index 100% rename from t/inflate/datetime_sqlanywhere.t rename to t/icdt/engine_specific/sqlanywhere.t diff --git a/t/icdt/engine_specific/sqlite.t b/t/icdt/engine_specific/sqlite.t new file mode 100644 index 0000000..3077371 --- /dev/null +++ b/t/icdt/engine_specific/sqlite.t @@ -0,0 +1,210 @@ +use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_dt_sqlite'; + +use strict; +use warnings; + +use Test::More; +use Test::Warn; +use Try::Tiny; +use lib qw(t/lib); +use DBICTest; + +# Test offline parser determination (formerly t/inflate/datetime_determine_parser.t) +{ + my $schema = DBICTest->init_schema( + no_deploy => 1, # Deploying would cause an early rebless + ); + + is( + ref $schema->storage, 'DBIx::Class::Storage::DBI', + 'Starting with generic storage' + ); + + # Calling date_time_parser should cause the storage to be reblessed, + # so that we can pick up datetime_parser_type from subclasses + my $parser = $schema->storage->datetime_parser(); + + is($parser, 'DateTime::Format::SQLite', 'Got expected storage-set datetime_parser'); + isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::SQLite', 'storage'); + + ok(! $schema->storage->connected, 'Not yet connected'); +} + +# so user's env doesn't screw us +delete $ENV{DBIC_DT_SEARCH_OK}; + +my $schema = DBICTest->init_schema(); + +# inflation test +my $event = $schema->resultset("Event")->find(1); + +isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); + +# klunky, but makes older Test::More installs happy +my $starts = $event->starts_at; +is("$starts", '2006-04-25T22:24:33', 'Correct date/time'); + +my $dt_warn_re = qr/DateTime objects.+not supported properly/; + +my $row; + +{ + local $ENV{DBIC_DT_SEARCH_OK} = 1; + local $SIG{__WARN__} = sub { + fail('Disabled warning still issued') if $_[0] =~ $dt_warn_re; + warn @_; + }; + $row = $schema->resultset('Event')->search({ starts_at => $starts })->single +} + +warnings_exist { + $row = $schema->resultset('Event')->search({ starts_at => $starts })->single +} [$dt_warn_re], + 'using a DateTime object in ->search generates a warning'; + +{ + local $TODO = "This stuff won't work without a -dt operator of some sort" + unless eval { require DBIx::Class::SQLMaker::DateOps }; + + is(eval { $row->id }, 1, 'DT in search'); + + local $ENV{DBIC_DT_SEARCH_OK} = 1; + + ok($row = + $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } }) + ->single); + + is(eval { $row->id }, 1, 'DT in search with condition'); +} + +# create using DateTime +my $created = $schema->resultset('Event')->create({ + starts_at => DateTime->new(year=>2006, month=>6, day=>18), + created_on => DateTime->new(year=>2006, month=>6, day=>23) +}); +my $created_start = $created->starts_at; + +isa_ok($created->starts_at, 'DateTime', 'DateTime returned'); +is("$created_start", '2006-06-18T00:00:00', 'Correct date/time'); + +## timestamp field +isa_ok($event->created_on, 'DateTime', 'DateTime returned'); + +## varchar fields +isa_ok($event->varchar_date, 'DateTime', 'DateTime returned'); +isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned'); + +## skip inflation field +isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column'); + +# klunky, but makes older Test::More installs happy +my $createo = $event->created_on; +is("$createo", '2006-06-22T21:00:05', 'Correct date/time'); + +my $created_cron = $created->created_on; + +isa_ok($created->created_on, 'DateTime', 'DateTime returned'); +is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time'); + +## varchar field using inflate_date => 1 +my $varchar_date = $event->varchar_date; +is("$varchar_date", '2006-07-23T00:00:00', 'Correct date/time'); + +## varchar field using inflate_datetime => 1 +my $varchar_datetime = $event->varchar_datetime; +is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time'); + +## skip inflation field +my $skip_inflation = $event->skip_inflation; +is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time'); + +# extra accessor tests with update_or_insert +{ + my $new = $schema->resultset("Track")->new( { + trackid => 100, + cd => 1, + title => 'Insert or Update', + last_updated_on => '1973-07-19 12:01:02' + } ); + $new->update_or_insert; + ok($new->in_storage, 'update_or_insert insert ok'); + + # test in update mode + $new->title('Insert or Update - updated'); + $new->update_or_insert; + is( $schema->resultset("Track")->find(100)->title, 'Insert or Update - updated', 'update_or_insert update ok'); + + # test get_inflated_columns with objects + my $event = $schema->resultset('Event')->search->first; + my %edata = $event->get_inflated_columns; + is($edata{'id'}, $event->id, 'got id'); + isa_ok($edata{'starts_at'}, 'DateTime', 'start_at is DateTime object'); + isa_ok($edata{'created_on'}, 'DateTime', 'create_on DateTime object'); + is($edata{'starts_at'}, $event->starts_at, 'got start date'); + is($edata{'created_on'}, $event->created_on, 'got created date'); + + # get_inflated_columns w/relation and accessor alias + isa_ok($new->updated_date, 'DateTime', 'have inflated object via accessor'); + my %tdata = $new->get_inflated_columns; + is($tdata{'trackid'}, 100, 'got id'); + isa_ok($tdata{'cd'}, 'DBICTest::CD', 'cd is CD object'); + is($tdata{'cd'}->id, 1, 'cd object is id 1'); + is( + $tdata{'position'}, + $schema->resultset ('Track')->search ({cd => 1})->count, + 'Ordered assigned proper position', + ); + is($tdata{'title'}, 'Insert or Update - updated'); + is($tdata{'last_updated_on'}, '1973-07-19T12:01:02'); + isa_ok($tdata{'last_updated_on'}, 'DateTime', 'inflated accessored column'); +} + +# create and update with literals +{ + my $d = { + created_on => \ '2001-09-11', + starts_at => \[ '?' => '2001-10-26' ], + }; + + my $ev = $schema->resultset('Event')->create($d); + + for my $col (qw(created_on starts_at)) { + ok (ref $ev->$col, "literal untouched in $col"); + is_deeply( $ev->$col, $d->{$col}); + is_deeply( $ev->get_inflated_column($col), $d->{$col}); + is_deeply( $ev->get_column($col), $d->{$col}); + } + + $ev->discard_changes; + + is_deeply( + { $ev->get_dirty_columns }, + {} + ); + + for my $col (qw(created_on starts_at)) { + isa_ok ($ev->$col, "DateTime", "$col properly inflated on retrieve"); + } + + for my $meth (qw(set_inflated_columns set_columns)) { + + $ev->$meth({%$d}); + + is_deeply( + { $ev->get_dirty_columns }, + $d, + "Expected dirty cols after setting literals via $meth", + ); + + $ev->update; + + for my $col (qw(created_on starts_at)) { + ok (ref $ev->$col, "literal untouched in $col updated via $meth"); + is_deeply( $ev->$col, $d->{$col}); + is_deeply( $ev->get_inflated_column($col), $d->{$col}); + is_deeply( $ev->get_column($col), $d->{$col}); + } + } +} + +done_testing; diff --git a/t/inflate/datetime_sybase.t b/t/icdt/engine_specific/sybase.t similarity index 100% rename from t/inflate/datetime_sybase.t rename to t/icdt/engine_specific/sybase.t diff --git a/t/inflate/datetime_mysql.t b/t/icdt/offline_mysql.t similarity index 100% rename from t/inflate/datetime_mysql.t rename to t/icdt/offline_mysql.t diff --git a/t/inflate/datetime_pg.t b/t/icdt/offline_pg.t similarity index 71% rename from t/inflate/datetime_pg.t rename to t/icdt/offline_pg.t index 4e51e28..754fa3b 100644 --- a/t/inflate/datetime_pg.t +++ b/t/icdt/offline_pg.t @@ -10,6 +10,21 @@ use DBICTest; DBICTest::Schema->load_classes('EventTZPg'); +{ + my $s = DBICTest::Schema->connect('dbi:Pg:whatever'); + + ok (!$s->storage->_dbh, 'definitely not connected'); + + # Check that datetime_parser returns correctly before we explicitly connect. + my $store = ref $s->storage; + is($store, 'DBIx::Class::Storage::DBI', 'Started with generic storage'); + + my $parser = $s->storage->datetime_parser; + is( $parser, 'DateTime::Format::Pg', 'datetime_parser is as expected'); + + ok (!$s->storage->_dbh, 'still not connected'); +} + my $schema = DBICTest->init_schema(); warnings_are { diff --git a/t/inflate/datetime.t b/t/inflate/datetime.t deleted file mode 100644 index e2c29af..0000000 --- a/t/inflate/datetime.t +++ /dev/null @@ -1,148 +0,0 @@ -use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_dt_sqlite'; - -use strict; -use warnings; - -use Test::More; -use Test::Warn; -use Try::Tiny; -use lib qw(t/lib); -use DBICTest; - -# so user's env doesn't screw us -delete $ENV{DBIC_DT_SEARCH_OK}; - -my $schema = DBICTest->init_schema(); - -# inflation test -my $event = $schema->resultset("Event")->find(1); - -isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); - -# klunky, but makes older Test::More installs happy -my $starts = $event->starts_at; -is("$starts", '2006-04-25T22:24:33', 'Correct date/time'); - -my $dt_warn_re = qr/DateTime objects.+not supported properly/; - -my $row; - -{ - local $ENV{DBIC_DT_SEARCH_OK} = 1; - local $SIG{__WARN__} = sub { - fail('Disabled warning still issued') if $_[0] =~ $dt_warn_re; - warn @_; - }; - $row = $schema->resultset('Event')->search({ starts_at => $starts })->single -} - -warnings_exist { - $row = $schema->resultset('Event')->search({ starts_at => $starts })->single -} [$dt_warn_re], - 'using a DateTime object in ->search generates a warning'; - -{ - local $TODO = "This stuff won't work without a -dt operator of some sort" - unless eval { require DBIx::Class::SQLMaker::DateOps }; - - is(eval { $row->id }, 1, 'DT in search'); - - local $ENV{DBIC_DT_SEARCH_OK} = 1; - - ok($row = - $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } }) - ->single); - - is(eval { $row->id }, 1, 'DT in search with condition'); -} - -# create using DateTime -my $created = $schema->resultset('Event')->create({ - starts_at => DateTime->new(year=>2006, month=>6, day=>18), - created_on => DateTime->new(year=>2006, month=>6, day=>23) -}); -my $created_start = $created->starts_at; - -isa_ok($created->starts_at, 'DateTime', 'DateTime returned'); -is("$created_start", '2006-06-18T00:00:00', 'Correct date/time'); - -## timestamp field -isa_ok($event->created_on, 'DateTime', 'DateTime returned'); - -## varchar fields -isa_ok($event->varchar_date, 'DateTime', 'DateTime returned'); -isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned'); - -## skip inflation field -isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column'); - -# klunky, but makes older Test::More installs happy -my $createo = $event->created_on; -is("$createo", '2006-06-22T21:00:05', 'Correct date/time'); - -my $created_cron = $created->created_on; - -isa_ok($created->created_on, 'DateTime', 'DateTime returned'); -is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time'); - -## varchar field using inflate_date => 1 -my $varchar_date = $event->varchar_date; -is("$varchar_date", '2006-07-23T00:00:00', 'Correct date/time'); - -## varchar field using inflate_datetime => 1 -my $varchar_datetime = $event->varchar_datetime; -is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time'); - -## skip inflation field -my $skip_inflation = $event->skip_inflation; -is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time'); - -# create and update with literals -{ - my $d = { - created_on => \ '2001-09-11', - starts_at => \[ '?' => '2001-10-26' ], - }; - - my $ev = $schema->resultset('Event')->create($d); - - for my $col (qw(created_on starts_at)) { - ok (ref $ev->$col, "literal untouched in $col"); - is_deeply( $ev->$col, $d->{$col}); - is_deeply( $ev->get_inflated_column($col), $d->{$col}); - is_deeply( $ev->get_column($col), $d->{$col}); - } - - $ev->discard_changes; - - is_deeply( - { $ev->get_dirty_columns }, - {} - ); - - for my $col (qw(created_on starts_at)) { - isa_ok ($ev->$col, "DateTime", "$col properly inflated on retrieve"); - } - - for my $meth (qw(set_inflated_columns set_columns)) { - - $ev->$meth({%$d}); - - is_deeply( - { $ev->get_dirty_columns }, - $d, - "Expected dirty cols after setting literals via $meth", - ); - - $ev->update; - - for my $col (qw(created_on starts_at)) { - ok (ref $ev->$col, "literal untouched in $col updated via $meth"); - is_deeply( $ev->$col, $d->{$col}); - is_deeply( $ev->get_inflated_column($col), $d->{$col}); - is_deeply( $ev->get_column($col), $d->{$col}); - } - } -} - -done_testing; diff --git a/t/inflate/datetime_determine_parser.t b/t/inflate/datetime_determine_parser.t deleted file mode 100644 index 1e7759f..0000000 --- a/t/inflate/datetime_determine_parser.t +++ /dev/null @@ -1,27 +0,0 @@ -use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_dt_sqlite'; - -use strict; -use warnings; - -use Test::More; -use lib qw(t/lib); -use DBICTest; - -my $schema = DBICTest->init_schema( - no_deploy => 1, # Deploying would cause an early rebless -); - -is( - ref $schema->storage, 'DBIx::Class::Storage::DBI', - 'Starting with generic storage' -); - -# Calling date_time_parser should cause the storage to be reblessed, -# so that we can pick up datetime_parser_type from subclasses - -my $parser = $schema->storage->datetime_parser(); - -is($parser, 'DateTime::Format::SQLite', 'Got expected storage-set datetime_parser'); -isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::SQLite', 'storage'); - -done_testing; diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index 52906c7..2e783a7 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -51,7 +51,7 @@ __PACKAGE__->load_classes(qw/ 'CD_to_Producer', 'Dummy', # this is a real result class we remove in the hook below ), - qw/SelfRefAlias TreeLike TwoKeyTreeLike Event EventTZ NoPrimaryKey/, + qw/SelfRefAlias TreeLike TwoKeyTreeLike Event NoPrimaryKey/, qw/Collection CollectionObject TypedObject Owners BooksInLibrary/, qw/ForceForeign Encoded/, );