A little ahead but really back Moose
Its practical test day here in the Moose-pen
Yesterday I set up a new class that would generate a nice little set of DB table for me on what ever DB the end user may have by using a plug-in to supply the generation SQL. Today I greatly expanded that class but there is no real reason for me to dump it here as it is just more of the same from yesterdays post.
I did create a new class to test complete with a Data::Accesosr definition which is below;
sub _build_da {
my $self = shift;
my $da = Database::Accessor->new({view =>{name=>"people"},
elements=>[{name =>'id',
identity =>{'DBI::db'=>{'ORACLE' => {
name => 'NEXTVAL',
view => 'people_seq'}}} },
{name=>'first_name'},
{name=>'last_name'},
{name=>'user_id'},
{name=>'address_id',
view=>'address',},
{name=>'street',
view=>'address',},
{name=>'city',
view=>'address',},
{name=>'postal_code',
view=>'address',},
{name=>'country_id',
view=>'address',},
{name=>'description',
alias=>'country',
view=>'country',},
{name=>'description',
alias=>'region',
view=>'region',},
{name=>'description',
alias=>'time zone',
view=>'time_zone',}, ],
links => [{type => 'LEFT',
to => { name => 'address'},
conditions => [{ left => { name => 'id', },
right => { name => 'address_id',
view => 'person'}},
{condition =>'and',
left => { name => 'primary_ind' },
right => { value => 1}}]},
{type => 'LEFT',
to => { name => 'country'},
conditions => [{ left => { name => 'id' },
right => { name => 'country_id',
view => 'person'}}]},
{type => 'LEFT',
to => { name => 'region'},
conditions => [{ left => { name => 'id' },
right => { name => 'region_id',
view => 'person'}}]},
{type => 'LEFT',
to => { name => 'time_zone'},
conditions => [{ left => { name => 'id' },
right => { name => 'time_zone_id',
view => 'person'}}]}],});
return $da;
}
I so according to what I have done so far I should have a full pass of this;
use Xtest::DB::Users;
use Xtest::DA::Person;
my $user_db = Xtest::DB::Users->new();
$user_db->create_db();
my $dbh = $user_db->connect();
my $person= Xtest::DA::Person->new($user_db->new_person_data->[0]);
my $da = $person->da();
ok($da->create($dbh,$person),"Create New User");
ok($da->result()->effected == 1,"One row effected");
However I get this;
not ok 1 - Create New User
# Failed test 'Create New User'
# at 10_crud_basic.t line 28.
not ok 2 - One row effected
# Failed test 'One row effected'
# at 10_crud_basic.t line 31.
and looking at the error coming from the Database::Accessor I have
'DBD::Oracle::st execute failed: ORA-00904: "STREET": invalid identifier (DBD ERROR:
….
and the generated SQL was;
INSERT INTO people ( city, country_id, first_name, last_name, postal_code, street, user_id )
VALUES( ?, ?, ?, ?, ?, ?, ? )
which is correct SQL but according to how I want Database::Accessor to work when I do a 'create' or 'update' I should only be able to effect the 'elements' that match the present 'view'. As the present view is ' people' only 'id','first_name', 'last_name' and 'user_id' should be present. The elements 'city', 'country_id','postal_code', and 'street' are all have the 'address' view so should not be there.
I guess back to my standard test suite and test case '40_joins.t' to see where I when wrong. To fix up the test to check for the expected condition all I need to add in this;
my $container = {
last_name => 'Bloggings',
first_name => 'Bill',
++ street => '101 test'
};
and re-run my tests and as expected I most tests failed like this one;
# Expected SQL--> INSERT INTO people ( first_name, last_name ) VALUES( ?, ? )
# Generated SQL-> INSERT INTO people ( first_name, last_name, street ) VALUES( ?, ?, ? )
oh well something to post about for tomorrow. I guess pratical tests relaly pay off, I was about to release this with this bug in there.
Leave a comment