Skip to content

Commit

Permalink
Merge pull request #199 from scientist-softserv/setting-version-befor…
Browse files Browse the repository at this point in the history
…e-super

Ensuring version is set earlier in instantiation
  • Loading branch information
jeremyf authored Mar 23, 2023
2 parents e338428 + a237064 commit 6bba4e0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/services/iiif_print/manifest_builder_service_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ def initialize(*args,
version: IiifPrint.config.default_iiif_manifest_version,
iiif_manifest_factory: iiif_manifest_factory_for(version),
&block)
super(*args, iiif_manifest_factory: iiif_manifest_factory, &block)
# Ensure we're setting the version before we go any further.
@version = version.to_i
@child_works = nil
super(*args, iiif_manifest_factory: iiif_manifest_factory, &block)
end

attr_reader :child_works
attr_reader :child_works, :version

def manifest_for(presenter:)
@child_works = get_solr_hits(member_ids_for(presenter))
Expand Down
2 changes: 1 addition & 1 deletion lib/iiif_print/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def excluded_model_name_solr_field_key

attr_writer :default_iiif_manifest_version
def default_iiif_manifest_version
@default_iiif_manifest_version || 2
@default_iiif_manifest_version.presence || 2
end

attr_writer :metadata_fields
Expand Down
20 changes: 20 additions & 0 deletions spec/iiif_print/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,24 @@
.to("-l esperanto")
end
end

describe '#default_iiif_manifest_version' do
subject { config.default_iiif_manifest_version }

context 'default' do
it { is_expected.to eq 2 }
end

context 'when set to empty' do
before { config.default_iiif_manifest_version = '' }
it { is_expected.to eq 2 }
end

it 'can be set' do
expect { config.default_iiif_manifest_version = 3 }
.to change(config, :default_iiif_manifest_version)
.from(2)
.to(3)
end
end
end
20 changes: 20 additions & 0 deletions spec/services/iiif_print/manifest_builder_service_behavior_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe IiifPrint::ManifestBuilderServiceBehavior do
context '#initialize' do
it 'uses defaults to set the version' do
builder_service = Hyrax::ManifestBuilderService.new
expect(builder_service.manifest_factory).to eq(::IIIFManifest::ManifestFactory)
expect(builder_service.version).to eq(IiifPrint.config.default_iiif_manifest_version)
end

it 'allows version overrides' do
# This in part verifies the expected interaction of the version as a parameter being picked up
# by another parameter.
builder_service = Hyrax::ManifestBuilderService.new(version: 3)
expect(builder_service.manifest_factory).to eq(::IIIFManifest::V3::ManifestFactory)
expect(builder_service.version).to eq(3)
end
end
end

0 comments on commit 6bba4e0

Please sign in to comment.