X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fdatetime.t;h=14a2ce07eb89bd7cf36a6c7c434fbccbe0ea270f;hb=124162a0580d6007d51d85c5caf198a52a12989f;hp=ae8fc3bc91d7d87b2347b0b5fdd0521e128a5ea3;hpb=40f751811e773082d1cc654f15f06ef65749a9e9;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/datetime.t b/t/inflate/datetime.t index ae8fc3b..14a2ce0 100644 --- a/t/inflate/datetime.t +++ b/t/inflate/datetime.t @@ -2,16 +2,18 @@ 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(); -eval { require DateTime::Format::SQLite }; -plan $@ - ? ( skip_all => "Need DateTime::Format::SQLite for DT inflation tests" ) - : ( tests => 18 ) -; +plan skip_all => 'DT inflation tests need ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_sqlite') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt_sqlite'); # inflation test my $event = $schema->resultset("Event")->find(1); @@ -22,15 +24,35 @@ isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); 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'; + TODO: { local $TODO = "We can't do this yet before 0.09" if DBIx::Class->VERSION < 0.09; - ok(my $row = - $schema->resultset('Event')->search({ starts_at => $starts })->single); 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); + $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } }) + ->single); + is(eval { $row->id }, 1, 'DT in search with condition'); } @@ -74,3 +96,5 @@ 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'); + +done_testing;