Baby Moose Does More

Its wrap up a test day here in the Moose-pen;

I am going to finish off '15_alias.t' today by adding in a few more test looking at the field 'alias' and here are the tests;


$in_hash->{elements}->[0]->{alias} = 'last';
$in_hash->{elements}->[1]->{alias} = 'first';
$da = Database::Accessor->new($in_hash);
$da->create( $utils->connect(),$container);
ok($da->result()->query() eq "INSERT INTO people sys_users ( sys_users.first_name ) VALUES( ? )","create SQL correct");
$da->retrieve( $utils->connect());
ok($da->result()->query() eq "SELECT users.last_name AS last, sys_users.first_name AS first FROM people sys_users","retrieve SQL correct");
$da->update( $utils->connect(),$container);
ok($da->result()->query() eq "UPDATE people sys_users SET sys_users.first_name = ?","update SQL correct");

and surprise surprise they all run correctly. So this will could be a very short post today. Well maybe not.

Me thinks I will work on doing a little planing of what I will test next. The various fields/elements items look like a good candidate and I could load them all into the '30_fields.t' case.

Given that at the present time I have a least four;

  1. Element
  2. Param
  3. Expression and
  4. Function

classes that can be in an field. I might be trying to test too much with a single case. The old golden rule of automated testing;

'Your test cases will test only one thing'

comes to mind here.

I know for a fact that Element is rather simple as is the Param but both the Expression and Function are much more involved so I will KISS and have four test cases

  1. '30_fields.t'
  2. '32_params.t'
  3. '34_expression.t'
  4. '36_function.t'

I might as well work with the easiest one '30_fields.t' for today.

Looking at the code I do not think there is a great deal to test at this point? I have already covered most of the 'element/field' that I can see though I could push my refactoring of Driver::DBI to get rid of 'joins; like this


my $fields_clause = join(" ",Database::Accessor::Driver::DBI::SQL::OPEN_PARENS,
join(", ",@fields),
Database::Accessor::Driver::DBI::SQL::CLOSE_PARENS);

this but that is really not that productive of a refraction as the function may just complicate matters.

What I think I will do is move some of the tests in '15_alias.t' into this case and one thing I am going to implement is the 'only_elements' option that can be passed into a CRUD function in Database::Accessor.

Again more work in Accessor.p today than Driver::DBI as this is a new screening rule that the DAD can just ignore. The change was simple enough;


   private_method get_dad_elements => sub {
        my $self = shift;
--        my ($action) = @_;
++        my ($action,$opt) = @_;
        my @allowed;

        foreach my $element (@{$self->elements()} ) {
++            next 
++              if (exists($opt->{only_elements})
++                  and !exists($opt->{only_elements}->{$element->name}));
             next
...


and a little change where I make the call to 'get_dad_elements'

view => $self->view,
– elements => $self->get_dad_elements($action),
++ elements => $self->get_dad_elements($action,$opt),
conditions => [@{$self->conditions},@{$self->dynamic_conditions}],

and a new test 62_crud_options.t and at least a little accomplished today.

hp5952.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