Skip to content

Commit

Permalink
Allow abid generation in the presence of object without a suffix (#77)
Browse files Browse the repository at this point in the history
When an abid model object is created without an abid archival
identifier, its suffix in the database is nil. When we attempt to create
an abid, it has to find the last identifier, and if that identifier is
nil the system cannot determine what number should come next. Therefore,
exclude nil suffix objects from consideration when determining the next
archival identifier.

Co-authored-by: Trey Pendraon <tpendragon@princeton.edu>
  • Loading branch information
bess and tpendragon authored Sep 22, 2021
1 parent 1cbfd63 commit 33e68e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/absolute_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def cache_holding_id
private

def highest_identifier
self.class.where(prefix: prefix, pool_identifier: pool_identifier).order(suffix: :desc).pick(:suffix) || last_legacy_identifier
self.class.where(prefix: prefix, pool_identifier: pool_identifier).where.not(suffix: nil).order(suffix: :desc).pick(:suffix) || last_legacy_identifier
end

# The old database ended identifiers for each pool at certain numbers - ensure
Expand Down
5 changes: 5 additions & 0 deletions app/services/barcode_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# frozen_string_literal: true

##
# Given a barcode, be able to get the next one in the sequence. This is coded
# against the barcodes used specifically at Princeton. Uses Luhn algorithm (*not*
# codabar algorithm).
class BarcodeService
def self.valid?(barcode)
new(barcode).valid?
Expand Down
7 changes: 7 additions & 0 deletions spec/models/absolute_identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
expect(firestone1.full_identifier).to be_blank
end
end
context "generate_abid==true AFTER generate_abid==false" do
it "does not raise an error" do
FactoryBot.create(:batch, first_barcode: "32101113344913").absolute_identifiers.first
FactoryBot.create(:batch, generate_abid: false).absolute_identifiers.first
expect { FactoryBot.create(:batch, first_barcode: "32101113344921").absolute_identifiers.first }.not_to raise_error
end
end
end

describe "#synchronize" do
Expand Down

0 comments on commit 33e68e1

Please sign in to comment.