From fe3c90f1d5bd22064103728a673c181fdd55007a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 23 Jan 2017 09:47:54 -0300 Subject: [PATCH] Bug 17932: (followup) Fix /patrons endpoint Content-Type: text/plain; charset=utf-8 Bug 17927 introduced data type fixes on the /patrons endpoint (integer and boolean types got fixed). This led to the /patrons endpoint not to work because the underlying code didn't provide the right data. With the introduction of TO_JSON on Koha::Object(s) we now have a way to output the proper data types. This patch does so by: - Adding is_boolean => 1 to the relevant columns on the Borrower.pm schema file. - Tweaking the controller class for the /patrons endpoint so it doesn't use the $object(s)->unblessed call but just let the Mojo::JSON library pick out TO_JSON implementation instead on rendering the output. - It adds a new test for booleans. To test: - Have 17927 applied - Run: $ prove t/db_dependent/api/v1/patrons.t => FAIL: Tests fail [1] - Apply this patches - Run: $ prove t/db_dependent/api/v1/patrons.t => SUCCESS: Tests pass! - Sign off! :-D [1] It is self explanatory to just try the API using any of the available tools (I use HttpRequester on Firefox) Signed-off-by: Nick Clemens Signed-off-by: Marcel de Rooy --- Koha/REST/V1/Patron.pm | 4 ++-- Koha/Schema/Result/Borrower.pm | 5 +++++ t/db_dependent/api/v1/patrons.t | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Koha/REST/V1/Patron.pm b/Koha/REST/V1/Patron.pm index b97a154..477980e 100644 --- a/Koha/REST/V1/Patron.pm +++ b/Koha/REST/V1/Patron.pm @@ -28,7 +28,7 @@ sub list { my $patrons = Koha::Patrons->search; - $c->$cb($patrons->unblessed, 200); + $c->$cb($patrons, 200); } sub get { @@ -41,7 +41,7 @@ sub get { return $c->$cb({error => "Patron not found"}, 404); } - return $c->$cb($patron->unblessed, 200); + return $c->$cb($patron, 200); } 1; diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index 1fe3988..ac414b4 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -1343,6 +1343,11 @@ __PACKAGE__->belongs_to( { borrowernumber => "guarantorid" }, ); +__PACKAGE__->add_columns( + '+lost' => { is_boolean => 1 }, + '+gonenoaddress' => { is_boolean => 1 } +); + sub koha_objects_class { 'Koha::Patrons'; } diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index f4b9410..6b3f51f 100644 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 20; +use Test::More tests => 21; use Test::Mojo; use t::lib::TestBuilder; @@ -52,7 +52,8 @@ my $borrower = $builder->build({ branchcode => $branchcode, categorycode => $categorycode, flags => 0, - guarantorid => $guarantor->{borrowernumber}, + lost => 1, + guarantorid => $guarantor->{borrowernumber}, } }); @@ -127,6 +128,7 @@ $tx->req->cookies({name => 'CGISESSID', value => $session->id}); $t->request_ok($tx) ->status_is(200) ->json_is('/borrowernumber' => $borrower->{ borrowernumber }) - ->json_is('/surname' => $borrower->{ surname }); + ->json_is('/surname' => $borrower->{ surname }) + ->json_is('/lost' => 1 ); $dbh->rollback; -- 2.1.4