X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fdatetime.t;h=7062563bb3d224037476189ecfc3e6f5da26ca9f;hb=refs%2Fheads%2Fcurrent%2Fdq;hp=061037a335aead2e204c7cc8e07262ed959f7b26;hpb=f4cb7f576191b819610e13c01bb073b76ee544bd;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/datetime.t b/t/inflate/datetime.t index 061037a..7062563 100644 --- a/t/inflate/datetime.t +++ b/t/inflate/datetime.t @@ -2,9 +2,14 @@ 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(); plan skip_all => 'DT inflation tests need ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_sqlite') @@ -19,15 +24,36 @@ isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); my $starts = $event->starts_at; is("$starts", '2006-04-25T22:24:33', 'Correct date/time'); -TODO: { - local $TODO = "We can't do this yet before 0.09" if DBIx::Class->VERSION < 0.09; +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 }; - 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'); }