diff --git a/app/models/absolute_identifier.rb b/app/models/absolute_identifier.rb index c2ab56f..a0c59fb 100644 --- a/app/models/absolute_identifier.rb +++ b/app/models/absolute_identifier.rb @@ -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 diff --git a/app/services/barcode_service.rb b/app/services/barcode_service.rb index 64e19ad..6e0d46c 100644 --- a/app/services/barcode_service.rb +++ b/app/services/barcode_service.rb @@ -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? diff --git a/spec/models/absolute_identifier_spec.rb b/spec/models/absolute_identifier_spec.rb index b66ee7e..cb33b4d 100644 --- a/spec/models/absolute_identifier_spec.rb +++ b/spec/models/absolute_identifier_spec.rb @@ -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