Commit | Line | Data |
40f75181 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
e1038213 |
5 | use Test::Warn; |
6 | use Try::Tiny; |
40f75181 |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
07d6018a |
10 | # so user's env doesn't screw us |
11 | undef $ENV{DBIC_DT_SEARCH_OK}; |
12 | |
40f75181 |
13 | my $schema = DBICTest->init_schema(); |
14 | |
f4cb7f57 |
15 | plan skip_all => 'DT inflation tests need ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_sqlite') |
16 | unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt_sqlite'); |
40f75181 |
17 | |
18 | # inflation test |
19 | my $event = $schema->resultset("Event")->find(1); |
20 | |
21 | isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); |
22 | |
23 | # klunky, but makes older Test::More installs happy |
24 | my $starts = $event->starts_at; |
25 | is("$starts", '2006-04-25T22:24:33', 'Correct date/time'); |
26 | |
07d6018a |
27 | my $dt_warn_re = qr/DateTime objects.+not supported properly/; |
28 | |
e1038213 |
29 | my $row; |
30 | |
07d6018a |
31 | { |
32 | local $ENV{DBIC_DT_SEARCH_OK} = 1; |
33 | local $SIG{__WARN__} = sub { |
34 | fail('Disabled warning still issued') if $_[0] =~ $dt_warn_re; |
35 | warn @_; |
e1038213 |
36 | }; |
07d6018a |
37 | $row = $schema->resultset('Event')->search({ starts_at => $starts })->single |
38 | } |
39 | |
40 | warnings_exist { |
41 | $row = $schema->resultset('Event')->search({ starts_at => $starts })->single |
42 | } [$dt_warn_re], |
e1038213 |
43 | 'using a DateTime object in ->search generates a warning'; |
44 | |
40f75181 |
45 | TODO: { |
46 | local $TODO = "We can't do this yet before 0.09" if DBIx::Class->VERSION < 0.09; |
47 | |
40f75181 |
48 | is(eval { $row->id }, 1, 'DT in search'); |
49 | |
07d6018a |
50 | local $ENV{DBIC_DT_SEARCH_OK} = 1; |
e1038213 |
51 | |
40f75181 |
52 | ok($row = |
e1038213 |
53 | $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } }) |
54 | ->single); |
55 | |
40f75181 |
56 | is(eval { $row->id }, 1, 'DT in search with condition'); |
57 | } |
58 | |
59 | # create using DateTime |
60 | my $created = $schema->resultset('Event')->create({ |
61 | starts_at => DateTime->new(year=>2006, month=>6, day=>18), |
62 | created_on => DateTime->new(year=>2006, month=>6, day=>23) |
63 | }); |
64 | my $created_start = $created->starts_at; |
65 | |
66 | isa_ok($created->starts_at, 'DateTime', 'DateTime returned'); |
67 | is("$created_start", '2006-06-18T00:00:00', 'Correct date/time'); |
68 | |
69 | ## timestamp field |
70 | isa_ok($event->created_on, 'DateTime', 'DateTime returned'); |
71 | |
72 | ## varchar fields |
73 | isa_ok($event->varchar_date, 'DateTime', 'DateTime returned'); |
74 | isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned'); |
75 | |
76 | ## skip inflation field |
77 | isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column'); |
78 | |
79 | # klunky, but makes older Test::More installs happy |
80 | my $createo = $event->created_on; |
81 | is("$createo", '2006-06-22T21:00:05', 'Correct date/time'); |
82 | |
83 | my $created_cron = $created->created_on; |
84 | |
85 | isa_ok($created->created_on, 'DateTime', 'DateTime returned'); |
86 | is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time'); |
87 | |
88 | ## varchar field using inflate_date => 1 |
89 | my $varchar_date = $event->varchar_date; |
90 | is("$varchar_date", '2006-07-23T00:00:00', 'Correct date/time'); |
91 | |
92 | ## varchar field using inflate_datetime => 1 |
93 | my $varchar_datetime = $event->varchar_datetime; |
94 | is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time'); |
95 | |
96 | ## skip inflation field |
97 | my $skip_inflation = $event->skip_inflation; |
98 | is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time'); |
68de9438 |
99 | |
100 | done_testing; |