Back to Momma Moose

Just another quick test postette day here in the Moose Pen.

As we seen in this post I found a bug where I was not coercing correctly on deeply nested Element Attributes. So that means back into the test suite of Database::Accessor I go to cover that bug and the new recusion functionality I have added recently.

Checking the current state of the test suite I see that I never did go deeper than one level of elements, though I do check to ensure that the View on elements are correct and the correct Class is passed in. Howeve I only test for Param and Element classes now I have at lest two others to check for.

I decided it is best to go for broke and create one have that will cover I think all of the combinations I could think of. Here is the hash;

$in_hash->{elements} =
[{ function => 'left',
left => { name => 'salary' },
right => { expression => '*',
left => { name => 'bonus' },
right => { param=>.05 }} },
{ function => 'abs',
left => { expression => '*',
left => { name => 'bonus',
view => 'Other' },
right => { param=>-.05 }} },
{ expression => '+',
left => { name => 'salary',
view => 'NotPeople' },
right => {
expression => '*',
left => { name => 'bonus'},
right =>
{ function => 'abs',
left =>
{ expression => '*',
left => { name => 'bonus',
view => 'Other' },
right => { name => 'bonus' }}

So three elements, all with varying left and right Classes and with three levels of recursion in the last one. The tests are simple enough first I create an new $da and so a retrieve and get back the $dad;

$da = Database::Accessor->new($in_hash);
$da->retrieve( Data::Test->new() );
$dad = $da->result->error();

Then test that the various elements in the DA are correct such as in the first element

ok(ref($dad->elements->[0]) eq 'Database::Accessor::Function','Element 0 is an function');
ok($dad->elements->[0]->left->view eq 'People','function left has correct view');
ok(ref($dad->elements->[0]->right) eq 'Database::Accessor::Expression','Element 0 right is an expression');
ok($dad->elements->[0]->right->left->view eq 'People','Element 0 right expression right has correct view');

where I check the Element's Class, the view attribute of its left attribute and the same sort of thisn for the right.

Now I am not going to list the entire test as it is much the same as above, just with ever more nested right and left calls, see here for the full test.

I also check in the test to ensure the right attribute can be undef like this test;

ok(!$dad->elements->[1]->right,'No Element 1 right');

and that I have the proper view on the very deeply nested elements like this test;

ok($dad->elements->[2]->right->right->left->left->view eq 'Other','Function 2 right->right->left->left has correct view');

In the end after a little clean up on the tests they all passed so now I know I will find that bug if it crops up again.


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