geoblacklight 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -3
- data/app/assets/javascripts/geoblacklight/geoblacklight.js +1 -1
- data/app/assets/javascripts/geoblacklight/modules/metadata.js +7 -0
- data/app/assets/javascripts/geoblacklight/modules/metadata_download_button.js +58 -0
- data/app/assets/javascripts/geoblacklight/modules/results.js +10 -15
- data/app/assets/stylesheets/geoblacklight/_geoblacklight.scss +3 -2
- data/app/assets/stylesheets/geoblacklight/modules/metadata.scss +27 -3
- data/app/assets/stylesheets/geoblacklight/modules/metadata_content.scss +38 -0
- data/app/assets/stylesheets/geoblacklight/modules/metadata_markup.scss +9 -0
- data/app/assets/stylesheets/geoblacklight/modules/metadata_missing.scss +7 -0
- data/app/helpers/geoblacklight_helper.rb +24 -0
- data/app/presenters/geoblacklight/document_presenter.rb +2 -1
- data/app/views/catalog/_metadata.html.erb +21 -6
- data/app/views/catalog/metadata/_content.html.erb +3 -0
- data/app/views/catalog/metadata/_markup.html.erb +8 -0
- data/app/views/catalog/metadata/_missing.html.erb +6 -0
- data/app/views/catalog/metadata.js.erb +8 -4
- data/config/locales/geoblacklight.en.yml +1 -0
- data/geoblacklight.gemspec +4 -1
- data/lib/generators/geoblacklight/templates/settings.yml +2 -2
- data/lib/geoblacklight/engine.rb +2 -1
- data/lib/geoblacklight/metadata/base.rb +88 -0
- data/lib/geoblacklight/metadata/fgdc.rb +14 -0
- data/lib/geoblacklight/metadata/iso19139.rb +14 -0
- data/lib/geoblacklight/metadata.rb +12 -31
- data/lib/geoblacklight/metadata_transformer/base.rb +49 -0
- data/lib/geoblacklight/metadata_transformer/fgdc.rb +16 -0
- data/lib/geoblacklight/metadata_transformer/iso19139.rb +16 -0
- data/lib/geoblacklight/metadata_transformer.rb +33 -0
- data/lib/geoblacklight/references.rb +14 -0
- data/lib/geoblacklight/version.rb +1 -1
- data/lib/geoblacklight/view_helper_override.rb +3 -2
- data/lib/geoblacklight.rb +7 -0
- data/spec/features/download_layer_spec.rb +5 -2
- data/spec/features/layer_inspection_spec.rb +1 -1
- data/spec/features/metadata_panel_spec.rb +15 -4
- data/spec/features/saved_searches_spec.rb +1 -1
- data/spec/features/split_view.html.erb_spec.rb +2 -2
- data/spec/fixtures/solr_documents/harvard_raster.json +2 -2
- data/spec/fixtures/solr_documents/public_iiif_princeton.json +1 -1
- data/spec/helpers/{geoblacklight_helpers_spec.rb → geoblacklight_helper_spec.rb} +54 -0
- data/spec/javascripts/geoblacklight_spec.js +4 -0
- data/spec/javascripts/metadata_download_button_spec.js +14 -0
- data/spec/lib/geoblacklight/metadata/base_spec.rb +85 -0
- data/spec/lib/geoblacklight/metadata_spec.rb +26 -18
- data/spec/lib/geoblacklight/metadata_transformer/base_spec.rb +35 -0
- data/spec/lib/geoblacklight/metadata_transformer/fgdc_spec.rb +23 -0
- data/spec/lib/geoblacklight/metadata_transformer/iso19139_spec.rb +23 -0
- data/spec/lib/geoblacklight/metadata_transformer_spec.rb +69 -0
- data/spec/lib/geoblacklight/references_spec.rb +12 -1
- data/spec/lib/geoblacklight/view_helper_override_spec.rb +1 -0
- data/spec/spec_helper.rb +11 -8
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +2 -0
- data/spec/test_app_templates/metadata/fgdc.html +129 -0
- data/spec/test_app_templates/metadata/fgdc.xml +145 -0
- data/spec/test_app_templates/metadata/iso.html +275 -0
- data/spec/test_app_templates/metadata/iso.xml +511 -0
- data/spec/test_app_templates/solr_documents +1 -1
- metadata +83 -7
- data/app/assets/stylesheets/geoblacklight/modules/coderay.scss +0 -147
@@ -0,0 +1,49 @@
|
|
1
|
+
module Geoblacklight
|
2
|
+
module MetadataTransformer
|
3
|
+
##
|
4
|
+
# Abstract class for transforming geospatial metadata
|
5
|
+
class Base
|
6
|
+
##
|
7
|
+
# @param [GeoCombine::Metadata] metadata metadata Object
|
8
|
+
# @see GeoCombine::Metadata
|
9
|
+
def initialize(metadata)
|
10
|
+
@metadata = metadata
|
11
|
+
# Access the Nokogiri::XML Document from the metadata Object
|
12
|
+
fail EmptyMetadataError, 'Failed to retrieve the metadata' if @metadata.blank?
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Returns HTML for the metadata transformed into HTML using GeoCombine
|
17
|
+
# @see GeoCombine::Metadata#to_html
|
18
|
+
# @return [String] the transformed metadata in the HTML
|
19
|
+
def transform
|
20
|
+
cleaned_metadata.to_html
|
21
|
+
rescue => e
|
22
|
+
raise TransformError, e.message
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
##
|
28
|
+
# Clean top-level HTML elements from GeoCombine HTML Documents (e. g. <html> and <body>)
|
29
|
+
# @return [Nokogiri::XML::Document] the Nokogiri XML Document for the cleaned HTML
|
30
|
+
def cleaned_metadata
|
31
|
+
transformed_doc = Nokogiri::XML(@metadata.to_html)
|
32
|
+
if transformed_doc.xpath('//body').children.empty?
|
33
|
+
fail TransformError,\
|
34
|
+
'Failed to extract the <body> child elements from the transformed metadata'
|
35
|
+
end
|
36
|
+
transformed_doc.xpath('//body').children
|
37
|
+
rescue => e
|
38
|
+
raise TransformError, e.message
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Retrieve the Class for the GeoCombine::Metadata instance
|
43
|
+
# @return [GeoCombine::Metadata]
|
44
|
+
def metadata_class
|
45
|
+
GeoCombine::Metadata
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Geoblacklight
|
2
|
+
module MetadataTransformer
|
3
|
+
##
|
4
|
+
# Class for transforming FGDC XML Documents
|
5
|
+
class Fgdc < Base
|
6
|
+
private
|
7
|
+
|
8
|
+
##
|
9
|
+
# Retrieve the Class for the GeoCombine::Metadata instance
|
10
|
+
# @return [GeoCombine::Fgdc]
|
11
|
+
def metadata_class
|
12
|
+
GeoCombine::Fgdc
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Geoblacklight
|
2
|
+
module MetadataTransformer
|
3
|
+
##
|
4
|
+
# Class for transforming ISO19139 XML Documents
|
5
|
+
class Iso19139 < Base
|
6
|
+
private
|
7
|
+
|
8
|
+
##
|
9
|
+
# Retrieve the Class for the GeoCombine::Metadata instance
|
10
|
+
# @return [GeoCombine::Iso19139]
|
11
|
+
def metadata_class
|
12
|
+
GeoCombine::Iso19139
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'geo_combine'
|
2
|
+
|
3
|
+
module Geoblacklight
|
4
|
+
module MetadataTransformer
|
5
|
+
##
|
6
|
+
# Exceptions raised for the types of geospatial metadata
|
7
|
+
class TypeError < EncodingError; end
|
8
|
+
##
|
9
|
+
# Exceptions raised when parsing geospatial metadata in the XML
|
10
|
+
class ParseError < EncodingError; end
|
11
|
+
##
|
12
|
+
# Exception raised when the geospatial metadata content is empty
|
13
|
+
class EmptyMetadataError < ParseError; end
|
14
|
+
##
|
15
|
+
# Exceptions raised when transforming the metadata into the HTML
|
16
|
+
class TransformError < EncodingError; end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Initialize a new MetadataTransformer instance
|
20
|
+
# @param [Geoblacklight::Metadata::Base] metadata string or File path to the raw metadata
|
21
|
+
# @return [Geoblacklight::MetadataTransformer::BaseTransformer]
|
22
|
+
def self.instance(metadata)
|
23
|
+
type = metadata.class.name.split('::').last
|
24
|
+
begin
|
25
|
+
klass = "Geoblacklight::MetadataTransformer::#{type.capitalize}".constantize
|
26
|
+
rescue
|
27
|
+
raise TypeError, "Metadata type #{type} is not supported"
|
28
|
+
end
|
29
|
+
|
30
|
+
klass.new(metadata)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -8,6 +8,20 @@ module Geoblacklight
|
|
8
8
|
@refs = parse_references.map { |ref| Reference.new(ref) }
|
9
9
|
end
|
10
10
|
|
11
|
+
##
|
12
|
+
# Return only those metadata references which are exposed within the configuration
|
13
|
+
# @return [Geoblacklight::Reference]
|
14
|
+
def shown_metadata_refs
|
15
|
+
@refs.select { |ref| Settings.METADATA_SHOWN.include?(ref.type.to_s) }
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Return only metadata for shown metadata
|
20
|
+
# @return [Geoblacklight::Metadata::Base]
|
21
|
+
def shown_metadata
|
22
|
+
@shown_metadata ||= shown_metadata_refs.map { |ref| Geoblacklight::Metadata.instance(ref) }
|
23
|
+
end
|
24
|
+
|
11
25
|
##
|
12
26
|
# Accessor for a document's file format
|
13
27
|
# @return [String] file format for the document
|
@@ -21,7 +21,7 @@ module Geoblacklight
|
|
21
21
|
|
22
22
|
def render_search_to_s_bbox(params)
|
23
23
|
return ''.html_safe if params['bbox'].blank?
|
24
|
-
render_search_to_s_element('
|
24
|
+
render_search_to_s_element(t('geoblacklight.bbox_label'), render_filter_value(params['bbox']))
|
25
25
|
end
|
26
26
|
|
27
27
|
def render_constraints_filters(localized_params = params)
|
@@ -30,7 +30,8 @@ module Geoblacklight
|
|
30
30
|
|
31
31
|
if localized_params[:bbox]
|
32
32
|
path = search_action_path(remove_spatial_filter_group(:bbox, localized_params))
|
33
|
-
content << render_constraint_element('
|
33
|
+
content << render_constraint_element(t('geoblacklight.bbox_label'),
|
34
|
+
localized_params[:bbox], remove: path)
|
34
35
|
end
|
35
36
|
|
36
37
|
content
|
data/lib/geoblacklight.rb
CHANGED
@@ -19,6 +19,13 @@ module Geoblacklight
|
|
19
19
|
require 'geoblacklight/download/shapefile_download'
|
20
20
|
require 'geoblacklight/download/hgl_download'
|
21
21
|
require 'geoblacklight/metadata'
|
22
|
+
require 'geoblacklight/metadata/base'
|
23
|
+
require 'geoblacklight/metadata/fgdc'
|
24
|
+
require 'geoblacklight/metadata/iso19139'
|
25
|
+
require 'geoblacklight/metadata_transformer'
|
26
|
+
require 'geoblacklight/metadata_transformer/base'
|
27
|
+
require 'geoblacklight/metadata_transformer/fgdc'
|
28
|
+
require 'geoblacklight/metadata_transformer/iso19139'
|
22
29
|
require 'geoblacklight/reference'
|
23
30
|
require 'geoblacklight/references'
|
24
31
|
require 'geoblacklight/routes'
|
@@ -43,7 +43,7 @@ feature 'Download layer' do
|
|
43
43
|
end
|
44
44
|
scenario 'clicking jpg download button should redirect to external image' do
|
45
45
|
visit solr_document_path('princeton-02870w62c')
|
46
|
-
expect(page).to have_css("a.btn.btn-default[href='
|
46
|
+
expect(page).to have_css("a.btn.btn-default[href='https://libimages.princeton.edu/loris/pudl0076/map_pownall/00000001.jp2/full/full/0/default.jpg']", text: 'Download JPG')
|
47
47
|
end
|
48
48
|
scenario 'options should be available under toggle' do
|
49
49
|
visit solr_document_path('mit-us-ma-e25zcta5dct-2000')
|
@@ -86,6 +86,9 @@ feature 'Download layer' do
|
|
86
86
|
fill_in('Email', with: 'foo@example.com')
|
87
87
|
click_button('Request')
|
88
88
|
end
|
89
|
-
|
89
|
+
using_wait_time 45 do
|
90
|
+
expect(page).to have_css('.alert-success')
|
91
|
+
expect(page).to have_content('You should receive an email when your download is ready')
|
92
|
+
end
|
90
93
|
end
|
91
94
|
end
|
@@ -4,7 +4,7 @@ feature 'Layer inspection', js: true do
|
|
4
4
|
scenario 'clicking map should trigger inspection' do
|
5
5
|
visit solr_document_path('mit-us-ma-e25zcta5dct-2000')
|
6
6
|
expect(page).to have_css('th', text: 'Attribute')
|
7
|
-
find('#map').
|
7
|
+
find('#map').click
|
8
8
|
expect(page).not_to have_css('td.default-text')
|
9
9
|
end
|
10
10
|
end
|
@@ -2,15 +2,26 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
feature 'Metadata tools' do
|
4
4
|
feature 'when metadata references are available', js: :true do
|
5
|
-
scenario 'shows up
|
5
|
+
scenario 'shows up as HTML' do
|
6
|
+
visit solr_document_path 'columbia-columbia-landinfo-global-aet'
|
7
|
+
expect(page).to have_css 'li.metadata a', text: 'Metadata'
|
8
|
+
click_link 'Metadata'
|
9
|
+
using_wait_time 15 do
|
10
|
+
within '.metadata-view' do
|
11
|
+
expect(page).to have_css '.pill-metadata', text: 'FGDC'
|
12
|
+
expect(page).to have_css 'dt', text: 'Identification Information'
|
13
|
+
expect(page).to have_css 'dt', text: 'Metadata Reference Information'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
scenario 'shows up as XML' do
|
6
18
|
visit solr_document_path 'stanford-cg357zz0321'
|
7
19
|
expect(page).to have_css 'li.metadata a', text: 'Metadata'
|
8
20
|
click_link 'Metadata'
|
9
21
|
using_wait_time 15 do
|
10
22
|
within '.metadata-view' do
|
11
|
-
expect(page).to have_css '
|
12
|
-
expect(page).to have_css '
|
13
|
-
expect(page).to have_css 'div.label', text: 'ISO 19139'
|
23
|
+
expect(page).to have_css '.pill-metadata', text: 'MODS'
|
24
|
+
expect(page).to have_css '.CodeRay'
|
14
25
|
end
|
15
26
|
end
|
16
27
|
end
|
@@ -8,6 +8,6 @@ feature 'saved searches' do
|
|
8
8
|
expect(page.current_url).to match(/bbox=/)
|
9
9
|
end
|
10
10
|
visit blacklight.search_history_path
|
11
|
-
expect(page).to have_css 'td.query a', text:
|
11
|
+
expect(page).to have_css 'td.query a', text: /#{I18n.t('geoblacklight.bbox_label')}:/
|
12
12
|
end
|
13
13
|
end
|
@@ -34,14 +34,14 @@ feature 'Index view', js: true do
|
|
34
34
|
# Needed to find an svg element on the page
|
35
35
|
visit search_catalog_path(f: { Settings.FIELDS.PROVENANCE => ['Stanford'] })
|
36
36
|
expect(Nokogiri::HTML.parse(page.body).css('path').length).to eq 0
|
37
|
-
find('.documentHeader', match: :first).
|
37
|
+
find('.documentHeader', match: :first).hover
|
38
38
|
expect(Nokogiri::HTML.parse(page.body).css('path').length).to eq 1
|
39
39
|
end
|
40
40
|
|
41
41
|
scenario 'click on a record area to expand collapse' do
|
42
42
|
within('.documentHeader', match: :first) do
|
43
43
|
expect(page).not_to have_css('.collapse')
|
44
|
-
find('.status-icons').
|
44
|
+
find('.status-icons').click
|
45
45
|
expect(page).to have_css('.collapse', visible: true)
|
46
46
|
end
|
47
47
|
end
|
@@ -26,7 +26,7 @@
|
|
26
26
|
],
|
27
27
|
"dc_title_s": "Saint Petersburg Region, Russia, 1834 (Raster Image)",
|
28
28
|
"dc_type_s": "Dataset",
|
29
|
-
"dct_references_s": "{\"http://schema.org/DownloadAction\":\"http://
|
29
|
+
"dct_references_s": "{\"http://schema.org/DownloadAction\":\"http://pelham.lib.harvard.edu:8080/HGL/HGLOpenDelivery\",\"http://www.opengis.net/def/serviceType/ogc/wcs\":\"http://pelham.lib.harvard.edu:8090/geoserver/wcs\",\"http://www.opengis.net/def/serviceType/ogc/wms\":\"http://pelham.lib.harvard.edu:8090/geoserver/wms\",\"http://www.opengis.net/cat/csw/csdgm\":\"https://raw.githubusercontent.com/OpenGeoMetadata/edu.harvard/master/217/121/227/77/fgdc.xml\"}",
|
30
30
|
"dct_spatial_sm": [
|
31
31
|
"Russia Saint Petersburg"
|
32
32
|
],
|
@@ -36,7 +36,7 @@
|
|
36
36
|
"dct_issued_s": "2000",
|
37
37
|
"dct_provenance_s": "Harvard",
|
38
38
|
"layer_slug_s": "harvard-g7064-s2-1834-k3",
|
39
|
-
"layer_id_s": "cite:
|
39
|
+
"layer_id_s": "cite:G7064_S2_1834_K3",
|
40
40
|
"layer_geom_type_s": "Raster",
|
41
41
|
"layer_modified_dt": "2014-05-27T18:09:36Z",
|
42
42
|
"solr_geom": "ENVELOPE(30.013108, 30.875309, 60.041712, 59.669749)",
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"Rogers, Henry Darwin",
|
17
17
|
"Pownall, Thomas"
|
18
18
|
],
|
19
|
-
"dct_references_s": "{\"http://schema.org/url\":\"http://arks.princeton.edu/ark:/88435/02870w62c\",\"http://schema.org/thumbnailUrl\":\"
|
19
|
+
"dct_references_s": "{\"http://schema.org/url\":\"http://arks.princeton.edu/ark:/88435/02870w62c\",\"http://schema.org/thumbnailUrl\":\"https://libimages.princeton.edu/loris2/pudl0076%2Fmap_pownall%2F00000001.jp2/full/50,/0/default.jpg\",\"http://iiif.io/api/image\":\"https://libimages.princeton.edu/loris/pudl0076/map_pownall/00000001.jp2/info.json\"}",
|
20
20
|
"dct_spatial_sm": [
|
21
21
|
"New York (State)",
|
22
22
|
"New Jersey",
|
@@ -155,4 +155,58 @@ describe GeoblacklightHelper, type: :helper do
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
158
|
+
|
159
|
+
describe '#render_transformed_metadata' do
|
160
|
+
let(:metadata) { instance_double(Geoblacklight::Metadata::Base) }
|
161
|
+
context 'with valid XML data' do
|
162
|
+
before do
|
163
|
+
allow(metadata).to receive(:transform).and_return('<div>test</div>')
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'renders the partial with metadata content' do
|
167
|
+
expect(helper).to receive(:render)
|
168
|
+
.with(partial: 'catalog/metadata/content', locals: { content: '<div>test</div>' })
|
169
|
+
helper.render_transformed_metadata(metadata)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'with valid XML data without an HTML transform' do
|
174
|
+
before do
|
175
|
+
allow(metadata).to receive(:transform).and_raise(Geoblacklight::MetadataTransformer::TransformError)
|
176
|
+
allow(metadata).to receive(:to_xml).and_return('<data></data>')
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'renders the partial with metadata content' do
|
180
|
+
expect(helper).to receive(:render).with(partial: 'catalog/metadata/markup', locals: { content: '<data></data>' })
|
181
|
+
helper.render_transformed_metadata(metadata)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'without XML data' do
|
186
|
+
before do
|
187
|
+
allow(metadata).to receive(:transform).and_raise(Geoblacklight::MetadataTransformer::ParseError)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'renders the partial with metadata content' do
|
191
|
+
expect(helper).to receive(:render).with(partial: 'catalog/metadata/missing')
|
192
|
+
helper.render_transformed_metadata(metadata)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '#first_metadata?' do
|
198
|
+
let(:metadata) { instance_double(Geoblacklight::Metadata::Base) }
|
199
|
+
let(:references) { instance_double(Geoblacklight::References) }
|
200
|
+
let(:document) { instance_double(SolrDocument) }
|
201
|
+
|
202
|
+
before do
|
203
|
+
allow(document).to receive(:references).and_return(references)
|
204
|
+
allow(references).to receive(:shown_metadata).and_return([metadata])
|
205
|
+
allow(metadata).to receive(:type).and_return('fgdc')
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'confirms that a metadata resource is the first item reference' do
|
209
|
+
expect(helper.first_metadata?(document, metadata)).to be true
|
210
|
+
end
|
211
|
+
end
|
158
212
|
end
|
@@ -9,5 +9,9 @@ describe('GeoBlacklight', function() {
|
|
9
9
|
it('History.js is defined', function() {
|
10
10
|
expect(History).toBeDefined();
|
11
11
|
});
|
12
|
+
|
13
|
+
it('MetadataDownloadButton is defined', function() {
|
14
|
+
expect(GeoBlacklight.MetadataDownloadButton).toBeDefined();
|
15
|
+
});
|
12
16
|
});
|
13
17
|
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
//= require geoblacklight
|
2
|
+
|
3
|
+
describe('MetadataDownloadButton', function() {
|
4
|
+
describe('initialize', function() {
|
5
|
+
fixture.set('<button id="foo" data-ref-endpoint="http://testdomain" data-ref-download="#bar">test element</button><a href="http://test2domain" id="bar">another test element</a>');
|
6
|
+
|
7
|
+
it('creates a new instance and sets the download button @href value', function() {
|
8
|
+
var button = new GeoBlacklight.MetadataDownloadButton('#foo');
|
9
|
+
expect(button.$el.attr('id')).toBe('foo');
|
10
|
+
expect(button.$download.attr('id')).toBe('bar');
|
11
|
+
expect(button.$download.attr('href')).toBe('http://testdomain');
|
12
|
+
});
|
13
|
+
});
|
14
|
+
});
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Geoblacklight::Metadata::Base do
|
4
|
+
let(:connection) { instance_double(Faraday::Connection) }
|
5
|
+
let(:response) { instance_double(Faraday::Response) }
|
6
|
+
let(:opengeometadata) do
|
7
|
+
described_class.new(
|
8
|
+
Geoblacklight::Reference.new(
|
9
|
+
['http://www.loc.gov/mods/v3', 'http://purl.stanford.edu/cg357zz0321.mods']
|
10
|
+
)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#document' do
|
15
|
+
before do
|
16
|
+
allow(Faraday).to receive(:new).with(url: 'http://purl.stanford.edu/cg357zz0321.mods').and_return(connection)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with valid XML data at an endpoint URL' do
|
20
|
+
before do
|
21
|
+
allow(response).to receive(:status).and_return(200)
|
22
|
+
allow(response).to receive(:body).and_return('<test>data</test>')
|
23
|
+
allow(connection).to receive(:get).and_return(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns an XML Document containing the payload from an endpoint url' do
|
27
|
+
expect(opengeometadata.document).to be_a Nokogiri::XML::Document
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when attempts to connect to an endpoint URL fail' do
|
32
|
+
subject { opengeometadata.document }
|
33
|
+
|
34
|
+
before do
|
35
|
+
allow(connection).to receive(:get).and_raise(Faraday::Error::ConnectionFailed, 'test connection failures')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns nil when a connection error' do
|
39
|
+
expect(subject).to be_a Nokogiri::XML::Document
|
40
|
+
expect(subject.children.empty?).to be true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#blank?' do
|
46
|
+
before do
|
47
|
+
allow(Faraday).to receive(:new).with(url: 'http://purl.stanford.edu/cg357zz0321.mods').and_return(connection)
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with valid XML data at an endpoint URL' do
|
51
|
+
before do
|
52
|
+
allow(response).to receive(:status).and_return(200)
|
53
|
+
allow(response).to receive(:body).and_return('<test>data</test>')
|
54
|
+
allow(connection).to receive(:get).and_return(response)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns false' do
|
58
|
+
expect(opengeometadata.blank?).to be false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when attempts to connect to an endpoint URL fail' do
|
63
|
+
before do
|
64
|
+
allow(connection).to receive(:get).and_raise(Faraday::Error::ConnectionFailed, 'test connection failures')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns true' do
|
68
|
+
expect(opengeometadata.blank?).to be true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#endpoint' do
|
74
|
+
before do
|
75
|
+
allow(Faraday).to receive(:new).with(url: 'http://purl.stanford.edu/cg357zz0321.mods').and_return(connection)
|
76
|
+
allow(response).to receive(:status).and_return(200)
|
77
|
+
allow(response).to receive(:body).and_return('<test>data</test>')
|
78
|
+
allow(connection).to receive(:get).and_return(response)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns the URI' do
|
82
|
+
expect(opengeometadata.endpoint).to eq 'http://purl.stanford.edu/cg357zz0321.mods'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,25 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Geoblacklight::Metadata do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
describe '.instance' do
|
5
|
+
let(:reference) { instance_double(Geoblacklight::Reference) }
|
6
|
+
context 'with an FGDC metadata reference' do
|
7
|
+
before do
|
8
|
+
allow(reference).to receive(:type).and_return('fgdc')
|
9
|
+
end
|
10
|
+
it 'constructs an Geoblacklight::Metadata::Fgdc instance' do
|
11
|
+
expect(described_class.instance(reference)).to be_a Geoblacklight::Metadata::Fgdc
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with an ISO19139 metadata reference' do
|
16
|
+
before do
|
17
|
+
allow(reference).to receive(:type).and_return('iso19139')
|
18
|
+
end
|
19
|
+
it 'constructs an Geoblacklight::Metadata::Iso19139 instance' do
|
20
|
+
expect(described_class.instance(reference)).to be_a Geoblacklight::Metadata::Iso19139
|
21
|
+
end
|
18
22
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
|
24
|
+
context 'with another metadata reference' do
|
25
|
+
before do
|
26
|
+
allow(reference).to receive(:type).and_return('unsupported')
|
27
|
+
end
|
28
|
+
it 'constructs an Geoblacklight::Metadata::Base instance' do
|
29
|
+
expect(described_class.instance(reference)).to be_a Geoblacklight::Metadata::Base
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Geoblacklight::MetadataTransformer::Base do
|
4
|
+
describe '.new' do
|
5
|
+
it 'raises an error for empty XML' do
|
6
|
+
expect { described_class.new(nil) }.to raise_error Geoblacklight::MetadataTransformer::EmptyMetadataError
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'with metadata types without XSL Stylesheets' do
|
11
|
+
let(:metadata) { instance_double(GeoCombine::Metadata) }
|
12
|
+
subject { described_class.new(metadata) }
|
13
|
+
describe '#transform' do
|
14
|
+
before do
|
15
|
+
allow(metadata).to receive(:to_html).and_raise(NoMethodError, 'undefined method `to_html\'')
|
16
|
+
end
|
17
|
+
it 'raises a transform error' do
|
18
|
+
expect { subject.transform }.to raise_error Geoblacklight::MetadataTransformer::TransformError, /undefined method `to_html'/
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with metadata types with XSL Stylesheets but invalid HTML' do
|
24
|
+
let(:metadata) { instance_double(GeoCombine::Metadata) }
|
25
|
+
subject { described_class.new(metadata) }
|
26
|
+
describe '#transform' do
|
27
|
+
before do
|
28
|
+
allow(metadata).to receive(:to_html).and_return('<invalid-html></invalid-html>')
|
29
|
+
end
|
30
|
+
it 'raises a transform error' do
|
31
|
+
expect { subject.transform }.to raise_error Geoblacklight::MetadataTransformer::TransformError, 'Failed to extract the <body> child elements from the transformed metadata'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Geoblacklight::MetadataTransformer::Fgdc do
|
4
|
+
let(:fgdc_html) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'metadata', 'fgdc.html')) }
|
5
|
+
let(:metadata) { instance_double('Geoblacklight::Metadata::Fgdc') }
|
6
|
+
subject do
|
7
|
+
described_class.new(metadata)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#transform' do
|
11
|
+
before do
|
12
|
+
allow(metadata).to receive(:blank?).and_return(false)
|
13
|
+
allow(metadata).to receive(:to_html).and_return(fgdc_html)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'transforms FGDC Documents in the XML into the HTML' do
|
17
|
+
transformed = Nokogiri::XML.fragment(subject.transform)
|
18
|
+
expect(transformed.at_xpath('.//h1').text.strip).to eq('Custom Link Sample')
|
19
|
+
expect(transformed.at_xpath('.//div/dl/dd/dl/dd/dl/dt').text).to eq('Originator')
|
20
|
+
expect(transformed.at_xpath('.//div/dl/dd/dl/dd/dl/dd').text.strip).to eq('Esri')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Geoblacklight::MetadataTransformer::Iso19139 do
|
4
|
+
let(:iso_html) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'metadata', 'iso.html')) }
|
5
|
+
let(:metadata) { instance_double('Geoblacklight::Metadata::Iso19139') }
|
6
|
+
subject do
|
7
|
+
described_class.new(metadata)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#transform' do
|
11
|
+
before do
|
12
|
+
expect(metadata).to receive(:blank?).and_return(false)
|
13
|
+
expect(metadata).to receive(:to_html).and_return(iso_html)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'transforms ISO19139 Documents in the XML into the HTML' do
|
17
|
+
transformed = Nokogiri::XML.fragment(subject.transform)
|
18
|
+
expect(transformed.at_xpath('.//h1').text.strip).to eq('Abandoned Mine Land Inventory Polygons: Pennsylvania, 2016')
|
19
|
+
expect(transformed.at_xpath('(.//div)[1]/dl/dd/dl/dd/dl/dt').text).to eq('Title')
|
20
|
+
expect(transformed.at_xpath('(.//div)[1]/dl/dd/dl/dd/dl/dd').text.strip).to eq('Abandoned Mine Land Inventory Polygons: Pennsylvania, 2016')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|