Fix failures and protect the suite from spurious VERSION-related warnings
[dbsrgits/DBIx-Class.git] / t / icdt / offline_pg.t
1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt_pg );
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Warn;
8 use lib qw(t/lib);
9 use DBICTest;
10
11 DBICTest::Schema->load_classes('EventTZPg');
12
13 {
14   my $s = DBICTest::Schema->connect('dbi:Pg:whatever');
15
16   ok (!$s->storage->_dbh, 'definitely not connected');
17
18   # Check that datetime_parser returns correctly before we explicitly connect.
19   my $store = ref $s->storage;
20   is($store, 'DBIx::Class::Storage::DBI', 'Started with generic storage');
21
22   my $parser = $s->storage->datetime_parser;
23   is( $parser, 'DateTime::Format::Pg', 'datetime_parser is as expected');
24
25   ok (!$s->storage->_dbh, 'still not connected');
26 }
27
28 my $schema = DBICTest->init_schema();
29
30 # this may generate warnings under certain CI flags, hence do it outside of
31 # the warnings_are below
32 my $dt = DateTime->new( year => 2000, time_zone => "America/Chicago" );
33
34 warnings_are {
35   my $event = $schema->resultset("EventTZPg")->find(1);
36   $event->update({created_on => '2009-01-15 17:00:00+00'});
37   $event->discard_changes;
38   isa_ok($event->created_on, "DateTime") or diag $event->created_on;
39   is($event->created_on->time_zone->name, "America/Chicago", "Timezone changed");
40   # Time zone difference -> -6hours
41   is($event->created_on->iso8601, "2009-01-15T11:00:00", "Time with TZ correct");
42
43 # test 'timestamp without time zone'
44   my $dt = DateTime->from_epoch(epoch => time);
45   $dt->set_nanosecond(int 500_000_000);
46   $event->update({ts_without_tz => $dt});
47   $event->discard_changes;
48   isa_ok($event->ts_without_tz, "DateTime") or diag $event->created_on;
49   is($event->ts_without_tz, $dt, 'timestamp without time zone inflation');
50   is($event->ts_without_tz->microsecond, $dt->microsecond,
51     'timestamp without time zone microseconds survived');
52 } [], 'No warnings during DT manipulations';
53
54 done_testing;