From 62c2dcad28553e2611d77da2ca536c55ed362d7a 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 --- 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 dd8d221..9d4d591 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 8e7dc6a..46348e4 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.1.4