Commit | Line | Data |
cb551b07 |
1 | use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_dt'; |
2 | |
9cd0b325 |
3 | use strict; |
68de9438 |
4 | use warnings; |
9cd0b325 |
5 | |
6 | use Test::More; |
9cd0b325 |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | use Scope::Guard (); |
10 | |
2b1fff81 |
11 | my $env2optdep = { |
12 | DBICTEST_FIREBIRD => 'test_rdbms_firebird', |
13 | DBICTEST_FIREBIRD_INTERBASE => 'test_rdbms_firebird_interbase', |
14 | DBICTEST_FIREBIRD_ODBC => 'test_rdbms_firebird_odbc', |
15 | }; |
16 | |
17 | plan skip_all => join (' ', |
18 | 'Set $ENV{DBICTEST_FIREBIRD_DSN} and/or $ENV{DBICTEST_FIREBIRD_INTERBASE_DSN}', |
19 | 'and/or $ENV{DBICTEST_FIREBIRD_ODBC_DSN},', |
20 | '_USER and _PASS to run these tests.', |
9cd0b325 |
21 | |
2b1fff81 |
22 | "WARNING: This test drops and creates a table called 'event'", |
23 | ) unless grep { $ENV{"${_}_DSN"} } keys %$env2optdep; |
24 | |
9cd0b325 |
25 | my $schema; |
26 | |
2b1fff81 |
27 | for my $prefix (keys %$env2optdep) { SKIP: { |
28 | |
29 | my ($dsn, $user, $pass) = map { $ENV{"${prefix}_$_"} } qw/DSN USER PASS/; |
9cd0b325 |
30 | |
31 | next unless $dsn; |
32 | |
2b1fff81 |
33 | note "Testing with ${prefix}_DSN"; |
34 | |
35 | skip ("Testing with ${prefix}_DSN needs " . DBIx::Class::Optional::Dependencies->req_missing_for( $env2optdep->{$prefix} ), 1) |
36 | unless DBIx::Class::Optional::Dependencies->req_ok_for($env2optdep->{$prefix}); |
37 | |
32323fc2 |
38 | $schema = DBICTest::Schema->connect($dsn, $user, $pass, { |
c5827074 |
39 | quote_char => '"', |
8273e845 |
40 | name_sep => '.', |
9cd0b325 |
41 | on_connect_call => [ 'datetime_setup' ], |
42 | }); |
43 | |
65d35121 |
44 | my $sg = Scope::Guard->new(sub { cleanup($schema) } ); |
9cd0b325 |
45 | |
c5827074 |
46 | eval { $schema->storage->dbh->do('DROP TABLE "event"') }; |
47 | $schema->storage->dbh->do(<<'SQL'); |
48 | CREATE TABLE "event" ( |
49 | "id" INT PRIMARY KEY, |
50 | "starts_at" DATE, |
51 | "created_on" TIMESTAMP |
9cd0b325 |
52 | ) |
53 | SQL |
a870aa85 |
54 | my $rs = $schema->resultset('Event'); |
c5827074 |
55 | |
56 | my $dt = DateTime->now; |
a870aa85 |
57 | $dt->set_nanosecond(555600000); |
c5827074 |
58 | |
59 | my $date_only = DateTime->new( |
60 | year => $dt->year, month => $dt->month, day => $dt->day |
61 | ); |
62 | |
9cd0b325 |
63 | my $row; |
c5827074 |
64 | ok( $row = $rs->create({ |
65 | id => 1, |
8273e845 |
66 | starts_at => $date_only, |
c5827074 |
67 | created_on => $dt, |
68 | })); |
69 | ok( $row = $rs->search({ id => 1 }, { select => [qw/starts_at created_on/] }) |
9cd0b325 |
70 | ->first |
71 | ); |
c5827074 |
72 | is $row->created_on, $dt, 'TIMESTAMP as DateTime roundtrip'; |
32323fc2 |
73 | |
c5827074 |
74 | cmp_ok $row->created_on->nanosecond, '==', $dt->nanosecond, |
a870aa85 |
75 | 'fractional part of a second survived'; |
c5827074 |
76 | |
77 | is $row->starts_at, $date_only, 'DATE as DateTime roundtrip'; |
2b1fff81 |
78 | } } |
9cd0b325 |
79 | |
80 | done_testing; |
81 | |
82 | # clean up our mess |
83 | sub cleanup { |
65d35121 |
84 | my $schema = shift; |
8273e845 |
85 | my $dbh; |
9cd0b325 |
86 | eval { |
87 | $schema->storage->disconnect; # to avoid object FOO is in use errors |
88 | $dbh = $schema->storage->dbh; |
89 | }; |
90 | return unless $dbh; |
91 | |
c5827074 |
92 | eval { $dbh->do(qq{DROP TABLE "$_"}) } for qw/event/; |
9cd0b325 |
93 | } |