Commit | Line | Data |
40f75181 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
8 | my $schema = DBICTest->init_schema(); |
9 | |
10 | eval { require DateTime::Format::SQLite }; |
11 | plan $@ |
12 | ? ( skip_all => "Need DateTime::Format::SQLite for DT inflation tests" ) |
13 | : ( tests => 18 ) |
14 | ; |
15 | |
16 | # inflation test |
17 | my $event = $schema->resultset("Event")->find(1); |
18 | |
19 | isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); |
20 | |
21 | # klunky, but makes older Test::More installs happy |
22 | my $starts = $event->starts_at; |
23 | is("$starts", '2006-04-25T22:24:33', 'Correct date/time'); |
24 | |
25 | TODO: { |
26 | local $TODO = "We can't do this yet before 0.09" if DBIx::Class->VERSION < 0.09; |
27 | |
28 | ok(my $row = |
29 | $schema->resultset('Event')->search({ starts_at => $starts })->single); |
30 | is(eval { $row->id }, 1, 'DT in search'); |
31 | |
32 | ok($row = |
33 | $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } })->single); |
34 | is(eval { $row->id }, 1, 'DT in search with condition'); |
35 | } |
36 | |
37 | # create using DateTime |
38 | my $created = $schema->resultset('Event')->create({ |
39 | starts_at => DateTime->new(year=>2006, month=>6, day=>18), |
40 | created_on => DateTime->new(year=>2006, month=>6, day=>23) |
41 | }); |
42 | my $created_start = $created->starts_at; |
43 | |
44 | isa_ok($created->starts_at, 'DateTime', 'DateTime returned'); |
45 | is("$created_start", '2006-06-18T00:00:00', 'Correct date/time'); |
46 | |
47 | ## timestamp field |
48 | isa_ok($event->created_on, 'DateTime', 'DateTime returned'); |
49 | |
50 | ## varchar fields |
51 | isa_ok($event->varchar_date, 'DateTime', 'DateTime returned'); |
52 | isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned'); |
53 | |
54 | ## skip inflation field |
55 | isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column'); |
56 | |
57 | # klunky, but makes older Test::More installs happy |
58 | my $createo = $event->created_on; |
59 | is("$createo", '2006-06-22T21:00:05', 'Correct date/time'); |
60 | |
61 | my $created_cron = $created->created_on; |
62 | |
63 | isa_ok($created->created_on, 'DateTime', 'DateTime returned'); |
64 | is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time'); |
65 | |
66 | ## varchar field using inflate_date => 1 |
67 | my $varchar_date = $event->varchar_date; |
68 | is("$varchar_date", '2006-07-23T00:00:00', 'Correct date/time'); |
69 | |
70 | ## varchar field using inflate_datetime => 1 |
71 | my $varchar_datetime = $event->varchar_datetime; |
72 | is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time'); |
73 | |
74 | ## skip inflation field |
75 | my $skip_inflation = $event->skip_inflation; |
76 | is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time'); |