Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added handling for Implicit inflate/deflate of CDBI has_a relationships
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use strict; | ||
use warnings; | ||
|
||
# Class::DBI in its infinate wisdom allows implicit inflation | ||
# and deflation of foriegn clas looups in has_a relationships. | ||
# for inflate it would call ->new on the foreign_class and for | ||
# deflate it would "" the column value and allow for overloading | ||
# of the "" operator. | ||
|
||
use Test::More; | ||
use DBIx::Class::Optional::Dependencies; | ||
|
||
BEGIN { | ||
plan skip_all => "Test needs ".DBIx::Class::Optional::Dependencies->req_missing_for('test_dt_sqlite') | ||
unless DBIx::Class::Optional::Dependencies->req_ok_for('test_dt_sqlite'); | ||
} | ||
|
||
use lib 't/cdbi/testlib'; | ||
use ImplicitInflate; | ||
|
||
ok(ImplicitInflate->can('db_Main'), 'set_db()'); | ||
is(ImplicitInflate->__driver, "SQLite", 'Driver set correctly'); | ||
|
||
my $now = DateTime->now; | ||
|
||
ImplicitInflate->create({ | ||
update_datetime => $now, | ||
text => "Test Data", | ||
}); | ||
|
||
my $implicit_inflate = ImplicitInflate->retrieve(text => 'Test Data'); | ||
|
||
ok($implicit_inflate->update_datetime->isa('DateTime'), 'Date column inflated correctly'); | ||
is($implicit_inflate->update_datetime => $now, 'Date has correct year'); | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package # Hide from PAUSE | ||
ImplicitInflate; | ||
|
||
# Test class for the testing of Implicit inflation | ||
# in CDBI Classes using Compat layer | ||
# See t/cdbi/70-implicit_inflate.t | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use base 'DBIC::Test::SQLite'; | ||
|
||
__PACKAGE__->set_table('Date'); | ||
|
||
__PACKAGE__->columns( Primary => 'id' ); | ||
__PACKAGE__->columns( All => qw/ update_datetime text/); | ||
|
||
__PACKAGE__->has_a( | ||
update_datetime => 'MyDateStamp', | ||
); | ||
|
||
sub create_sql { | ||
# SQLite doesn't support Datetime datatypes. | ||
return qq{ | ||
id INTEGER PRIMARY KEY, | ||
update_datetime TEXT, | ||
text VARCHAR(20) | ||
} | ||
} | ||
|
||
{ | ||
package MyDateStamp; | ||
|
||
use DateTime::Format::SQLite; | ||
|
||
sub new { | ||
my ($self, $value) = @_; | ||
return DateTime::Format::SQLite->parse_datetime($value); | ||
} | ||
} | ||
|
||
1; |