Bug 17089: Mark out the boundaries of ratings
In the doc of C4::Ratings, it was written that the rate values should be >=0 and <=5, but it was not taken into account. This bug should be fixed on stable releases as well. Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
b9d5cbedc4
commit
e4136c2b3a
|
|
@ -33,6 +33,21 @@ Koha::Rating - Koha Rating Object class
|
|||
|
||||
=cut
|
||||
|
||||
=head3 store
|
||||
|
||||
=cut
|
||||
|
||||
sub store {
|
||||
my ($self) = @_;
|
||||
if ( $self->rating_value > 5 ) {
|
||||
$self->rating_value(5);
|
||||
}
|
||||
elsif ( $self->rating_value < 0 ) {
|
||||
$self->rating_value(0);
|
||||
}
|
||||
return $self->SUPER::store;
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 6;
|
||||
|
||||
use Koha::Database;
|
||||
use Koha::Rating;
|
||||
|
|
@ -43,6 +43,14 @@ $rating_1->rating_value(5)->store;
|
|||
|
||||
is( Koha::Ratings->search( { biblionumber => $biblionumber } )->get_avg_rating, 4.5, );
|
||||
|
||||
$rating_1->rating_value(42)->store;
|
||||
is( Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $patron_1->{borrowernumber} } )->rating_value,
|
||||
5, 'Koha::Ratings->store should mark out the boundaries of the rating values, 5 is max' );
|
||||
|
||||
$rating_1->rating_value(-42)->store;
|
||||
is( Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $patron_1->{borrowernumber} } )->rating_value,
|
||||
0, 'Koha::Ratings->store should mark out the boundaries of the rating values, 0 is min' );
|
||||
|
||||
Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $patron_1->{borrowernumber} } )->delete;
|
||||
Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $patron_2->{borrowernumber} } )->delete;
|
||||
is( Koha::Ratings->search( { biblionumber => $biblionumber } )->count, 0, 'Delete should have deleted the ratings' );
|
||||
|
|
|
|||
Loading…
Reference in New Issue