diff --git a/app/models/detector/lcsh.rb b/app/models/detector/lcsh.rb index b2c5d05..0d97e53 100644 --- a/app/models/detector/lcsh.rb +++ b/app/models/detector/lcsh.rb @@ -28,7 +28,8 @@ def self.record(term) results.identifiers.each_key do Detection.find_or_create_by( term:, - detector: Detector.where(name: 'LCSH').first + detector: Detector.where(name: 'LCSH').first, + detector_version: ENV.fetch('DETECTOR_VERSION', 'unset') ) end diff --git a/test/models/detector/lcsh_test.rb b/test/models/detector/lcsh_test.rb index 15d56e4..3372601 100644 --- a/test/models/detector/lcsh_test.rb +++ b/test/models/detector/lcsh_test.rb @@ -49,5 +49,24 @@ class LcshTest < ActiveSupport::TestCase assert_equal(detection_count, Detection.count) end + + test 'record respects changes to the DETECTOR_VERSION value' do + # Create a relevant detection + Detector::Lcsh.record(terms('lcsh')) + + detection_count = Detection.count + + # Calling the record method again doesn't do anything, but does not error. + Detector::Lcsh.record(terms('lcsh')) + + assert_equal(detection_count, Detection.count) + + # Calling the record method after DETECTOR_VERSION is incremented results in a new Detection + ClimateControl.modify DETECTOR_VERSION: 'updated' do + Detector::Lcsh.record(terms('lcsh')) + + assert_equal detection_count + 1, Detection.count + end + end end end