add _verify_pid and _verify_tid to methods that croak in ::Replicated
[dbsrgits/DBIx-Class.git] / t / inflate / datetime.t
CommitLineData
40f75181 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
10eval { require DateTime::Format::SQLite };
11plan $@
12 ? ( skip_all => "Need DateTime::Format::SQLite for DT inflation tests" )
13 : ( tests => 18 )
14;
15
16# inflation test
17my $event = $schema->resultset("Event")->find(1);
18
19isa_ok($event->starts_at, 'DateTime', 'DateTime returned');
20
21# klunky, but makes older Test::More installs happy
22my $starts = $event->starts_at;
23is("$starts", '2006-04-25T22:24:33', 'Correct date/time');
24
25TODO: {
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
38my $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});
42my $created_start = $created->starts_at;
43
44isa_ok($created->starts_at, 'DateTime', 'DateTime returned');
45is("$created_start", '2006-06-18T00:00:00', 'Correct date/time');
46
47## timestamp field
48isa_ok($event->created_on, 'DateTime', 'DateTime returned');
49
50## varchar fields
51isa_ok($event->varchar_date, 'DateTime', 'DateTime returned');
52isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned');
53
54## skip inflation field
55isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column');
56
57# klunky, but makes older Test::More installs happy
58my $createo = $event->created_on;
59is("$createo", '2006-06-22T21:00:05', 'Correct date/time');
60
61my $created_cron = $created->created_on;
62
63isa_ok($created->created_on, 'DateTime', 'DateTime returned');
64is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time');
65
66## varchar field using inflate_date => 1
67my $varchar_date = $event->varchar_date;
68is("$varchar_date", '2006-07-23T00:00:00', 'Correct date/time');
69
70## varchar field using inflate_datetime => 1
71my $varchar_datetime = $event->varchar_datetime;
72is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time');
73
74## skip inflation field
75my $skip_inflation = $event->skip_inflation;
76is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time');