ETOOMANYARGS - change _resolve_collapse to take a couple hashes
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_informix.t
CommitLineData
b0a4cf8e 1use strict;
68de9438 2use warnings;
b0a4cf8e 3
4use Test::More;
199fbc45 5use DBIx::Class::Optional::Dependencies ();
b0a4cf8e 6use lib qw(t/lib);
7use DBICTest;
8use Scope::Guard ();
9
199fbc45 10plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt')
11. ' and ' .
12DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_informix')
13 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt')
14 && DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_informix');
15
b0a4cf8e 16my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/};
17
18if (not $dsn) {
19 plan skip_all => <<'EOF';
20Set $ENV{DBICTEST_INFORMIX_DSN} _USER and _PASS to run this test'.
21Warning: This test drops and creates a table called 'event'";
22EOF
b0a4cf8e 23}
24
25my $schema;
26
27{
28 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
29 on_connect_call => [ 'datetime_setup' ],
30 });
31
65d35121 32 my $sg = Scope::Guard->new(sub { cleanup($schema) } );
b0a4cf8e 33
34 eval { $schema->storage->dbh->do('DROP TABLE event') };
35 $schema->storage->dbh->do(<<'SQL');
36 CREATE TABLE event (
37 id INT PRIMARY KEY,
38 starts_at DATE,
39 created_on DATETIME YEAR TO FRACTION(5)
40 );
41SQL
42 my $rs = $schema->resultset('Event');
43
44 my $dt = DateTime->now;
45 $dt->set_nanosecond(555640000);
46
47 my $date_only = DateTime->new(
48 year => $dt->year, month => $dt->month, day => $dt->day
49 );
50
51 my $row;
52 ok( $row = $rs->create({
53 id => 1,
8273e845 54 starts_at => $date_only,
b0a4cf8e 55 created_on => $dt,
56 }));
57 ok( $row = $rs->search({ id => 1 }, { select => [qw/starts_at created_on/] })
58 ->first
59 );
60 is $row->created_on, $dt, 'TIMESTAMP as DateTime roundtrip';
61
62 cmp_ok $row->created_on->nanosecond, '==', $dt->nanosecond,
63 'fractional part of a second survived';
64
65 is $row->starts_at, $date_only, 'DATE as DateTime roundtrip';
66}
67
68done_testing;
69
70# clean up our mess
71sub cleanup {
65d35121 72 my $schema = shift;
8273e845 73 my $dbh;
b0a4cf8e 74 eval {
75 $dbh = $schema->storage->dbh;
76 };
77 return unless $dbh;
78
79 eval { $dbh->do(qq{DROP TABLE $_}) } for qw/event/;
80}