From 0bb144bbaf578ef7e4a131d640b3866bfe05fdf5 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 27 Jun 2016 10:17:20 -0300 Subject: [PATCH] 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 Signed-off-by: Jonathan Druart Signed-off-by: Jesse Weaver --- Koha/RefundLostItemFeeRule.pm | 18 ------------------ Koha/RefundLostItemFeeRules.pm | 8 ++++++-- .../mandatory/refund_lost_item_fee_rules.sql | 2 -- t/db_dependent/RefundLostItemFeeRule.t | 17 +++++++---------- 4 files changed, 13 insertions(+), 32 deletions(-) delete mode 100644 installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql diff --git a/Koha/RefundLostItemFeeRule.pm b/Koha/RefundLostItemFeeRule.pm index 2a58c064e9..56e4d93f82 100644 --- a/Koha/RefundLostItemFeeRule.pm +++ b/Koha/RefundLostItemFeeRule.pm @@ -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; diff --git a/Koha/RefundLostItemFeeRules.pm b/Koha/RefundLostItemFeeRules.pm index 3e37f4349b..479f55e586 100644 --- a/Koha/RefundLostItemFeeRules.pm +++ b/Koha/RefundLostItemFeeRules.pm @@ -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; + my $default_rule = $self->find({ branchcode => '*' }); - return $self->find({ branchcode => '*' })->refund; + return (defined $default_rule) + ? $default_rule->refund + : 1; } 1; diff --git a/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql b/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql deleted file mode 100644 index 3139805284..0000000000 --- a/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Default refund lost item fee rule -INSERT INTO refund_lost_item_fee_rules (branchcode,refund) VALUES ( '*', '1' ); diff --git a/t/db_dependent/RefundLostItemFeeRule.t b/t/db_dependent/RefundLostItemFeeRule.t index 68746e3fce..2a8a759077 100755 --- a/t/db_dependent/RefundLostItemFeeRule.t +++ b/t/db_dependent/RefundLostItemFeeRule.t @@ -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; }; -- 2.39.5