10 # so user's env doesn't screw us
11 delete $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 = "This stuff won't work without a -dt operator of some sort"
47 unless eval { require DBIx::Class::SQLMaker::DateOps };
49 is(eval { $row->id }, 1, 'DT in search');
51 local $ENV{DBIC_DT_SEARCH_OK} = 1;
54 $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } })
57 is(eval { $row->id }, 1, 'DT in search with condition');
60 # create using DateTime
61 my $created = $schema->resultset('Event')->create({
62 starts_at => DateTime->new(year=>2006, month=>6, day=>18),
63 created_on => DateTime->new(year=>2006, month=>6, day=>23)
65 my $created_start = $created->starts_at;
67 isa_ok($created->starts_at, 'DateTime', 'DateTime returned');
68 is("$created_start", '2006-06-18T00:00:00', 'Correct date/time');
71 isa_ok($event->created_on, 'DateTime', 'DateTime returned');
74 isa_ok($event->varchar_date, 'DateTime', 'DateTime returned');
75 isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned');
77 ## skip inflation field
78 isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column');
80 # klunky, but makes older Test::More installs happy
81 my $createo = $event->created_on;
82 is("$createo", '2006-06-22T21:00:05', 'Correct date/time');
84 my $created_cron = $created->created_on;
86 isa_ok($created->created_on, 'DateTime', 'DateTime returned');
87 is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time');
89 ## varchar field using inflate_date => 1
90 my $varchar_date = $event->varchar_date;
91 is("$varchar_date", '2006-07-23T00:00:00', 'Correct date/time');
93 ## varchar field using inflate_datetime => 1
94 my $varchar_datetime = $event->varchar_datetime;
95 is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time');
97 ## skip inflation field
98 my $skip_inflation = $event->skip_inflation;
99 is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time');
101 # create and update with literals
104 created_on => \ '2001-09-11',
105 starts_at => \[ '?' => '2001-10-26' ],
108 my $ev = $schema->resultset('Event')->create($d);
110 for my $col (qw(created_on starts_at)) {
111 ok (ref $ev->$col, "literal untouched in $col");
112 is_deeply( $ev->$col, $d->{$col});
113 is_deeply( $ev->get_inflated_column($col), $d->{$col});
114 is_deeply( $ev->get_column($col), $d->{$col});
117 $ev->discard_changes;
120 { $ev->get_dirty_columns },
124 for my $col (qw(created_on starts_at)) {
125 isa_ok ($ev->$col, "DateTime", "$col properly inflated on retrieve");
128 for my $meth (qw(set_inflated_columns set_columns)) {
133 { $ev->get_dirty_columns },
135 "Expected dirty cols after setting literals via $meth",
140 for my $col (qw(created_on starts_at)) {
141 ok (ref $ev->$col, "literal untouched in $col updated via $meth");
142 is_deeply( $ev->$col, $d->{$col});
143 is_deeply( $ev->get_inflated_column($col), $d->{$col});
144 is_deeply( $ev->get_column($col), $d->{$col});