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