Moose Still Extends



  • Back into extended test mode here in the Moose-Pen;

    Time to get back to some more practical tests as I have been side tracked by a few API issues. Just to re-cap the practical tests are found in the 'xt' dir and I am using them to test Driver::DBI against a real DB. So far this practical testing has sniffed out a whole lot of bugs and I am hoping to sniff out a few more.

    Today I am am going to play with the DBIs 'execute array' this should be totally transparent to the end user all I need to do is pass an 'Array-ref' into my $da as the container and DBI::Driver should do the rest.

    First I will need some more data and I added;


    {first_name =>'Tom',
    last_name =>'Atkins',
    user_id =>'atkinst'},
    {first_name =>'Tom',
    last_name =>'Atkins2',
    user_id =>'atkinst2'},
    {first_name =>'Tom',
    last_name =>'Atkins3',
    user_id =>'atkinst3'},
    {first_name =>'Tom',
    last_name =>'Atkins4',
    user_id =>'atkinst4'},

    to the '_new_person_data' array ref. Next I will need a new test case '25_exe_array.t';

    #!perl
    use Test::More tests => 2;
    use Data::Dumper;
    use Xtest::DB::Users;
    use Xtest::DA::Person;
    use Test::Deep qw(cmp_deeply);

    my $user_db = Xtest::DB::Users->new();
    my $dbh = $user_db->connect();
    my $people = $user_db->new_person_data;
    shift($people);
    my $person= Xtest::DA::Person->new();
    my $da = $person->da();

    ok($da->create($dbh,$people),"Create Four New Users ");
    ok($da->result()->effected == 4,"Four row effected");


    Lets see what happens when I run the above I get;

    can\'t use an undefined value as a HASH reference at D:/Perl64/lib/DBI.pm line 1962
    hmm seems I need to clean out a little more data that just the first one on that ' new_person_data'.

    This patch should fix that;

    ...
    my $people = $user_db->new_person_data;
    splice($people,0,3);
    my $person= Xtest::DA::Person->new();


    That is funny I can't remember when the last time I had to splice an array must be at least 6 or 7 years. Anyway on the next run I get;

    
    ok 1 - Create Four New Users
    ok 2 - Four row effected
    
    Ok that supposedly worked but the only way to know for sure is to add in another test;
    
    $da = $person->da();
    $da->add_condition({
                    left => {
                        name => 'first_name',
                    },
                    right     => { value => $people->[0]->{first_name}},
                    operator  => '=',
                });
    
    

    $da->retrieve($dbh);

    cmp_deeply( $da->result()->set->[0], $people,
    "All 4 users added correctly");


    Now for the above to work I have to re-set my DB as it may already have those four records in it. I can accomplish this simply by running '10_crud_basic.t' first. On my next run I got this error;

    DBD::Oracle::db prepare failed: ORA-00904: "PEOPLE_ADDRESS"."ID":

    and looking at the genrated SQL

    LEFT JOIN people_address ON people_address.id = people_address.people_id

    That is the Link API buggering me up this time. That should be

    LEFT JOIN people_address ON people.id = people_address.people_id

    So a quick fix to the 'Xtest::DA::Person' class '_build_da' sub;

    links => [{type => 'LEFT',
    to => { name => 'people_address'},
    conditions => [{ left => { name => 'id',
    ++ view => 'people' },
    right => { name => 'people_id'}},
    {condition =>'and',
    left => { name => 'primary_ind',
    view => 'people_address' },
    right => { value => 1}}}},

    and another try I get this;

    Compared array length of $data
    # got : array with 14 element(s)
    # expect : array with 4 element(s)

    and looking at the returned value;

    [ '6',
    'Tom',
    'Atkins',
    'atkinst ',
    undef,
    undef,
    undef,
    undef,
    undef,
    undef,
    undef,
    undef,
    undef,
    undef
    ],

    I will have to pad out those expected values a little as the returned so I will just add them onto the end of the '_people_data' array ref from 'Xtest::DB::Users' and adjust my test a little;

    
    ++my $all_people = $user_db->_people_data();
    ++splice($all_people,0,4);
    --cmp_deeply( $da->result()->set->[0], $people,
    ++cmp_deeply( $da->result()->set, $all_people,
                "All 4 users added correctly");
    
    and when I run (after a fix of a few typos in my '_people_data' I get
    
    ok 1 - Create Four New Users
    ok 2 - Four row effected
    ok 3 - All 4 users added correctly
    
    So not bad for a days work;

    IMG_7189a.jpg



    http://blogs.perl.org/users/byterock/2018/10/moose-still-extends.html

 

© Lightnetics 2018