Still Extending Mooosse
Back to basics here in the Moose-Pen
Still expanding my 'xt' tests after yesterday fix. Going to try the “Like” operator to start;
$da->add_condition(
{
left => {
name => 'user_id',
view => 'people'
},
operator => 'Like',
right =>{value=>'atkinst%'}
},
);
no real need for all the rest of the test code here mostly the same as before. The above should select out just those five users I added with the execute_array test.
…
ok 5 - All 4 users retrieved with Like
and that worked. I think one more is in order this tests case
$da->add_condition(
{
left => {
name => 'user_id',
view => 'people'
},
operator => 'Not Like',
right =>{value=>'atkinst%'}
},
);
and my full results are now;
ok 1 - All 4 users retrieved correctly with between
ok 2 - All 4 users retrieved correctly with is null
ok 3 - All 4 users retrieved with in
ok 4 - All 4 users retrieved with in using a DA
ok 5 - All 4 users retrieved with Like
ok 6 - All 4 users retrieved with not Like
So onto the next case which is '40_joins.t' but when I look at the code I am already using I think it will just be overkill to add more tests for joins.
How about '50_group_by.t'?
I will start with the standard;
my $user_db = Xtest::DB::Users->new();
my $dbh = $user_db->connect();
my $updated_people = $user_db->updated_people_data();
my $person= Xtest::DA::Person->new();
my $da = $person->da();
my $regions = $user_db->regions_data();
Now the little problem of that '$person' DA it has some 14 fields/elements way to many for a practical test so I will just cut it down a little with that brand new 'only_elements' call of mine so I now have.
$address_da->only_elements({region=>1});
and then the gather/group by;
$da->add_gather({elements => [{name => 'description',
view => 'region'}]});
and the rest of the test
$da->add_sort({name=>'description',
view => 'region' });
$da->retrieve($dbh);
cmp_deeply( $da->result()->set, regions,
"3 regions selected in order");
and when I run my test I get;
Attribute (elements) does not pass the type constraint because: ArrayRefofElements can not be an empty array ref at D:\Perl64\site\lib\Moose\Object.pm line 24
Moose::Object::new('Database::Accessor::Driver::DBI', 'HASH(0x5c00990)') called at D:\GitHub\database-accessor\lib\Database\Accessor.pm line 917
Database::Accessor::__ANON__('Database::Accessor=HASH(0x5c00ae0)', 'RETRIEVE', 'DBI::db=HASH(0x5a829d0)', 'HASH(0x5c035b8)', undef) called at D:\GitHub\database-accessor\lib\Database\Accessor.pm line 606
Database::Accessor::retrieve('Database::Accessor=HASH(0x5c00ae0)', 'DBI::db=HASH(0x5a829d0)') called at 50_group_by.t line 29
# Looks like your test exited with 255 before it could output anything.
Opps moose poop.
Looking into that fail I think it is because of my 'only_elements' call as I have no elements in my DA hence the constraint error.
So the problem is in Database::Accessor on this line
next
if (!$self->only_elements_is_empty() and !$self->only_elements_exists($element->name));
in my case I am asking for the alias 'region' but only checking on the $element->name. I think this patch will fix that;
next
if (!$self->only_elements_is_empty()
and (!$self->only_elements_exists($element->name)
and !($element->alias()
and $self->only_elements_exists($element->alias) )));
and on my next run I get;
ok 1 - 3 regions selected in order
Now the question comes to mind. What if I want to do a count on the number of people in each region? Well with Database::Accessor as it stands you can't. I took out the ability to add in new 'elements/fields' very early on in the development process. You are stuck with just he elements in you DA.
Why? You might ask. It goes down to the simple fact that Database::Accessor is not an ORM but I could see that it would be useful to do counts on my $da so perhaps I can change my API a little.
Something for tomorrow I guess.
Leave a comment