Bugzilla – Attachment 23670 Details for
Bug 11279
Quote of the day feature won't pick a quote
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11279: Specific case @quotes <= 1 is useless
Bug-11279-Specific-case-quotes--1-is-useless.patch (text/plain), 3.25 KB, created by
Jonathan Druart
on 2013-12-19 10:25:32 UTC
(
hide
)
Description:
Bug 11279: Specific case @quotes <= 1 is useless
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2013-12-19 10:25:32 UTC
Size:
3.25 KB
patch
obsolete
>From e237aa9d577985f08fabde2c7c9fb2df07a846d7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Thu, 19 Dec 2013 11:05:54 +0100 >Subject: [PATCH] Bug 11279: Specific case @quotes <= 1 is useless > >It is not necessary to process the case where the number of quotes. >(int(rand(1)) will always produce 0). >--- > C4/Koha.pm | 25 +++++++++---------------- > t/db_dependent/Koha/GetDailyQuote.t | 12 +++++++++++- > 2 files changed, 20 insertions(+), 17 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index f3ffcc3..4202957 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -1442,22 +1442,15 @@ sub GetDailyQuote { > $sth = C4::Context->dbh->prepare('SELECT count(*) FROM quotes;'); > $sth->execute; > my $range = ($sth->fetchrow_array)[0]; >- if ($range > 1) { >- # chose a random id within that range if there is more than one quote >- my $offset = int(rand($range)); >- # grab it >- $query = 'SELECT * FROM quotes ORDER BY id LIMIT 1 OFFSET ?'; >- $sth = C4::Context->dbh->prepare($query); >- # see http://www.perlmonks.org/?node_id=837422 for why >- # we're being verbose and using bind_param >- $sth->bind_param(1, $offset, SQL_INTEGER); >- $sth->execute(); >- } >- else { >- $query = 'SELECT * FROM quotes;'; >- $sth = C4::Context->dbh->prepare($query); >- $sth->execute(); >- } >+ # chose a random id within that range if there is more than one quote >+ my $offset = int(rand($range)); >+ # grab it >+ $query = 'SELECT * FROM quotes ORDER BY id LIMIT 1 OFFSET ?'; >+ $sth = C4::Context->dbh->prepare($query); >+ # see http://www.perlmonks.org/?node_id=837422 for why >+ # we're being verbose and using bind_param >+ $sth->bind_param(1, $offset, SQL_INTEGER); >+ $sth->execute(); > $quote = $sth->fetchrow_hashref(); > # update the timestamp for that quote > $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?'; >diff --git a/t/db_dependent/Koha/GetDailyQuote.t b/t/db_dependent/Koha/GetDailyQuote.t >index 2785b22..d003218 100644 >--- a/t/db_dependent/Koha/GetDailyQuote.t >+++ b/t/db_dependent/Koha/GetDailyQuote.t >@@ -2,7 +2,7 @@ > > use Modern::Perl; > >-use Test::More tests => 9; >+use Test::More tests => 12; > use C4::Koha qw( GetDailyQuote ); > use DateTime::Format::MySQL; > use Koha::DateUtils qw(dt_from_string); >@@ -63,5 +63,15 @@ cmp_ok($quote->{'id'}, '==', $expected_quote->{'id'}, "Id is correct"); > is($quote->{'quote'}, $expected_quote->{'quote'}, "Quote is correct"); > is($quote->{'timestamp'}, $expected_quote->{'timestamp'}, "Timestamp $timestamp is correct"); > >+$dbh->do(q|DELETE FROM quotes|); >+$quote = eval {GetDailyQuote();}; >+is( $@, '', 'GetDailyQuote does not die if no quote exist' ); >+is_deeply( $quote, {}, 'GetDailyQuote return an empty hashref is no quote exist'); # Is it what we expect? >+$dbh->do(q|INSERT INTO `quotes` VALUES >+ (6,'George Washington','To be prepared for war is one of the most effectual means of preserving peace.','0000-00-00 00:00:00') >+|); >+ >+$quote = GetDailyQuote(); >+is( $quote->{id}, 6, ' GetDailyQuote returns the only existing quote' ); > > $dbh->rollback; >-- >1.7.10.4
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 11279
:
23493
|
23494
|
23662
|
23663
|
23668
|
23669
| 23670