Bug 14048: (QA followup) Default to 1 if no default rule

This patch answers Jonathan's request to simplify this patchset a bit.

It removes the need for the .sql file, as _default_rule now defaults to
a fixed value (1, which was set by the removed .sql file).
This allowed to remove the overloaded ->delete method.

The tests have been adjusted to reflect this changes, including tests for
the new 'default'-if-absent situation.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2016-06-27 10:17:20 -03:00 committed by Jesse Weaver
parent 1887b7ab3e
commit 0bb144bbaf
4 changed files with 14 additions and 33 deletions

View file

@ -42,22 +42,4 @@ sub _type {
return 'RefundLostItemFeeRule';
}
=head3 delete
This is an overloaded delete method. It throws an exception if the wildcard
branch is passed (it can only be modified, but not deleted).
=cut
sub delete {
my ($self) = @_;
if ( $self->branchcode eq '*' ) {
Koha::Exceptions::CannotDeleteDefault->throw;
}
return $self->SUPER::delete($self);
}
1;

View file

@ -130,14 +130,18 @@ sub _choose_branch {
=head3 _default_rule (internal)
This function returns the default rule defined for refunding lost
item fees on return.
item fees on return. It defaults to 1 if no rule is defined.
=cut
sub _default_rule {
my $self = shift;
return $self->find({ branchcode => '*' })->refund;
my $self = shift;
my $default_rule = $self->find({ branchcode => '*' });
return (defined $default_rule)
? $default_rule->refund
: 1;
}
1;

View file

@ -1,2 +0,0 @@
-- Default refund lost item fee rule
INSERT INTO refund_lost_item_fee_rules (branchcode,refund) VALUES ( '*', '1' );

View file

@ -35,7 +35,7 @@ my $builder = t::lib::TestBuilder->new;
subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub {
plan tests => 7;
plan tests => 5;
# Start transaction
$schema->storage->txn_begin;
@ -68,21 +68,13 @@ subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub {
$other_rule->delete;
ok( !$other_rule->in_storage, 'Other rule deleted from storage' );
# deleting the default rule
eval {
$default_rule->delete;
};
is( ref($@), 'Koha::Exceptions::CannotDeleteDefault',
'Exception on deleting default' );
ok( $default_rule->in_storage, 'Default rule still in storage' );
# Rollback transaction
$schema->storage->txn_rollback;
};
subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub {
plan tests => 4;
plan tests => 6;
# Start transaction
$schema->storage->txn_begin;
@ -115,6 +107,11 @@ subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub {
branchcode => '*' });
ok( !Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to not refund' );
$default_rule->delete;
ok( !$default_rule->in_storage, 'Default rule effectively deleted from storage' );
ok( Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to refund if no default rule is present' );
# Rollback transaction
$schema->storage->txn_rollback;
};