Skip to content

Commit

Permalink
Increasing the test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Mar 21, 2019
1 parent c4a928a commit 67832b9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
12 changes: 5 additions & 7 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,28 @@ def document_thumbnail(document, image_options = {})
# Generate the URL for the Universal Viewer to view the content for the
# document manifest
# @return [String]
def universal_viewer_url
universal_viewer.url
end
delegate :url, to: :universal_viewer, prefix: true

private

# Generate the URL for the configuration for the UV
# @return [String]
def universal_viewer_config_url
url_base = Pomegranate.config["universal_viewer_config_url"]
url_base = Pomegranate.config["external_universal_viewer_config_url"]
"#{url_base}?manifest=#{@document.manifest}"
end

# Generate the URL for the UV viewer
# @return [String]
def universal_viewer_instance_url
Pomegranate.config["universal_viewer_url"]
def universal_viewer_installation_url
Pomegranate.config["external_universal_viewer_url"]
end

# Construct the object used to handle Universal Viewer installations
# @return [UniversalViewer]
def universal_viewer
UniversalViewer.new(
universal_viewer_instance_url,
universal_viewer_installation_url,
manifest: @document.manifest,
config: universal_viewer_config_url
)
Expand Down
4 changes: 1 addition & 3 deletions app/values/universal_viewer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# Class modeling URLs for Universal Viewer installations
class UniversalViewer

# Constructor
# @param base_url [String] URL to the installation
# @param uv_params [Hash] GET parameters to pass to the URL
Expand All @@ -19,11 +18,10 @@ def url

params = []
@params.each_pair do |name, value|
params << "#{name.to_s}=#{CGI::escape(value)}"
params << "#{name}=#{CGI.escape(value)}"
end
components += [params.join('&')]

components.join
end
end

4 changes: 2 additions & 2 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defaults: &defaults
all_collection_manifest_url: "https://figgy.princeton.edu/iiif/collections"
universal_viewer_url: "https://figgy.princeton.edu/uv/uv"
universal_viewer_config_url: "https://figgy.princeton.edu/viewer/exhibit/config"
external_universal_viewer_url: "https://figgy.princeton.edu/uv/uv"
external_universal_viewer_config_url: "https://figgy.princeton.edu/viewer/exhibit/config"
events:
server: 'amqp://localhost:5672'
exchange: 'plum_events'
Expand Down
15 changes: 15 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,19 @@
end
end
end

describe '#universal_viewer_url' do
let(:document) { instance_double(SolrDocument) }
let(:manifest_url) { 'https://figgy.princeton.edu/concern/scanned_resources/c321a5f1-26e4-46ec-9a19-7c3351eaf308/manifest' }
let(:config_url) { "https://figgy.princeton.edu/viewer/exhibit/config?manifest=#{manifest_url}" }

before do
allow(document).to receive(:manifest).and_return(manifest_url)
assign(:document, document)
end

it "generates the URL for an embedded installation of the Universal Viewer" do
expect(helper.universal_viewer_url).to eq "https://figgy.princeton.edu/uv/uv#?manifest=#{CGI.escape(manifest_url)}&config=#{CGI.escape(config_url)}"
end
end
end
8 changes: 7 additions & 1 deletion spec/models/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
let(:solr_document) { described_class.new(hsh) }
let(:hsh) do
{
"access_identifier_ssim" => "123"
"access_identifier_ssim" => "123",
"content_metadata_iiif_manifest_field_ssi" => "https://figgy.princeton.edu/concern/scanned_resources/c321a5f1-26e4-46ec-9a19-7c3351eaf308/manifest"
}
end
describe "#to_param" do
Expand All @@ -17,4 +18,9 @@
expect(solr_document.export_formats).not_to include(:oai_dc_xml, :dc_xml)
end
end
describe "#manifest" do
it "accesses the URL for the IIIF manifest" do
expect(solr_document.manifest).to eq "https://figgy.princeton.edu/concern/scanned_resources/c321a5f1-26e4-46ec-9a19-7c3351eaf308/manifest"
end
end
end
19 changes: 19 additions & 0 deletions spec/values/universal_viewer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails_helper'

RSpec.describe UniversalViewer do
subject(:universal_viewer) { described_class.new(url, **params) }

let(:url) { "https://institution.edu/viewer" }
let(:params) do
{
manifest: "https://images.institution.edu/resource1/manifest",
config: "https://institution.edu/viewer/config"
}
end

describe "#url" do
it "generates the URL for an embedded Universal Viewer installation" do
expect(universal_viewer.url).to eq "https://institution.edu/viewer#?manifest=https%3A%2F%2Fimages.institution.edu%2Fresource1%2Fmanifest&config=https%3A%2F%2Finstitution.edu%2Fviewer%2Fconfig"
end
end
end

0 comments on commit 67832b9

Please sign in to comment.