Browse Source

Bug 17091: Add delete to the Koha::Objects AUTOLOAD method

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
16.11.x
Jonathan Druart 8 years ago
committed by Brendan Gallagher
parent
commit
981ad35ce3
  1. 4
      Koha/Objects.pm
  2. 11
      t/db_dependent/Koha/Objects.t

4
Koha/Objects.pm

@ -233,14 +233,14 @@ The autoload method is used call DBIx::Class method on a resultset.
Important: If you plan to use one of the DBIx::Class methods you must provide
relevant tests in t/db_dependent/Koha/Objects.t
Currently count, pager, reset and update are covered.
Currently count, pager, reset, update and delete are covered.
=cut
sub AUTOLOAD {
my ( $self, @params ) = @_;
my @known_methods = qw( count pager reset update );
my @known_methods = qw( count pager reset update delete );
my $method = our $AUTOLOAD;
$method =~ s/.*:://;

11
t/db_dependent/Koha/Objects.t

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 6;
use Test::More tests => 7;
use Test::Warn;
use Koha::Authority::Types;
@ -67,6 +67,15 @@ subtest 'reset' => sub {
is( $patrons->reset->next->borrowernumber, $first_borrowernumber, 'Koha::Objects->reset should work as expected');
};
subtest 'delete' => sub {
plan tests => 2;
my $builder = t::lib::TestBuilder->new;
my $patron_1 = $builder->build({source => 'Borrower'});
my $patron_2 = $builder->build({source => 'Borrower'});
is( Koha::Patrons->search({ -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber}]}})->delete, 2, '');
is( Koha::Patrons->search({ -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber}]}})->count, 0, '');
};
subtest 'not_covered_yet' => sub {
plan tests => 1;
warning_is { Koha::Patrons->search->not_covered_yet } { carped => 'The method not_covered_yet is not covered by tests' }, "If a method is not covered by tests, the AUTOLOAD method won't execute the method";

Loading…
Cancel
Save