From: Aran Deltac Date: Thu, 23 Mar 2006 18:05:37 +0000 (+0000) Subject: Additional tests for first_sibling and last_sibling. X-Git-Tag: v0.07002~75^2~273 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5faa95affd5bb016d0fa81f7f99411ce4db5ff08;p=dbsrgits%2FDBIx-Class.git Additional tests for first_sibling and last_sibling. --- diff --git a/lib/DBIx/Class/Positioned.pm b/lib/DBIx/Class/Positioned.pm index d3b7cf7..02d4aac 100644 --- a/lib/DBIx/Class/Positioned.pm +++ b/lib/DBIx/Class/Positioned.pm @@ -115,12 +115,14 @@ sub siblings { my $sibling = $employee->first_sibling(); -Returns the first sibling object. +Returns the first sibling object, or 0 if the first sibling +is this sibliing. =cut sub first_sibling { my( $self ) = @_; + return 0 if ($self->get_column($self->position_column())==1); return ($self->result_source->resultset->search( { $self->position_column => 1, @@ -133,13 +135,15 @@ sub first_sibling { my $sibling = $employee->last_sibling(); -Return the last sibling. +Return the last sibling, or 0 if the last sibling is this +sibling. =cut sub last_sibling { my( $self ) = @_; my $count = $self->result_source->resultset->search({$self->_collection_clause()})->count(); + return 0 if ($self->get_column($self->position_column())==$count); return ($self->result_source->resultset->search( { $self->position_column => $count, diff --git a/t/run/26positioned.tl b/t/run/26positioned.tl index c73e257..720b173 100644 --- a/t/run/26positioned.tl +++ b/t/run/26positioned.tl @@ -2,7 +2,7 @@ sub run_tests { - plan tests => 56; + plan tests => 66; my $schema = shift; my $employees = $schema->resultset('Employee::Positioned'); @@ -44,14 +44,20 @@ sub run_tests { if ($position==1) { ok( !$employee->previous_sibling(), 'no previous sibling' ); ok( $employee->next_sibling(), 'next sibling' ); + ok( !$employee->first_sibling(), 'no first sibling' ); + ok( $employee->last_sibling(), 'last sibling' ); } elsif ($position==$employees->count()) { ok( $employee->previous_sibling(), 'previous sibling' ); ok( !$employee->next_sibling(), 'no next sibling' ); + ok( $employee->first_sibling(), 'first sibling' ); + ok( !$employee->last_sibling(), 'no last sibling' ); } else { ok( $employee->previous_sibling(), 'previous sibling' ); ok( $employee->next_sibling(), 'next sibling' ); + ok( $employee->first_sibling(), 'first sibling' ); + ok( $employee->last_sibling(), 'last sibling' ); } }