Moose Never Stops Testing
Its new test day again in the Moose-Pen
Well starting with the 20_fields.t test case today and this is really just this so far;
my $in_hash = {
da_compose_only => 1,
update_requires_condition => 0,
delete_requires_condition => 0,
view => { name => 'people' },
elements => [ { name => 'first_name', }, { name => 'last_name', }, ],
};
my $container = {
last_name => 'Bloggings',
first_name => 'Bill',
};
my $tests = [
{
caption => 'Fields',
create => {
container => $container,
sql =>
"INSERT INTO people ( first_name, last_name ) VALUES( ?, ? )",
params => [ 'Bill', 'Bloggings' ]
},
retrieve =>
{ sql => "SELECT people.first_name, people.last_name FROM people" },
update => {
container => { first_name => 'Robert' },
sql => "UPDATE people SET first_name = ?",
params => ['Robert']
},
delete => { sql => "DELETE FROM people" },
},
{
caption => '2 Fields and 2 parama',
key => 'elements',
elements => [
{ value => 'User Name:' },
{
name => 'first_name',
},
{ value => 'Address:' },
{ name => 'last_name', },
],
create => {
container => $container,
sql =>
"INSERT INTO people ( first_name, last_name ) VALUES( ?, ? )",
params => [ 'Bill', 'Bloggings' ]
},
retrieve => {
sql =>
"SELECT ?, people.first_name, ?, people.laste_name FROM people",
params=>[ 'Bill', 'Bloggings']
},
update => {
container => { first_name => 'Robert' },
sql => "UPDATE people SET first_name = ?",
params => ['Robert']
},
delete => { sql => "DELETE FROM people" },
},
];
$utils->sql_param_ok($in_hash,$tests);
Which translates into 13 test compared to the seven I had in the previous incarnation of the fields test case.
On my first run of the above I did get two fails;
… ok 8 - 2 Fields and 2 parama create params correct not ok 9 - 2 Fields and 2 parama retrieve SQL correct not ok 10 - 2 Fields and 2 parama retrieve params correct ok 11 - 2 Fields and 2 parama update SQL correct …
checking the output, the generated SQL is
SELECT people.first_name, people.last_name FROM people
so I am missing my params in the first and last place. That is of course in my Driver::DBI or at least I though that until I had a close look at the code and the bug was in my Utils sub
foreach my $test ( @{$tests} ) {
++ if ( exists( $test->{index} ) ) {
++ $in_hash->{ $test->{key} }->[ $test->{index} ] =
++ $test->{ $test->{key} };
++ }
++ elsif ( exists( $test->{key} ) ) {
++ $in_hash->{ $test->{key} } = $test->{ $test->{key} };
++ }
foreach my $action ((qw(create retrieve update delete))){
next
my $sub_test = $test->{$action};
--
-- if ( exists( $sub_test->{index} ) ) {
-- $in_hash->{ $sub_test->{key} }->[ $sub_test->{index} ] =
-- $sub_test->{ $sub_test->{key} };
-- }
-- elsif ( exists( $sub_test->{key} ) ) {
-- $in_hash->{ $sub_test->{key} } = $sub_test->{ $sub_test->{key} };
-- }
my $da = Database::Accessor->new
…
I should have had that $in_hash change before I loop though all the actions. It did clean up the problem but now I am getting;
Can't locate object method "alias" via package "Database::Accessor::Param" GitHub\database-accessor-driver-dbi\lib/Database/Accessor/Driver/DBI.pm line 412.oh well at least I have a post-ette for tomorrow.
Leave a comment