Bug 18014: Add test to AuthoritiesMarc.t to expose problem in AddAuthority
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tue, 31 Jan 2017 08:11:05 +0000 (09:11 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 14 Feb 2017 14:01:10 +0000 (14:01 +0000)
Since AddAuthority uses max(id)+1 logic to produce the next authid,
authority id's will be reused when you delete the last record. This may
be a source of problems and will be addressed on the next patch.

This patch add a test to expose the problem.

Test plan:
[1] Run t/db_dependent/AuthoritiesMarc.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
t/db_dependent/AuthoritiesMarc.t

index da8241d..91025cf 100755 (executable)
@@ -5,7 +5,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 8;
+use Test::More tests => 9;
 use Test::MockModule;
 use Test::Warn;
 use MARC::Record;
@@ -191,4 +191,16 @@ is_deeply(
     'test BuildSummary for UNIMARC'
 );
 
+subtest 'AddAuthority should respect AUTO_INCREMENT (BZ 18104)' => sub {
+    plan tests => 1;
+
+    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
+    my $record = C4::AuthoritiesMarc::GetAuthority(1);
+    my $id1 = AddAuthority( $record, undef, 'GEOGR_NAME' );
+    DelAuthority( $id1 );
+    my $id2 = AddAuthority( $record, undef, 'GEOGR_NAME' );
+    is( $id1, $id2, 'FIXME: Got the same id back, let\'s fix that behavior' );
+
+};
+
 $schema->storage->txn_rollback;