geoblacklight 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rubocop.yml +45 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +27 -6
- data/README.md +2 -9
- data/Rakefile +20 -11
- data/app/assets/javascripts/geoblacklight/basemaps.js +6 -3
- data/app/assets/javascripts/geoblacklight/modules/layer_opacity.js +13 -5
- data/app/assets/javascripts/geoblacklight/viewers/map.js +7 -0
- data/app/assets/javascripts/geoblacklight/viewers/wms.js +2 -5
- data/app/assets/stylesheets/geoblacklight/modules/item.scss +1 -1
- data/app/controllers/download_controller.rb +18 -14
- data/app/controllers/wms_controller.rb +1 -1
- data/app/helpers/geoblacklight_helper.rb +17 -11
- data/{lib → app/models/concerns}/geoblacklight/solr_document.rb +13 -8
- data/{lib → app/models/concerns}/geoblacklight/solr_document/carto_db.rb +0 -0
- data/{lib → app/models/concerns}/geoblacklight/solr_document/finder.rb +1 -2
- data/app/models/concerns/geoblacklight/solr_document/inspection.rb +15 -0
- data/{lib → app/presenters}/geoblacklight/document_presenter.rb +0 -0
- data/app/views/catalog/_show_default_viewer_container.html.erb +1 -1
- data/config/initializers/rails_config.rb +2 -2
- data/geoblacklight.gemspec +3 -4
- data/lib/generators/geoblacklight/install_generator.rb +17 -16
- data/lib/generators/geoblacklight/templates/catalog_controller.rb +1 -5
- data/lib/generators/geoblacklight/templates/geoblacklight.css.scss +0 -1
- data/lib/generators/geoblacklight/templates/geoblacklight.js +0 -1
- data/lib/geoblacklight.rb +1 -6
- data/lib/geoblacklight/bounding_box.rb +2 -1
- data/lib/geoblacklight/catalog_helper_override.rb +0 -1
- data/lib/geoblacklight/download.rb +12 -7
- data/lib/geoblacklight/download/hgl_download.rb +2 -3
- data/lib/geoblacklight/download/kmz_download.rb +9 -3
- data/lib/geoblacklight/download/shapefile_download.rb +5 -1
- data/lib/geoblacklight/engine.rb +1 -3
- data/lib/geoblacklight/exceptions.rb +1 -1
- data/lib/geoblacklight/metadata.rb +0 -1
- data/lib/geoblacklight/references.rb +3 -4
- data/lib/geoblacklight/routes.rb +5 -3
- data/lib/geoblacklight/search_builder.rb +3 -2
- data/lib/geoblacklight/version.rb +1 -1
- data/lib/geoblacklight/view_helper_override.rb +9 -10
- data/lib/geoblacklight/wms_layer.rb +12 -15
- data/lib/geoblacklight/wms_layer/feature_info_response.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +1 -1
- data/spec/controllers/download_controller_spec.rb +7 -7
- data/spec/features/home_page_spec.rb +1 -1
- data/spec/features/layer_opacity_spec.rb +9 -0
- data/spec/features/metadata_panel_spec.rb +6 -4
- data/spec/features/saved_searches_spec.rb +1 -1
- data/spec/features/split_view.html.erb_spec.rb +3 -3
- data/spec/helpers/geoblacklight_helpers_spec.rb +3 -4
- data/spec/lib/geoblacklight/bounding_box_spec.rb +7 -7
- data/spec/lib/geoblacklight/controller_override_spec.rb +1 -1
- data/spec/lib/geoblacklight/document_presenter_spec.rb +1 -1
- data/spec/lib/geoblacklight/download/geojson_download_spec.rb +5 -5
- data/spec/lib/geoblacklight/download/geotiff_download_spec.rb +5 -5
- data/spec/lib/geoblacklight/download/hgl_download_spec.rb +6 -6
- data/spec/lib/geoblacklight/download/kmz_download_spec.rb +5 -5
- data/spec/lib/geoblacklight/download/shapefile_download_spec.rb +5 -5
- data/spec/lib/geoblacklight/download_spec.rb +14 -14
- data/spec/lib/geoblacklight/geoblacklight_helper_behavior_spec.rb +2 -1
- data/spec/lib/geoblacklight/item_viewer_spec.rb +5 -5
- data/spec/lib/geoblacklight/metadata_spec.rb +3 -3
- data/spec/lib/geoblacklight/reference_spec.rb +3 -3
- data/spec/lib/geoblacklight/references_spec.rb +34 -34
- data/spec/lib/geoblacklight/search_builder_spec.rb +7 -15
- data/spec/lib/geoblacklight/view_helper_override_spec.rb +15 -15
- data/spec/lib/geoblacklight/wms_layer/feature_info_response_spec.rb +10 -10
- data/spec/lib/geoblacklight/wms_layer_spec.rb +7 -7
- data/spec/{lib → models/concerns}/geoblacklight/solr_document/carto_db_spec.rb +0 -0
- data/spec/{lib → models/concerns}/geoblacklight/solr_document/finder_spec.rb +2 -2
- data/spec/models/concerns/geoblacklight/solr_document/inspection_spec.rb +16 -0
- data/spec/{lib → models/concerns}/geoblacklight/solr_document_spec.rb +24 -24
- data/spec/spec_helper.rb +6 -7
- data/spec/support/features.rb +1 -1
- data/spec/support/features/session_helpers.rb +1 -1
- data/spec/teaspoon_env.rb +38 -33
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +4 -4
- data/spec/views/catalog/_document_split.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_index_split.html.erb_spec.rb +1 -1
- metadata +31 -33
- data/lib/geoblacklight/config.rb +0 -0
@@ -1,10 +1,11 @@
|
|
1
1
|
module Geoblacklight
|
2
|
-
class SearchBuilder
|
2
|
+
class SearchBuilder < Blacklight::Solr::SearchBuilder
|
3
3
|
self.default_processor_chain += [:add_spatial_params]
|
4
4
|
|
5
5
|
def initialize(processor_chain, scope)
|
6
6
|
super(processor_chain, scope)
|
7
|
-
@processor_chain += [:add_spatial_params] unless @processor_chain
|
7
|
+
@processor_chain += [:add_spatial_params] unless @processor_chain
|
8
|
+
.include?(:add_spatial_params)
|
8
9
|
end
|
9
10
|
|
10
11
|
##
|
@@ -11,8 +11,8 @@ module Geoblacklight
|
|
11
11
|
spatial_parameters? || super
|
12
12
|
end
|
13
13
|
|
14
|
-
def query_has_constraints?(
|
15
|
-
has_search_parameters? || super
|
14
|
+
def query_has_constraints?(localized_params = params)
|
15
|
+
has_search_parameters? || super(localized_params)
|
16
16
|
end
|
17
17
|
|
18
18
|
def render_search_to_s(params)
|
@@ -21,19 +21,18 @@ 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('Bounding box', render_filter_value(params['bbox'])
|
24
|
+
render_search_to_s_element('Bounding box', render_filter_value(params['bbox']))
|
25
25
|
end
|
26
26
|
|
27
|
-
def render_constraints_filters(
|
28
|
-
content = super(
|
27
|
+
def render_constraints_filters(localized_params = params)
|
28
|
+
content = super(localized_params)
|
29
29
|
|
30
|
-
if
|
31
|
-
|
32
|
-
|
33
|
-
remove: search_action_path(remove_spatial_filter_group(:bbox, params)))
|
30
|
+
if localized_params[:bbox]
|
31
|
+
path = search_action_path(remove_spatial_filter_group(:bbox, localized_params))
|
32
|
+
content << render_constraint_element('Bounding Box', localized_params[:bbox], remove: path)
|
34
33
|
end
|
35
34
|
|
36
|
-
|
35
|
+
content
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Geoblacklight
|
2
2
|
class WmsLayer
|
3
|
-
|
4
3
|
def initialize(params)
|
5
4
|
@params = params.merge(Settings.WMS_PARAMS)
|
6
5
|
@response = Geoblacklight::FeatureInfoResponse.new(request_response)
|
@@ -14,25 +13,23 @@ module Geoblacklight
|
|
14
13
|
@params.except('URL')
|
15
14
|
end
|
16
15
|
|
17
|
-
def
|
16
|
+
def feature_info
|
18
17
|
@response.check
|
19
18
|
end
|
20
19
|
|
21
20
|
def request_response
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
request.options.open_timeout = Settings.TIMEOUT_WMS
|
28
|
-
end
|
29
|
-
rescue Faraday::Error::ConnectionFailed => error
|
30
|
-
Geoblacklight.logger.error error.inspect
|
31
|
-
{ error: error.inspect }
|
32
|
-
rescue Faraday::Error::TimeoutError => error
|
33
|
-
Geoblacklight.logger.error error.inspect
|
34
|
-
{ error: error.inspect }
|
21
|
+
conn = Faraday.new(url: url)
|
22
|
+
conn.get do |request|
|
23
|
+
request.params = search_params
|
24
|
+
request.options.timeout = Settings.TIMEOUT_WMS
|
25
|
+
request.options.open_timeout = Settings.TIMEOUT_WMS
|
35
26
|
end
|
27
|
+
rescue Faraday::Error::ConnectionFailed => error
|
28
|
+
Geoblacklight.logger.error error.inspect
|
29
|
+
{ error: error.inspect }
|
30
|
+
rescue Faraday::Error::TimeoutError => error
|
31
|
+
Geoblacklight.logger.error error.inspect
|
32
|
+
{ error: error.inspect }
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe CatalogController, type: :controller do
|
4
4
|
describe '#web_services' do
|
5
|
-
it '
|
5
|
+
it 'returns a document based off an id' do
|
6
6
|
get :web_services, id: 'mit-us-ma-e25zcta5dct-2000'
|
7
7
|
expect(response.status).to eq 200
|
8
8
|
expect(assigns(:document)).to_not be_nil
|
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe Geoblacklight::DownloadController, type: :controller do
|
4
4
|
describe '#file' do
|
5
5
|
describe 'restricted file' do
|
6
|
-
it '
|
6
|
+
it 'redirects to login for authentication' do
|
7
7
|
get :file, id: 'stanford-cg357zz0321-shapefile', format: 'zip'
|
8
8
|
expect(response.status).to eq 401
|
9
9
|
end
|
10
10
|
end
|
11
11
|
describe 'public file' do
|
12
|
-
it '
|
12
|
+
it 'initiates download' do
|
13
13
|
expect(controller).to receive(:render)
|
14
14
|
expect(controller).to receive(:send_file)
|
15
15
|
get :file, id: 'mit-us-ma-e25zcta5dct-2000-shapefile', format: 'zip'
|
@@ -19,27 +19,27 @@ describe Geoblacklight::DownloadController, type: :controller do
|
|
19
19
|
end
|
20
20
|
describe '#show' do
|
21
21
|
describe 'restricted file' do
|
22
|
-
it '
|
22
|
+
it 'redirects to login for authentication' do
|
23
23
|
get 'show', id: 'stanford-cg357zz0321', format: 'json'
|
24
24
|
expect(response.status).to eq 401
|
25
25
|
end
|
26
26
|
end
|
27
27
|
describe 'public file' do
|
28
|
-
it '
|
28
|
+
it 'initiates download creation' do
|
29
29
|
get 'show', id: 'mit-us-ma-e25zcta5dct-2000', type: 'shapefile'
|
30
30
|
expect(response.status).to eq 200
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
describe '#hgl' do
|
35
|
-
it '
|
35
|
+
it 'requests file' do
|
36
36
|
expect_any_instance_of(Geoblacklight::HglDownload).to receive(:get).and_return('success')
|
37
37
|
get :hgl, id: 'harvard-g7064-s2-1834-k3', email: 'foo@example.com'
|
38
38
|
expect(response.status).to eq 200
|
39
39
|
end
|
40
|
-
it '
|
40
|
+
it 'renders form' do
|
41
41
|
get :hgl, id: 'harvard-g7064-s2-1834-k3'
|
42
42
|
expect(response).to render_template('hgl')
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
@@ -29,7 +29,7 @@ feature 'Home page', js: true do # use js: true for tests which require js, but
|
|
29
29
|
scenario 'clicking map search should create a spatial search' do
|
30
30
|
within '#map' do
|
31
31
|
find('.search-control a').click
|
32
|
-
expect(page.current_url).to match
|
32
|
+
expect(page.current_url).to match(/bbox=/)
|
33
33
|
end
|
34
34
|
expect(page).to have_css '#documents'
|
35
35
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Layer opacity', js: true do
|
4
|
+
scenario 'WMS layer should have opacity control' do
|
5
|
+
visit catalog_path('mit-us-ma-e25zcta5dct-2000')
|
6
|
+
expect(page).to have_css('div.opacity-text', text: '75%')
|
7
|
+
expect(page.all('div.leaflet-layer')[1][:style]).to match(/opacity: 0.75;/)
|
8
|
+
end
|
9
|
+
end
|
@@ -6,10 +6,12 @@ feature 'Metadata tools' do
|
|
6
6
|
visit catalog_path 'stanford-cg357zz0321'
|
7
7
|
expect(page).to have_css 'li.metadata a', text: 'Metadata'
|
8
8
|
click_link 'Metadata'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
using_wait_time 15 do
|
10
|
+
within '.metadata-view' do
|
11
|
+
expect(page).to have_css 'div.label', text: 'MODS'
|
12
|
+
expect(page).to have_css 'div.CodeRay', count: 2
|
13
|
+
expect(page).to have_css 'div.label', text: 'ISO 19139'
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -5,7 +5,7 @@ feature 'saved searches' do
|
|
5
5
|
visit root_path
|
6
6
|
within '#map' do
|
7
7
|
find('.search-control a').click
|
8
|
-
expect(page.current_url).to match
|
8
|
+
expect(page.current_url).to match(/bbox=/)
|
9
9
|
end
|
10
10
|
visit search_history_path
|
11
11
|
expect(page).to have_css 'td.query a', text: /Bounding box:/
|
@@ -6,9 +6,9 @@ feature 'Index view', js: true do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
scenario 'should have documents and map on page' do
|
9
|
-
visit catalog_index_path(f: { dct_provenance_s: ['Stanford']})
|
9
|
+
visit catalog_index_path(f: { dct_provenance_s: ['Stanford'] })
|
10
10
|
expect(page).to have_css('#documents')
|
11
|
-
expect(page).to have_css(
|
11
|
+
expect(page).to have_css('.document', count: 3)
|
12
12
|
expect(page).to have_css('#map')
|
13
13
|
end
|
14
14
|
|
@@ -31,7 +31,7 @@ feature 'Index view', js: true do
|
|
31
31
|
|
32
32
|
scenario 'hover on record should produce bounding box on map' do
|
33
33
|
# Needed to find an svg element on the page
|
34
|
-
visit catalog_index_path(f: { dct_provenance_s: ['Stanford']})
|
34
|
+
visit catalog_index_path(f: { dct_provenance_s: ['Stanford'] })
|
35
35
|
expect(Nokogiri::HTML.parse(page.body).css('path').length).to eq 0
|
36
36
|
find('.documentHeader', match: :first).trigger(:mouseover)
|
37
37
|
expect(Nokogiri::HTML.parse(page.body).css('path').length).to eq 1
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GeoblacklightHelper, type: :helper do
|
4
|
-
include GeoblacklightHelper
|
5
4
|
include ActionView::Helpers::UrlHelper
|
6
5
|
include ActionView::Helpers::TranslationHelper
|
7
6
|
describe '#render_facet_links' do
|
8
|
-
it '
|
9
|
-
expect(self).to receive(:catalog_index_path).exactly(3).times.and_return(
|
10
|
-
html = Capybara.string(render_facet_links('dc_subject_sm',
|
7
|
+
it 'contains unique links' do
|
8
|
+
expect(self).to receive(:catalog_index_path).exactly(3).times.and_return('http://example.com/catalog?f[dc_subject_sm][]=category')
|
9
|
+
html = Capybara.string(render_facet_links('dc_subject_sm', %w(Test Test Earth Science)))
|
11
10
|
expect(html).to have_css 'a', count: 3
|
12
11
|
expect(html).to have_css 'a', text: 'Test', count: 1
|
13
12
|
expect(html).to have_css 'a', text: 'Earth', count: 1
|
@@ -3,25 +3,25 @@ require 'spec_helper'
|
|
3
3
|
describe Geoblacklight::BoundingBox do
|
4
4
|
describe '#initialize' do
|
5
5
|
it 'handles multiple input types as arguments' do
|
6
|
-
expect(
|
7
|
-
expect(
|
8
|
-
expect(
|
6
|
+
expect(described_class.new('1', '1', '1', '1')).to be_an described_class
|
7
|
+
expect(described_class.new(1, 2, 3, 3)).to be_an described_class
|
8
|
+
expect(described_class.new(1.1, 2.1, 3.1, 3.1)).to be_an described_class
|
9
9
|
end
|
10
10
|
end
|
11
11
|
describe '#to_envelope' do
|
12
|
-
let(:example_box) {
|
12
|
+
let(:example_box) { described_class.new(-160, -80, 120, 70) }
|
13
13
|
it 'creates an envelope syntax version of the bounding box' do
|
14
14
|
expect(example_box.to_envelope).to eq 'ENVELOPE(-160, 120, 70, -80)'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
describe '#from_rectangle' do
|
18
|
-
let(:example_box) {
|
18
|
+
let(:example_box) { described_class.from_rectangle('-160 -80 120 70') }
|
19
19
|
it 'parses and creates a Geoblacklight::BoundingBox from a Solr lat-lon' do
|
20
|
-
expect(example_box).to be_an
|
20
|
+
expect(example_box).to be_an described_class
|
21
21
|
expect(example_box.to_envelope).to eq 'ENVELOPE(-160, 120, 70, -80)'
|
22
22
|
end
|
23
23
|
it 'checks for valididity' do
|
24
|
-
expect {
|
24
|
+
expect { described_class.from_rectangle('-160 -80 120') }.to raise_error Geoblacklight::Exceptions::WrongBoundingBoxFormat
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1 +1 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require 'spec_helper'
|
@@ -5,7 +5,7 @@ describe Geoblacklight::DocumentPresenter do
|
|
5
5
|
let(:config) { Blacklight::Configuration.new }
|
6
6
|
subject { presenter }
|
7
7
|
let(:presenter) do
|
8
|
-
|
8
|
+
described_class.new(document, request_context, config)
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:document) do
|
@@ -2,16 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Geoblacklight::GeojsonDownload do
|
4
4
|
let(:document) { SolrDocument.new(layer_slug_s: 'test', solr_wfs_url: 'http://www.example.com/wfs', layer_id_s: 'stanford-test', solr_geom: 'ENVELOPE(-180, 180, 90, -90)') }
|
5
|
-
let(:download) {
|
5
|
+
let(:download) { described_class.new(document) }
|
6
6
|
describe '#initialize' do
|
7
|
-
it '
|
8
|
-
expect(download).to be_an
|
7
|
+
it 'initializes as a GeojsonDownload object with specific options' do
|
8
|
+
expect(download).to be_an described_class
|
9
9
|
options = download.instance_variable_get(:@options)
|
10
10
|
expect(options[:content_type]).to eq 'application/json'
|
11
11
|
expect(options[:request_params][:typeName]).to eq 'stanford-test'
|
12
12
|
end
|
13
|
-
it '
|
14
|
-
download =
|
13
|
+
it 'merges custom options' do
|
14
|
+
download = described_class.new(document, timeout: 33)
|
15
15
|
options = download.instance_variable_get(:@options)
|
16
16
|
expect(options[:timeout]).to eq 33
|
17
17
|
end
|
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Geoblacklight::GeotiffDownload do
|
4
4
|
let(:document) { SolrDocument.new(layer_slug_s: 'test', layer_id_s: 'stanford-test', solr_geom: 'ENVELOPE(-180, 180, 90, -90)') }
|
5
|
-
let(:download) {
|
5
|
+
let(:download) { described_class.new(document) }
|
6
6
|
describe '#initialize' do
|
7
|
-
it '
|
8
|
-
expect(download).to be_an
|
7
|
+
it 'initializes as a GeotiffDownload object with specific options' do
|
8
|
+
expect(download).to be_an described_class
|
9
9
|
options = download.instance_variable_get(:@options)
|
10
10
|
expect(options[:content_type]).to eq 'image/geotiff'
|
11
11
|
expect(options[:request_params][:layers]).to eq 'stanford-test'
|
12
12
|
expect(options[:reflect]).to be_truthy
|
13
13
|
end
|
14
|
-
it '
|
15
|
-
download =
|
14
|
+
it 'merges custom options' do
|
15
|
+
download = described_class.new(document, timeout: 33)
|
16
16
|
options = download.instance_variable_get(:@options)
|
17
17
|
expect(options[:timeout]).to eq 33
|
18
18
|
end
|
@@ -2,18 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Geoblacklight::HglDownload do
|
4
4
|
let(:document) { SolrDocument.new(layer_slug_s: 'test', layer_id_s: 'cite:harvard-test') }
|
5
|
-
let(:download) {
|
5
|
+
let(:download) { described_class.new(document, 'foo@example.com') }
|
6
6
|
describe '#initialize' do
|
7
|
-
it '
|
8
|
-
expect(download).to be_an
|
7
|
+
it 'initializes as an HglDownload object with specific options' do
|
8
|
+
expect(download).to be_an described_class
|
9
9
|
options = download.instance_variable_get(:@options)
|
10
10
|
expect(options[:request_params]['LayerName']).to eq 'harvard-test'
|
11
11
|
expect(options[:request_params]['UserEmail']).to eq 'foo@example.com'
|
12
12
|
end
|
13
|
-
it '
|
14
|
-
download =
|
13
|
+
it 'merges custom options' do
|
14
|
+
download = described_class.new(document, 'foo@example.com', timeout: 33)
|
15
15
|
options = download.instance_variable_get(:@options)
|
16
16
|
expect(options[:timeout]).to eq 33
|
17
17
|
end
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Geoblacklight::KmzDownload do
|
4
4
|
let(:document) { SolrDocument.new(layer_slug_s: 'test', solr_wfs_url: 'http://www.example.com/wfs', layer_id_s: 'stanford-test', solr_geom: 'ENVELOPE(-180, 180, 90, -90)') }
|
5
|
-
let(:download) {
|
5
|
+
let(:download) { described_class.new(document) }
|
6
6
|
describe '#initialize' do
|
7
|
-
it '
|
8
|
-
expect(download).to be_an
|
7
|
+
it 'initializes as a KmzDownload object with specific options' do
|
8
|
+
expect(download).to be_an described_class
|
9
9
|
options = download.instance_variable_get(:@options)
|
10
10
|
expect(options[:content_type]).to eq 'application/vnd.google-earth.kmz'
|
11
11
|
expect(options[:request_params][:layers]).to eq 'stanford-test'
|
12
12
|
expect(options[:request_params][:bbox]).to eq '-180, -90, 180, 90'
|
13
13
|
end
|
14
|
-
it '
|
15
|
-
download =
|
14
|
+
it 'merges custom options' do
|
15
|
+
download = described_class.new(document, timeout: 33)
|
16
16
|
options = download.instance_variable_get(:@options)
|
17
17
|
expect(options[:timeout]).to eq 33
|
18
18
|
end
|
@@ -2,16 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Geoblacklight::ShapefileDownload do
|
4
4
|
let(:document) { SolrDocument.new(layer_slug_s: 'test', solr_wfs_url: 'http://www.example.com/wfs', layer_id_s: 'stanford-test', solr_geom: 'ENVELOPE(-180, 180, 90, -90)') }
|
5
|
-
let(:download) {
|
5
|
+
let(:download) { described_class.new(document) }
|
6
6
|
describe '#initialize' do
|
7
|
-
it '
|
8
|
-
expect(download).to be_an
|
7
|
+
it 'initializes as a ShapefileDownload object with specific options' do
|
8
|
+
expect(download).to be_an described_class
|
9
9
|
options = download.instance_variable_get(:@options)
|
10
10
|
expect(options[:content_type]).to eq 'application/zip'
|
11
11
|
expect(options[:request_params][:typeName]).to eq 'stanford-test'
|
12
12
|
end
|
13
|
-
it '
|
14
|
-
download =
|
13
|
+
it 'merges custom options' do
|
14
|
+
download = described_class.new(document, timeout: 33)
|
15
15
|
options = download.instance_variable_get(:@options)
|
16
16
|
expect(options[:timeout]).to eq 33
|
17
17
|
end
|
@@ -4,45 +4,45 @@ describe Geoblacklight::Download do
|
|
4
4
|
let(:response) { double('response') }
|
5
5
|
let(:get) { double('get') }
|
6
6
|
let(:body) { double('body') }
|
7
|
-
let(:document) { SolrDocument.new(layer_slug_s: 'test', dct_references_s: {'http://www.opengis.net/def/serviceType/ogc/wms' => 'http://www.example.com/wms'}.to_json) }
|
7
|
+
let(:document) { SolrDocument.new(layer_slug_s: 'test', dct_references_s: { 'http://www.opengis.net/def/serviceType/ogc/wms' => 'http://www.example.com/wms' }.to_json) }
|
8
8
|
let(:options) { { type: 'shapefile', extension: 'zip', service_type: 'wms', content_type: 'application/zip' } }
|
9
9
|
let(:download) { Geoblacklight::ShapefileDownload.new(document, options) }
|
10
10
|
|
11
11
|
describe '#initialize' do
|
12
|
-
it '
|
13
|
-
expect(download).to be_an
|
12
|
+
it 'initializes as a Download object' do
|
13
|
+
expect(download).to be_an described_class
|
14
14
|
end
|
15
15
|
end
|
16
16
|
describe '#file_name' do
|
17
|
-
it '
|
17
|
+
it 'gives the file name with path and extension' do
|
18
18
|
expect(download.file_name).to eq 'test-shapefile.zip'
|
19
19
|
end
|
20
20
|
end
|
21
21
|
describe '#file_path' do
|
22
|
-
it '
|
22
|
+
it 'returns the path with name and extension' do
|
23
23
|
expect(download.class.file_path).to eq "#{Rails.root}/tmp/cache/downloads"
|
24
24
|
end
|
25
|
-
it '
|
25
|
+
it 'is configurable' do
|
26
26
|
expect(Settings).to receive(:DOWNLOAD_PATH).and_return('configured/path')
|
27
27
|
expect(download.class.file_path).to eq 'configured/path'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
describe '#download_exists?' do
|
31
|
-
it '
|
31
|
+
it 'returns false if file does not exist' do
|
32
32
|
expect(File).to receive(:file?).and_return(false)
|
33
33
|
expect(download.download_exists?).to be_falsey
|
34
34
|
end
|
35
|
-
it '
|
35
|
+
it 'returns true if file does not exist' do
|
36
36
|
expect(File).to receive(:file?).and_return(true)
|
37
37
|
expect(download.download_exists?).to be_truthy
|
38
38
|
end
|
39
39
|
end
|
40
40
|
describe '#get' do
|
41
|
-
it '
|
41
|
+
it 'returns filename if download exists' do
|
42
42
|
expect(download).to receive(:download_exists?).and_return(true)
|
43
43
|
expect(download.get).to eq download.file_name
|
44
44
|
end
|
45
|
-
it '
|
45
|
+
it 'calls create_download_file if it does not exist' do
|
46
46
|
expect(download).to receive(:download_exists?).and_return(false)
|
47
47
|
expect(download).to receive(:initiate_download).and_return(object: 'file')
|
48
48
|
expect(File).to receive(:open).with("#{download.file_path_and_name}.tmp", 'wb').and_return('')
|
@@ -51,14 +51,14 @@ describe Geoblacklight::Download do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
describe '#create_download_file' do
|
54
|
-
it '
|
54
|
+
it 'creates the file in fs and delete it if the content headers are not correct' do
|
55
55
|
bad_file = OpenStruct.new(headers: { 'content-type' => 'bad/file' })
|
56
56
|
expect(download).to receive(:initiate_download).and_return(bad_file)
|
57
57
|
expect(File).to receive(:delete).with("#{download.file_path_and_name}.tmp").and_return(nil)
|
58
58
|
expect { download.create_download_file }.to raise_error(Geoblacklight::Exceptions::ExternalDownloadFailed, 'Wrong download type')
|
59
59
|
end
|
60
|
-
it '
|
61
|
-
shapefile = OpenStruct.new(headers: {'content-type' => 'application/zip'})
|
60
|
+
it 'creates the file, write it, and then rename from tmp if everything is ok' do
|
61
|
+
shapefile = OpenStruct.new(headers: { 'content-type' => 'application/zip' })
|
62
62
|
expect(download).to receive(:initiate_download).and_return(shapefile)
|
63
63
|
expect(File).to receive(:open).with("#{download.file_path_and_name}.tmp", 'wb').and_return('')
|
64
64
|
expect(File).to receive(:rename)
|
@@ -71,7 +71,7 @@ describe Geoblacklight::Download do
|
|
71
71
|
expect(Faraday).to receive(:new).with(url: 'http://www.example.com/wms').and_return(response)
|
72
72
|
download.initiate_download
|
73
73
|
end
|
74
|
-
it '
|
74
|
+
it 'raises Geoblacklight::Exceptions::ExternalDownloadFailed with a connection failure' do
|
75
75
|
expect(response).to receive(:url_prefix).and_return 'http://www.example.com/wms'
|
76
76
|
expect(response).to receive(:get).and_raise(Faraday::Error::ConnectionFailed.new('Failed'))
|
77
77
|
expect(Faraday).to receive(:new).with(url: 'http://www.example.com/wms').and_return(response)
|