10 # so user's env doesn't screw us
11 undef $ENV{DBIC_DT_SEARCH_OK};
13 my $schema = DBICTest->init_schema();
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');
19 my $event = $schema->resultset("Event")->find(1);
21 isa_ok($event->starts_at, 'DateTime', 'DateTime returned');
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');
27 my $dt_warn_re = qr/DateTime objects.+not supported properly/;
32 local $ENV{DBIC_DT_SEARCH_OK} = 1;
33 local $SIG{__WARN__} = sub {
34 fail('Disabled warning still issued') if $_[0] =~ $dt_warn_re;
37 $row = $schema->resultset('Event')->search({ starts_at => $starts })->single
41 $row = $schema->resultset('Event')->search({ starts_at => $starts })->single
43 'using a DateTime object in ->search generates a warning';
46 local $TODO = "We can't do this yet before 0.09" if DBIx::Class->VERSION < 0.09;
48 is(eval { $row->id }, 1, 'DT in search');
50 local $ENV{DBIC_DT_SEARCH_OK} = 1;
53 $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } })
56 is(eval { $row->id }, 1, 'DT in search with condition');
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)
64 my $created_start = $created->starts_at;
66 isa_ok($created->starts_at, 'DateTime', 'DateTime returned');
67 is("$created_start", '2006-06-18T00:00:00', 'Correct date/time');
70 isa_ok($event->created_on, 'DateTime', 'DateTime returned');
73 isa_ok($event->varchar_date, 'DateTime', 'DateTime returned');
74 isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned');
76 ## skip inflation field
77 isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column');
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');
83 my $created_cron = $created->created_on;
85 isa_ok($created->created_on, 'DateTime', 'DateTime returned');
86 is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time');
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');
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');
96 ## skip inflation field
97 my $skip_inflation = $event->skip_inflation;
98 is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time');