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