Finally implement compound OptDep group augmentation
[dbsrgits/DBIx-Class.git] / t / icdt / offline_pg.t
1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( icdt icdt_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 warnings_are {
31   my $event = $schema->resultset("EventTZPg")->find(1);
32   $event->update({created_on => '2009-01-15 17:00:00+00'});
33   $event->discard_changes;
34   isa_ok($event->created_on, "DateTime") or diag $event->created_on;
35   is($event->created_on->time_zone->name, "America/Chicago", "Timezone changed");
36   # Time zone difference -> -6hours
37   is($event->created_on->iso8601, "2009-01-15T11:00:00", "Time with TZ correct");
38
39 # test 'timestamp without time zone'
40   my $dt = DateTime->from_epoch(epoch => time);
41   $dt->set_nanosecond(int 500_000_000);
42   $event->update({ts_without_tz => $dt});
43   $event->discard_changes;
44   isa_ok($event->ts_without_tz, "DateTime") or diag $event->created_on;
45   is($event->ts_without_tz, $dt, 'timestamp without time zone inflation');
46   is($event->ts_without_tz->microsecond, $dt->microsecond,
47     'timestamp without time zone microseconds survived');
48 } [], 'No warnings during DT manipulations';
49
50 done_testing;