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

Fix ID handling in IIIF helper methods #2863

Merged
merged 4 commits into from
Jul 17, 2024
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
4 changes: 2 additions & 2 deletions app/models/spotlight/resources/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def sidecar
def to_solr
return {} unless upload&.file_present?

dimensions = Spotlight::Engine.config.iiif_service.info(id)
dimensions = Spotlight::Engine.config.iiif_service.info(upload.id)

{
spotlight_full_image_width_ssm: dimensions.width,
spotlight_full_image_height_ssm: dimensions.height,
Spotlight::Engine.config.thumbnail_field => Spotlight::Engine.config.iiif_service.thumbnail_url(upload),
Spotlight::Engine.config.iiif_manifest_field => Spotlight::Engine.config.iiif_service.manifest_url(exhibit, upload)
Spotlight::Engine.config.iiif_manifest_field => Spotlight::Engine.config.iiif_service.manifest_url(exhibit, self)
}
end

Expand Down
8 changes: 4 additions & 4 deletions lib/spotlight/riiif_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def self.info_url(image, _host = nil)
end

# @param [Spotlight::Exhibit] exhibit
# @param [Spotlight::FeaturedImage] image
# @param [Spotlight::Resource::Upload] resource
# @return [String]
def self.manifest_url(exhibit, image)
Spotlight::Engine.routes.url_helpers.manifest_exhibit_solr_document_path(exhibit, "#{exhibit.id}-#{image.id}")
def self.manifest_url(exhibit, resource)
Spotlight::Engine.routes.url_helpers.manifest_exhibit_solr_document_path(exhibit, "#{exhibit.id}-#{resource.id}")
end

# @param [String] id
# @param [String] id the ID string of a Spotlight::FeaturedImage
# @return [Hash]
def self.info(id)
Riiif::Image.new(id).info
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/spotlight/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
it 'returns a 404 when called on something other than an uploaded resource' do
get :manifest, params: { exhibit_id: exhibit, id: 'dx157dh4345' }
expect(response).not_to be_successful
expect(response.status).to eq(404)
expect(response).to have_http_status(:not_found)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
it 'gives a 404 with appropriate message when the record no longer exists' do
contact_email.destroy
delete :destroy, params: { id: contact_email, exhibit_id: contact_email.exhibit }
expect(response.status).to eq 404
expect(response).to have_http_status :not_found
expect(response.parsed_body).to eq('success' => false, 'error' => 'Not Found')
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/spotlight/solr_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
it 'raises an error' do
post_update_with_json_body(exhibit, a: 1)

expect(response.code).to eq '409'
expect(response).to have_http_status :conflict
end
end

Expand Down
18 changes: 18 additions & 0 deletions spec/models/spotlight/resources/upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
end
end

describe '#to_solr' do
subject(:solr_document) { upload.to_solr }

let(:featured_image) { instance_double(Spotlight::FeaturedImage, id: 1, file_present?: true) }

before do
allow(upload).to receive(:upload).and_return(featured_image)
allow(Spotlight::RiiifService).to receive(:thumbnail_url).with(featured_image).and_return('/a/thumbnail/url')
allow(Spotlight::RiiifService).to receive(:manifest_url).with(exhibit, upload).and_return('/a/manifest/url')
end

it 'returns a hash using the iiif service' do
expect(solr_document).to have_key(:iiif_manifest_url_ssi)
expect(solr_document).to have_key(:thumbnail_url_ssm)
expect(Spotlight::RiiifService).to have_received(:manifest_url).with(exhibit, upload)
end
end

context 'when creating' do
before do
allow(upload).to receive(:write?).and_return(false)
Expand Down