From efa6fa3411890300ff6cb1a97add621d1797020e Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Fri, 18 Oct 2024 11:35:42 +0200 Subject: [PATCH] Fix check for data import exclusion Add spec --- app/models/concerns/indexable.rb | 2 +- spec/models/doi_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index cc4c0e61c..4bf789337 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -26,7 +26,7 @@ module Indexable if aasm_state == "findable" changed_attributes = saved_changes relevant_changes = changed_attributes.keys & %w[related_identifiers creators funding_references aasm_state] - if relevant_changes.any? || (created == updated) && !ENV["EXCLUDE_PREFIXES_FROM_DATA_IMPORT"].to_s.split(",").include?(prefix) + if (relevant_changes.any? || (created == updated)) && !ENV["EXCLUDE_PREFIXES_FROM_DATA_IMPORT"].to_s.split(",").include?(prefix) send_import_message(to_jsonapi) Rails.logger.info "[Event Data Import Message] State: #{aasm_state} Params: #{to_jsonapi} message sent to Event Data service." end diff --git a/spec/models/doi_spec.rb b/spec/models/doi_spec.rb index ebd6dd484..5e97b64a7 100644 --- a/spec/models/doi_spec.rb +++ b/spec/models/doi_spec.rb @@ -84,6 +84,13 @@ expect(new_doi).not_to receive(:send_import_message) end + + it "does not send import message when environment variable EXCLUDE_PREFIXES_FROM_DATA_IMPORT is set to prefix of doi" do + ENV["EXCLUDE_PREFIXES_FROM_DATA_IMPORT"] = "10.18730" + new_doi = create(:doi, doi: "10.18730/nvb5=", aasm_state: "findable") + + expect(new_doi).not_to receive(:send_import_message) + end end context "On Create event" do