Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring specs to remove warning #111

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions app/services/iiif_print/pluggable_derivative_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/models/iiif_print/derivative_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ 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
model = described_class.create
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
model = described_class.create
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
4 changes: 2 additions & 2 deletions spec/models/iiif_print/ingest_file_relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down