Bugzilla – Attachment 125159 Details for
Bug 29082
Add filtering methods to Koha::ArticleRequests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29082: Add filtering methods to Koha::ArticleRequests
Bug-29082-Add-filtering-methods-to-KohaArticleRequ.patch (text/plain), 6.22 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-09-22 18:25:18 UTC
(
hide
)
Description:
Bug 29082: Add filtering methods to Koha::ArticleRequests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-09-22 18:25:18 UTC
Size:
6.22 KB
patch
obsolete
>From e5629244d5eda73e86701d3beb4a0f8e1b08e59a Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 22 Sep 2021 15:23:07 -0300 >Subject: [PATCH] Bug 29082: Add filtering methods to Koha::ArticleRequests > >This patch adds handy methods for filtering Koha::ArticleRequests >resultsets. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/ArticleRequests.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/ArticleRequests.pm | 45 ++++++++- > t/db_dependent/Koha/ArticleRequests.t | 134 ++++++++++++++++++++++++++ > 2 files changed, 178 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Koha/ArticleRequests.t > >diff --git a/Koha/ArticleRequests.pm b/Koha/ArticleRequests.pm >index 662677af64..78b19255ee 100644 >--- a/Koha/ArticleRequests.pm >+++ b/Koha/ArticleRequests.pm >@@ -33,7 +33,7 @@ Koha::ArticleRequests - Koha ArticleRequests Object class > > =head1 API > >-=head2 Class Methods >+=head2 Class methods > > =cut > >@@ -60,6 +60,49 @@ sub search_limited { > return $self->search( $params, $attributes ); > } > >+=head3 filter_by_current >+ >+ my $current_article_requests = $article_requests->filter_by_current; >+ >+Returns a new resultset, filtering out finished article requests. >+ >+=cut >+ >+sub filter_by_current { >+ my ($self) = @_; >+ >+ return $self->search( >+ { >+ status => [ >+ Koha::ArticleRequest::Status::Requested, >+ Koha::ArticleRequest::Status::Pending, >+ Koha::ArticleRequest::Status::Processing, >+ ] >+ } >+ ); >+} >+ >+=head3 filter_by_finished >+ >+ my $finished_article_requests = $article_requests->filter_by_finished; >+ >+Returns a new resultset, filtering out current article requests. >+ >+=cut >+ >+sub filter_by_finished { >+ my ($self) = @_; >+ >+ return $self->search( >+ { >+ status => [ >+ Koha::ArticleRequest::Status::Completed, >+ Koha::ArticleRequest::Status::Canceled, >+ ] >+ } >+ ); >+} >+ > =head3 requested > > =cut >diff --git a/t/db_dependent/Koha/ArticleRequests.t b/t/db_dependent/Koha/ArticleRequests.t >new file mode 100755 >index 0000000000..9408712197 >--- /dev/null >+++ b/t/db_dependent/Koha/ArticleRequests.t >@@ -0,0 +1,134 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+use Koha::ArticleRequest::Status; >+use Koha::ArticleRequests; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'filter_by_current() tests' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $ar_requested = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Requested } >+ } >+ ); >+ my $ar_pending = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Pending } >+ } >+ ); >+ my $ar_processing = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Processing } >+ } >+ ); >+ my $ar_completed = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Completed } >+ } >+ ); >+ my $ar_cancelled = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Canceled } >+ } >+ ); >+ >+ my $article_requests = Koha::ArticleRequests->search( >+ { >+ id => [ >+ $ar_requested->id, $ar_pending->id, $ar_processing->id, >+ $ar_completed->id, $ar_cancelled->id >+ ] >+ } >+ ); >+ >+ my $current_article_requests = $article_requests->filter_by_current; >+ >+ is( $current_article_requests->count, 3, 'Count is correct' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'filter_by_current() tests' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $ar_requested = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Requested } >+ } >+ ); >+ my $ar_pending = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Pending } >+ } >+ ); >+ my $ar_processing = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Processing } >+ } >+ ); >+ my $ar_completed = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Completed } >+ } >+ ); >+ my $ar_cancelled = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { status => Koha::ArticleRequest::Status::Canceled } >+ } >+ ); >+ >+ my $article_requests = Koha::ArticleRequests->search( >+ { >+ id => [ >+ $ar_requested->id, $ar_pending->id, $ar_processing->id, >+ $ar_completed->id, $ar_cancelled->id >+ ] >+ } >+ ); >+ >+ my $finished_article_requests = $article_requests->filter_by_finished; >+ >+ is( $finished_article_requests->count, 2, 'Count is correct' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29082
:
125159
|
125239
|
125263
|
125639
|
125691