Skip to content

Commit

Permalink
Allow nil source_uri for Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
elohanlon committed Dec 24, 2024
1 parent f5f7391 commit 9e08b40
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/concerns/triclops/resource/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/models/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e08b40

Please sign in to comment.