Just Another Moose Day

Its test day again here in the Moose-pen

Today I am working of a separate branch 'trigger_dynamic' as I am trying out a large re-factotring of the code. The switch to the branch and then a pull I have


4 files changed, 341 insertions(+), 67 deletions(-)

so some major changes. On my first rung to the test cases I got fairly poor results with 14 test cases failing. The majority of fails were tests I invalidated by my code changes from the past few days;

1/12 Gather view_element Price in not in the elements array! Only elements from that array can be added …

# Looks like your test exited with 2 just after 11.


The above counts for 10 or the 14 case fails. Better fix that first;

The fist part of the fix was a simple change to the various test input hashes so the test elements would match up with 'elements' attribute, like this example;


{
name => 'user_id',
view => 'People'
}
],
conditions => [
{
left => {
-- name => 'first1',
++ name => 'first_name',
view => 'People'
},

after these fixes where made I ran into;

# Failed test 'DA conditions 0->predicates 0 correct'
# at GitHub\database-accessor\t\lib/Test/Database/Accessor/Utils.pm line 62.
# Comparing hash keys of $data->left
# Extra: '_lookup_name'

Another invalidated test which is fixed with this patch to the “deep_predicate” sub in the Utils.pm file;

bless( $predicate, "Database::Accessor::Predicate" );
bless_element( $predicate->{left} );
$predicate->{left}->_lookup_name()
++ if (ref($predicate->{left}) eq "Database::Accessor::Element" );
bless_element( $predicate->{right} );
$predicate->{right}->_lookup_name()
++ if (ref($predicate->{right}) eq "Database::Accessor::Element" );
my @preticates;

and this round with this test case 't/33_conditions.t' with a few more fixes for field 'view' I get a full pass on that one.

The next test case I tried to fix was 't/35_links.t' and I ran into a real bug on that one. Given this $in_hash;


my $in_hash = {
view => { name => 'People' },
elements => [
{
name => 'first_name',
view => 'People'
},
{
name => 'last_name',
view => 'People'
},
{
name => 'user_id',
view => 'People'
},
{
name => 'name',
view => 'country'
}
],
links => [
{
to => {
name => 'country,
alias => 'a_country'
},
type => 'Left',
conditions => [
{
left => {
name => 'country_id',
view => 'People'
},
right => {
name => 'id',
view => 'a_country'
},
operator => '=',
open_parentheses => 0,
close_parentheses => 0,
}
]
},
],
};

I got this error;

Only elements from that array can be added at /home/scolesj/database-accessor/lib/Database/Accessor.pm line 775.

The problem is the $in_hash is valid as this is how one would normally do such a view. I will have to add a flag so I can do the above when instantiating a DA.

To accomplish this I passed in the '$type' var down from the '_elements_check' call though to the '_check_element' in which I made this small change;


if (ref($element) eq 'Database::Accessor::Element'){
unless ( $element->view() ) {
$element->view( $self->view->name() );
die( "Gather view_element "
.$element->name()
." in not in the elements array! Only elements from that array can be added" )
-- unless ($type ne "static" and $self->get_element_by_lookup($element->_lookup_name()));
++ if ($type eq "dynamic" and !$self->get_element_by_lookup($element->_lookup_name()));
}
elsif (ref($element) eq 'Database::Accessor::If'){

and I now get a full pass.

Unfortunately my 't/33_conditions.t' is back to failing because now I never hit any code that will fire my '_lookup_name' attribute for the static elements and this was the fix


++ $element->_lookup_name();
die( "Gather view_element "

For the final problem of the day I ran into this bug next

Database::Accessor->dynamic Unbalanced parentheses in your dynamic attributes. Please check them! at /home/scolesj/database-accesso

when I ran the ' t/43_dynamic_conditions.t' test case.

Well I most certainly caused some problems with this re-rfactor. I fix one thing then break another. Seems like every fix I add in I break the previous test I just fixed.

I guess I will have to take a closer look at the code tomorrow and stop playing wack-a-mole' with the test cases.

moose-kananaskis-7.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