Merge 'trunk' into 'replication_dedux'
[dbsrgits/DBIx-Class.git] / t / 73oracle_inflate.t
CommitLineData
8f7e044c 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
9
10eval "use DateTime; use DateTime::Format::Oracle;";
11if ($@) {
12 plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
13}
14elsif (not ($dsn && $user && $pass)) {
15 plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
16 'Warning: This test drops and creates a table called \'track\'';
17}
18else {
19 plan tests => 4;
20}
21
22# DateTime::Format::Oracle needs this set
23$ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
24
25my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
26
27# Need to redefine the last_updated_on column
28my $col_metadata = $schema->class('Track')->column_info('last_updated_on');
29$schema->class('Track')->add_column( 'last_updated_on' => {
30 data_type => 'date' });
31
32my $dbh = $schema->storage->dbh;
33
34eval {
35 $dbh->do("DROP TABLE track");
36};
37$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE)");
38
39# insert a row to play with
40my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07' });
41is($new->trackid, 1, "insert sucessful");
42
43my $track = $schema->resultset('Track')->find( 1 );
44
45is( ref($track->last_updated_on), 'DateTime', "last_updated_on inflated ok");
46
47is( $track->last_updated_on->month, 5, "DateTime methods work on inflated column");
48
49my $dt = DateTime->now();
50$track->last_updated_on($dt);
51$track->update;
52
53is( $track->last_updated_on->month, $dt->month, "deflate ok");
54
55# clean up our mess
56END {
8f7e044c 57 if($dbh) {
58 $dbh->do("DROP TABLE track");
59 }
60}
61