Baby Moose all Clean

Code clean-up day here in the Moose-pen.

After adding in a few ENV flags in yesterday's post I better get back on track and fix the 16 test cases I broke in this post.

The thing I had to do was modify the 'Database::Accessor::Driver::Test', (remember this one? my DAD for testing), so it returned a 'Database::Accessor::Result' class and the was easy enough and in now looks like


sub execute {
my $self = shift;
my ($result, $type, $conn, $container, $opt ) = @_;
$result->effected(10);
$result->query($type.' Query');
$result->set([9,8,7,6,5,4,3,2,1,0]);
$result->DB('Data::Test');
$result->error($self); #kludge for testing. Sends the DAD back to ensure it is correct
return $result;
}

and I fixed up the first failing test case '20_dad_load.t' like this;

foreach my $type (qw(create retrieve update delete)){
my $container = {key=>1};
ok($da_new->$type(Data::Test->new(),$container),"$type Query ran");
if ($type eq 'create') {
ok($da_new->result()->is_error == 0,"$type->No Error");
ok($da_new->result()->effected() == 10,"$type->10 rows effected");
ok($da_new->result()->query() eq uc($type).' Query','correct '.uc($type)." query returned");
ok($da_new->result()->DAD() eq 'Database::Accessor::Driver::Test',"$type->correct raw DAD class");
ok($da_new->result()->DB() eq 'Data::Test',"$type->correct DB");
ok(ref($da_new->result()->error) eq 'Database::Accessor::Driver::Test', "Got an object in the error class")
}
}

now in the above I made to choice to check the contents of the returned class only once as this is just the same canned data returned on each method call, otherwise I would be just testing the same thing over and over again. Useful only if I want to have a large test count.

The next change was rather simple. I just swapped out ;


#my $dad = $return->{dad};
my $dad = $da->result->error(); #note to others this is a kludge for testing

in any of the test cases that happened to use it. I left a note on it to explain what I am getting in the error and it is just for testing.

That left me with the final four test cases for the CRUD methods and I had to a little jigging to get them all to pass.

First I removed all tests like this;


ok( $return_str->{type} eq Database::Accessor::Constants::RETRIEVE,
'Retrieve constant passed in and out' );

as I already do that test in the 20_dad_load.t test case.

Next I added in some tests for create and update that check to make sure I cannot enter a bad container type such as an empty hash or alike.

I finally added in a new test case 60_env_vars.t which is a very simple iteration over the named environment vars to see if the corresponding Accessor.pm attributes was properly set. I then gave it all the good old 'dzil test t' and got;


All tests successful.
Files=27, Tests=349, 82 wallclock secs ( 0.19 usr 0.06 sys + 38.14 cusr 2.19 csys = 40.58 CPU)
Result: PASS

So that is all great and good. Now I did have to make some adjustments and fixes as I went along so have a look at the latest checked in code.

I even took the opportunity once I had the full test past to re-factor the '_execute' sub. I moved the param validation for the 'create' and 'update' methods back into their respective subs and simplified the check to ensure a connection class is passed into the sub. I even added in a test to check for that. I re-ran my tests and full PASS so maybe I can finally move on to the Driver::DBI?

4a094d2a3d0a6ea1495ca43c5b750aad--mama-baby-elk.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations