diff --git a/app/services/iiif_print/pluggable_derivative_service.rb b/app/services/iiif_print/pluggable_derivative_service.rb index efe08366..b9692fe9 100644 --- a/app/services/iiif_print/pluggable_derivative_service.rb +++ b/app/services/iiif_print/pluggable_derivative_service.rb @@ -41,7 +41,7 @@ def valid? true end - def respond_to_missing?(method_name) + def respond_to_missing?(method_name, include_private = false) allowed_methods.include?(method_name) || super end @@ -56,14 +56,14 @@ def services(method_name) end end - def method_missing(name, *args, **opts, &block) - if respond_to_missing?(name) + def method_missing(method_name, *args, **opts, &block) + if allowed_methods.include?(method_name) # we have an allowed method, construct services and include all valid # services for the file_set # services = plugins.map { |plugin| plugin.new(file_set) }.select(&:valid?) # run all valid services, in order: - services(name).each do |plugin| - plugin.send(name, *args) + services(method_name).each do |plugin| + plugin.send(method_name, *args) end else super @@ -73,8 +73,11 @@ def method_missing(name, *args, **opts, &block) private def skip_destination?(method_name, destination_name) - return false if file_set.id.nil? || destination_name.nil? return false unless method_name == :create_derivatives + return false unless destination_name + # NOTE: What are we after with this nil test? Are we looking for persisted objects? + return false if file_set.id.nil? + # skip :create_derivatives if existing --> do not re-create existing_derivative?(destination_name) || impending_derivative?(destination_name) diff --git a/spec/models/iiif_print/derivative_attachment_spec.rb b/spec/models/iiif_print/derivative_attachment_spec.rb index 527a3ead..4213e689 100644 --- a/spec/models/iiif_print/derivative_attachment_spec.rb +++ b/spec/models/iiif_print/derivative_attachment_spec.rb @@ -15,7 +15,7 @@ module IiifPrint destination_name: 'txt' ) # attempt save without required data; expect failure - expect { model.save! }.not_to raise_exception(ActiveRecord::RecordInvalid) + expect { model.save! }.not_to raise_exception end it "saves when all fields completely set" do @@ -23,7 +23,7 @@ module IiifPrint model.fileset_id = 'someid123' model.path = '/path/to/somefile' model.destination_name = 'txt' - expect { model.save! }.not_to raise_exception(ActiveRecord::RecordInvalid) + expect { model.save! }.not_to raise_exception end it "saves when only path, destination_name set" do @@ -31,7 +31,7 @@ module IiifPrint model.fileset_id = nil model.path = '/path/to/somefile' model.destination_name = 'txt' - expect { model.save! }.not_to raise_exception(ActiveRecord::RecordInvalid) + expect { model.save! }.not_to raise_exception end end end diff --git a/spec/models/iiif_print/ingest_file_relation_spec.rb b/spec/models/iiif_print/ingest_file_relation_spec.rb index 57b6a401..6bea32ab 100644 --- a/spec/models/iiif_print/ingest_file_relation_spec.rb +++ b/spec/models/iiif_print/ingest_file_relation_spec.rb @@ -36,14 +36,14 @@ def make_test_records file_path: '/path/to/this', derivative_path: '/path/to/that' ) - expect { model.save! }.not_to raise_exception(ActiveRecord::RecordInvalid) + expect { model.save! }.not_to raise_exception end it "will save when all fields completely set" do model = described_class.create model.file_path = '/path/to/sourcefile.tiff' model.derivative_path = '/path/to/derived.jp2' - expect { model.save! }.not_to raise_exception(ActiveRecord::RecordInvalid) + expect { model.save! }.not_to raise_exception end it "can query derivative paths for primary file" do