From 981ad35ce3390d473fcb63ca9cd58996b456ddc0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 Aug 2016 16:53:27 +0100 Subject: [PATCH] Bug 17091: Add delete to the Koha::Objects AUTOLOAD method Signed-off-by: Aleisha Amohia Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- Koha/Objects.pm | 4 ++-- t/db_dependent/Koha/Objects.t | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Koha/Objects.pm b/Koha/Objects.pm index dd8d221069..9d4d5915bb 100644 --- a/Koha/Objects.pm +++ b/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/.*:://; diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index 8e7dc6a123..46348e426f 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/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"; -- 2.39.5