diff --git a/app/models/concerns/triclops/resource/validations.rb b/app/models/concerns/triclops/resource/validations.rb index 7702b37..acc83b0 100644 --- a/app/models/concerns/triclops/resource/validations.rb +++ b/app/models/concerns/triclops/resource/validations.rb @@ -4,7 +4,9 @@ module Validations extend ActiveSupport::Concern included do - validates :identifier, :pcdm_type, :source_uri, presence: true + # NOTE: :source_uri is NOT required, since it's okay to create a Resource with no_uri and only a pcdm_type + # when derivatives have not yet been created for the resource, but we want to show a pdcm-type-based placeholder. + validates :identifier, :pcdm_type, presence: true validates :identifier, length: { minimum: 1, maximum: 255 } validates :standard_width, :standard_height, :limited_width, :limited_height, diff --git a/app/models/resource.rb b/app/models/resource.rb index 0df0d25..934800a 100644 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -58,6 +58,7 @@ def delete_filesystem_cache! end def queue_base_derivative_generation_if_pending + return if self.source_uri.nil? return unless self.pending? CreateBaseDerivativesJob.perform_later(self.identifier) end diff --git a/spec/models/resource_spec.rb b/spec/models/resource_spec.rb index 82d3175..1fb16ae 100644 --- a/spec/models/resource_spec.rb +++ b/spec/models/resource_spec.rb @@ -85,6 +85,12 @@ expect(CreateBaseDerivativesJob).not_to receive(:perform_later) ready_resource.queue_base_derivative_generation_if_pending end + + it "does not queue generation for a resource with a nil source_uri, even if it has a ready status" do + ready_resource.source_uri = nil + expect(CreateBaseDerivativesJob).not_to receive(:perform_later) + ready_resource.queue_base_derivative_generation_if_pending + end end describe '#switch_to_pending_state_if_core_properties_changed!' do