geoblacklight 6.0.0.pre.alpha.4 → 6.0.0.pre.alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +0 -1
- data/app/assets/stylesheets/geoblacklight/record.css +37 -1
- data/app/components/geoblacklight/document/download_link_component.html.erb +6 -0
- data/app/components/geoblacklight/document/download_link_component.rb +66 -0
- data/app/components/geoblacklight/document/download_links_component.html.erb +8 -0
- data/app/components/geoblacklight/document/download_links_component.rb +59 -0
- data/app/components/geoblacklight/document/sidebar_component.html.erb +3 -9
- data/app/components/geoblacklight/document/sidebar_component.rb +6 -11
- data/app/components/geoblacklight/login_link_component.html.erb +3 -5
- data/app/javascript/geoblacklight/core.js +0 -2
- data/app/javascript/geoblacklight/index.js +0 -2
- data/app/javascript/geoblacklight/leaflet/inspection.js +5 -4
- data/app/models/concerns/geoblacklight/solr_document.rb +1 -2
- data/config/locales/geoblacklight.en.yml +5 -14
- data/lib/generators/geoblacklight/install_generator.rb +4 -9
- data/lib/generators/geoblacklight/templates/settings.yml +1 -15
- data/lib/geoblacklight/configuration/settings_builder.rb +0 -3
- data/lib/geoblacklight/configuration.rb +0 -10
- data/lib/geoblacklight/exceptions.rb +0 -23
- data/lib/geoblacklight/references.rb +0 -80
- data/lib/geoblacklight/version.rb +1 -1
- data/lib/geoblacklight.rb +0 -1
- data/lib/tasks/geoblacklight.rake +0 -30
- data/spec/components/geoblacklight/document/sidebar_component_spec.rb +1 -1
- data/spec/components/geoblacklight/download_links_component_spec.rb +59 -85
- data/spec/features/index_view_spec.rb +0 -33
- data/spec/features/layer_inspection_spec.rb +0 -10
- data/spec/features/layer_opacity_spec.rb +0 -7
- data/spec/lib/geoblacklight/configuration/settings_builder_spec.rb +0 -2
- data/spec/lib/geoblacklight/references_spec.rb +1 -57
- data/spec/models/concerns/geoblacklight/solr_document_spec.rb +0 -7
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/template.rb +1 -1
- metadata +6 -28
- data/app/components/geoblacklight/download_links_component.html.erb +0 -31
- data/app/components/geoblacklight/download_links_component.rb +0 -87
- data/app/controllers/download_controller.rb +0 -76
- data/app/javascript/geoblacklight/controllers/downloads_controller.js +0 -64
- data/lib/geoblacklight/download/csv_download.rb +0 -22
- data/lib/geoblacklight/download/geojson_download.rb +0 -24
- data/lib/geoblacklight/download/geotiff_download.rb +0 -22
- data/lib/geoblacklight/download/kmz_download.rb +0 -24
- data/lib/geoblacklight/download/shapefile_download.rb +0 -22
- data/lib/geoblacklight/download.rb +0 -110
- data/lib/geoblacklight/routes/downloadable.rb +0 -15
- data/spec/controllers/download_controller_spec.rb +0 -99
- data/spec/features/download_layer_spec.rb +0 -96
- data/spec/features/esri_viewer_spec.rb +0 -43
- data/spec/features/index_map_spec.rb +0 -40
- data/spec/features/layer_with_no_references_spec.rb +0 -10
- data/spec/features/linkified_attribute_table_spec.rb +0 -13
- data/spec/features/multiple_downloads_spec.rb +0 -17
- data/spec/features/show_page_download_spec.rb +0 -22
- data/spec/lib/geoblacklight/download/csv_download_spec.rb +0 -21
- data/spec/lib/geoblacklight/download/geojson_download_spec.rb +0 -22
- data/spec/lib/geoblacklight/download/geotiff_download_spec.rb +0 -25
- data/spec/lib/geoblacklight/download/kmz_download_spec.rb +0 -22
- data/spec/lib/geoblacklight/download/shapefile_download_spec.rb +0 -21
- data/spec/lib/geoblacklight/download_spec.rb +0 -188
- data/spec/tasks/geoblacklight_spec.rb +0 -20
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.feature "feature_layer reference", js: true do
|
|
6
|
-
scenario "displays image map layer" do
|
|
7
|
-
skip "spec depend on potentially flaky external services"
|
|
8
|
-
visit solr_document_path "32653ed6-8d83-4692-8a06-bf13ffe2c018"
|
|
9
|
-
expect(page).to have_css ".leaflet-control-zoom", visible: true
|
|
10
|
-
expect(page).to have_css "img.leaflet-image-layer", visible: true
|
|
11
|
-
end
|
|
12
|
-
scenario "displays dynamic layer (all layers)" do
|
|
13
|
-
skip "spec depend on potentially flaky external services"
|
|
14
|
-
visit solr_document_path "90f14ff4-1359-4beb-b931-5cb41d20ab90"
|
|
15
|
-
expect(page).to have_css ".leaflet-control-zoom", visible: true
|
|
16
|
-
expect(page).to have_css "img.leaflet-image-layer", visible: true
|
|
17
|
-
end
|
|
18
|
-
scenario "displays dynamic layer (single layer)" do
|
|
19
|
-
skip "spec depend on potentially flaky external services"
|
|
20
|
-
visit solr_document_path "4669301e-b4b2-4c8b-bf40-01b968a2865b"
|
|
21
|
-
expect(page).to have_css ".leaflet-control-zoom", visible: true
|
|
22
|
-
expect(page).to have_css "img.leaflet-image-layer", visible: true
|
|
23
|
-
end
|
|
24
|
-
scenario "displays feature layer" do
|
|
25
|
-
pending "cannot currently test for svg feature"
|
|
26
|
-
visit solr_document_path "f406332e63eb4478a9560ad86ae90327_18"
|
|
27
|
-
expect(page).to have_css ".leaflet-control-zoom", visible: true
|
|
28
|
-
expect(Nokogiri::HTML.parse(page.body).css("g").length).to eq 23
|
|
29
|
-
fail
|
|
30
|
-
end
|
|
31
|
-
scenario "displays tiled map layer" do
|
|
32
|
-
skip "spec depend on potentially flaky external services"
|
|
33
|
-
visit solr_document_path "31567cf1-bad8-4bc5-8d57-44b96c207ecc"
|
|
34
|
-
expect(page).to have_css ".leaflet-control-zoom", visible: true
|
|
35
|
-
expect(page).to have_css "img.leaflet-tile.leaflet-tile-loaded", visible: true
|
|
36
|
-
end
|
|
37
|
-
scenario "displays Esri WMS layer" do
|
|
38
|
-
skip "spec depend on potentially flaky external services"
|
|
39
|
-
visit solr_document_path "purdue-urn-f082acb1-b01e-4a08-9126-fd62a23fd9aa"
|
|
40
|
-
expect(page).to have_css ".leaflet-control-zoom", visible: true
|
|
41
|
-
expect(page).to have_css "img.leaflet-tile.leaflet-tile-loaded", visible: true
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.feature "Index map", js: true do
|
|
6
|
-
# Colors
|
|
7
|
-
default_color = "#7FCDBB"
|
|
8
|
-
selected_color = "#2C7FB8"
|
|
9
|
-
scenario "displays index map viewer (polygon)" do
|
|
10
|
-
skip "Doesn't work for importmaps when headless in CI" if ENV["CI"]
|
|
11
|
-
|
|
12
|
-
visit solr_document_path("stanford-fb897vt9938")
|
|
13
|
-
# Wait until SVG elements are added
|
|
14
|
-
expect(page).to have_css ".leaflet-overlay-pane svg"
|
|
15
|
-
within "#leaflet-viewer" do
|
|
16
|
-
expect(page).to have_css "svg g path:nth-child(2)[fill='#{default_color}']"
|
|
17
|
-
# Click the top-left corner of the polygon instead of the center
|
|
18
|
-
# to prevent it being occluded by other DOM elements (occurs in headless mode)
|
|
19
|
-
find("svg g path:nth-child(2)").click(x: 1, y: 1)
|
|
20
|
-
expect(page).to have_css "svg g path:nth-child(2)[fill='#{selected_color}']"
|
|
21
|
-
first("svg g path").click(x: 1, y: 1)
|
|
22
|
-
expect(page).to have_css "svg g path:nth-child(2)[fill='#{default_color}']"
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
scenario "displays index map viewer (points)" do
|
|
27
|
-
skip "Doesn't work for importmaps when headless in CI" if ENV["CI"]
|
|
28
|
-
|
|
29
|
-
visit solr_document_path("cornell-ny-aerial-photos-1960s")
|
|
30
|
-
# Wait until SVG elements are added
|
|
31
|
-
expect(page).to have_css ".leaflet-overlay-pane svg"
|
|
32
|
-
within "#leaflet-viewer" do
|
|
33
|
-
expect(page).to have_css "svg g path:nth-child(2)[fill='#{default_color}']"
|
|
34
|
-
find("svg g path:nth-child(2)").click(x: 1, y: 1)
|
|
35
|
-
expect(page).to have_css "svg g path:nth-child(2)[fill='#{selected_color}']"
|
|
36
|
-
first("svg g path").click(x: 1, y: 1)
|
|
37
|
-
expect(page).to have_css "svg g path:nth-child(2)[fill='#{default_color}']"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.feature "Attribute table values", js: true do
|
|
6
|
-
xscenario "are linkified" do
|
|
7
|
-
# ArcGIS server returning an error. Wait until SVG elements are added
|
|
8
|
-
visit solr_document_path "f406332e63eb4478a9560ad86ae90327_18"
|
|
9
|
-
expect(page).to have_css ".leaflet-overlay-pane svg"
|
|
10
|
-
page.first("svg g path").click
|
|
11
|
-
expect(page).to have_css 'td a[href="http://www.minneapolismn.gov/fire/stations/fire_station28"]', text: "http://www.minneapolismn.gov/fire/stations/fire_station28"
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.feature "Multiple downloads" do
|
|
6
|
-
feature "when item has multiple downloads in dct_references_s" do
|
|
7
|
-
scenario "downloads are listed in download card" do
|
|
8
|
-
visit solr_document_path "cugir-007950"
|
|
9
|
-
find("#downloads-button").click
|
|
10
|
-
within "#downloads-collapse" do
|
|
11
|
-
expect(page).to have_link "Shapefile", href: "https://cugir-data.s3.amazonaws.com/00/79/50/cugir-007950.zip"
|
|
12
|
-
expect(page).to have_link "PDF", href: "https://cugir-data.s3.amazonaws.com/00/79/50/agBROO.pdf"
|
|
13
|
-
expect(page).to have_link "KMZ", href: "https://cugir-data.s3.amazonaws.com/00/79/50/agBROO2011.kmz"
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.feature "Download display on show page" do
|
|
6
|
-
scenario "with download String" do
|
|
7
|
-
visit solr_document_path "2eddde2f-c222-41ca-bd07-2fd74a21f4de"
|
|
8
|
-
find("#downloads-button").click
|
|
9
|
-
within "#downloads-collapse" do
|
|
10
|
-
expect(page).to have_selector(:css, 'a[href="ftp://gdrs.dnr.state.mn.us/gdrs/data/pub/us_mn_state_dnr/fgdb_base_usgs_scanned_topo_100k_drg.zip"]')
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
scenario "with download Array" do
|
|
15
|
-
visit solr_document_path "princeton-sx61dn82p"
|
|
16
|
-
find("#downloads-button").click
|
|
17
|
-
within "#downloads-collapse" do
|
|
18
|
-
expect(page).to have_selector(:css, 'a[href="https://figgy.princeton.edu/downloads/a990e1b4-7f0e-44b8-ae2a-de7e93cdd74a/file/36a2274c-e0c6-4901-a14f-7c422d15e194"]')
|
|
19
|
-
expect(page).to have_selector(:css, 'a[href="https://libimages1.princeton.edu/loris/figgy_prod/2e%2Fa9%2F43%2F2ea943b0bd4348fc9954b299f1b359f6%2Fintermediate_file.jp2/full/full/0/default.jpg"]')
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Geoblacklight::CsvDownload do
|
|
6
|
-
let(:document) { SolrDocument.new(Geoblacklight.configuration.fields.id => "test", :solr_wfs_url => "http://www.example.com/wfs", Geoblacklight.configuration.fields.wxs_identifier => "stanford-test", Geoblacklight.configuration.fields.geometry => "ENVELOPE(-180, 180, 90, -90)") }
|
|
7
|
-
let(:download) { described_class.new(document) }
|
|
8
|
-
describe "#initialize" do
|
|
9
|
-
it "initializes as a CsvDownload object with specific options" do
|
|
10
|
-
expect(download).to be_an described_class
|
|
11
|
-
options = download.instance_variable_get(:@options)
|
|
12
|
-
expect(options[:content_type]).to eq "text/csv"
|
|
13
|
-
expect(options[:request_params][:typeName]).to eq "stanford-test"
|
|
14
|
-
end
|
|
15
|
-
it "merges custom options" do
|
|
16
|
-
download = described_class.new(document, timeout: 33)
|
|
17
|
-
options = download.instance_variable_get(:@options)
|
|
18
|
-
expect(options[:timeout]).to eq 33
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Geoblacklight::GeojsonDownload do
|
|
6
|
-
let(:document) { SolrDocument.new(Geoblacklight.configuration.fields.id => "test", :solr_wfs_url => "http://www.example.com/wfs", Geoblacklight.configuration.fields.wxs_identifier => "stanford-test", Geoblacklight.configuration.fields.geometry => "ENVELOPE(-180, 180, 90, -90)") }
|
|
7
|
-
let(:download) { described_class.new(document) }
|
|
8
|
-
describe "#initialize" do
|
|
9
|
-
it "initializes as a GeojsonDownload object with specific options" do
|
|
10
|
-
expect(download).to be_an described_class
|
|
11
|
-
options = download.instance_variable_get(:@options)
|
|
12
|
-
expect(options[:content_type]).to eq "application/json"
|
|
13
|
-
expect(options[:request_params][:typeName]).to eq "stanford-test"
|
|
14
|
-
expect(options[:extension]).to eq "geojson"
|
|
15
|
-
end
|
|
16
|
-
it "merges custom options" do
|
|
17
|
-
download = described_class.new(document, timeout: 33)
|
|
18
|
-
options = download.instance_variable_get(:@options)
|
|
19
|
-
expect(options[:timeout]).to eq 33
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Geoblacklight::GeotiffDownload do
|
|
6
|
-
let(:document) do
|
|
7
|
-
SolrDocument.new(Geoblacklight.configuration.fields.id => "test", Geoblacklight.configuration.fields.wxs_identifier => "stanford-test",
|
|
8
|
-
Geoblacklight.configuration.fields.geometry => "ENVELOPE(-180, 180, 90, -90)")
|
|
9
|
-
end
|
|
10
|
-
let(:download) { described_class.new(document) }
|
|
11
|
-
describe "#initialize" do
|
|
12
|
-
it "initializes as a GeotiffDownload object with specific options" do
|
|
13
|
-
expect(download).to be_an described_class
|
|
14
|
-
options = download.instance_variable_get(:@options)
|
|
15
|
-
expect(options[:content_type]).to eq "image/geotiff"
|
|
16
|
-
expect(options[:request_params][:layers]).to eq "stanford-test"
|
|
17
|
-
expect(options[:reflect]).to be_truthy
|
|
18
|
-
end
|
|
19
|
-
it "merges custom options" do
|
|
20
|
-
download = described_class.new(document, timeout: 33)
|
|
21
|
-
options = download.instance_variable_get(:@options)
|
|
22
|
-
expect(options[:timeout]).to eq 33
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Geoblacklight::KmzDownload do
|
|
6
|
-
let(:document) { SolrDocument.new(Geoblacklight.configuration.fields.id => "test", :solr_wfs_url => "http://www.example.com/wfs", Geoblacklight.configuration.fields.wxs_identifier => "stanford-test", Geoblacklight.configuration.fields.geometry => "ENVELOPE(-180, 180, 90, -90)") }
|
|
7
|
-
let(:download) { described_class.new(document) }
|
|
8
|
-
describe "#initialize" do
|
|
9
|
-
it "initializes as a KmzDownload object with specific options" do
|
|
10
|
-
expect(download).to be_an described_class
|
|
11
|
-
options = download.instance_variable_get(:@options)
|
|
12
|
-
expect(options[:content_type]).to eq "application/vnd.google-earth.kmz"
|
|
13
|
-
expect(options[:request_params][:layers]).to eq "stanford-test"
|
|
14
|
-
expect(options[:request_params][:bbox]).to eq "-180.0, -90.0, 180.0, 90.0"
|
|
15
|
-
end
|
|
16
|
-
it "merges custom options" do
|
|
17
|
-
download = described_class.new(document, timeout: 33)
|
|
18
|
-
options = download.instance_variable_get(:@options)
|
|
19
|
-
expect(options[:timeout]).to eq 33
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Geoblacklight::ShapefileDownload do
|
|
6
|
-
let(:document) { SolrDocument.new(Geoblacklight.configuration.fields.id => "test", :solr_wfs_url => "http://www.example.com/wfs", Geoblacklight.configuration.fields.wxs_identifier => "stanford-test", Geoblacklight.configuration.fields.geometry => "ENVELOPE(-180, 180, 90, -90)") }
|
|
7
|
-
let(:download) { described_class.new(document) }
|
|
8
|
-
describe "#initialize" do
|
|
9
|
-
it "initializes as a ShapefileDownload object with specific options" do
|
|
10
|
-
expect(download).to be_an described_class
|
|
11
|
-
options = download.instance_variable_get(:@options)
|
|
12
|
-
expect(options[:content_type]).to eq "application/zip"
|
|
13
|
-
expect(options[:request_params][:typeName]).to eq "stanford-test"
|
|
14
|
-
end
|
|
15
|
-
it "merges custom options" do
|
|
16
|
-
download = described_class.new(document, timeout: 33)
|
|
17
|
-
options = download.instance_variable_get(:@options)
|
|
18
|
-
expect(options[:timeout]).to eq 33
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Geoblacklight::Download do
|
|
6
|
-
subject(:download) { described_class.new(document, options) }
|
|
7
|
-
|
|
8
|
-
let(:faraday_connection) { instance_double(Faraday::Connection) }
|
|
9
|
-
let(:faraday_response) { instance_double(Faraday::Response) }
|
|
10
|
-
let(:references_field) { Geoblacklight.configuration.fields.references }
|
|
11
|
-
let(:document) do
|
|
12
|
-
SolrDocument.new(:"#{Geoblacklight.configuration.fields.id}" => "test",
|
|
13
|
-
references_field => {"http://www.opengis.net/def/serviceType/ogc/wms" => "http://www.example.com/wms"}.to_json)
|
|
14
|
-
end
|
|
15
|
-
let(:options) { {type: "shapefile", extension: "zip", service_type: "wms", content_type: "application/zip"} }
|
|
16
|
-
|
|
17
|
-
describe "#initialize" do
|
|
18
|
-
it "initializes as a Download object" do
|
|
19
|
-
expect(download).to be_a described_class
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe "#downloadable?" do
|
|
24
|
-
before do
|
|
25
|
-
allow(document).to receive(:downloadable?).and_return(true)
|
|
26
|
-
end
|
|
27
|
-
it "determines whether or not the resource can be downloaded" do
|
|
28
|
-
expect(download.downloadable?).to be true
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "#file_name" do
|
|
33
|
-
it "gives the file name with path and extension" do
|
|
34
|
-
expect(download.file_name).to eq "test-shapefile.zip"
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "#file_path" do
|
|
39
|
-
it "returns the path with name and extension" do
|
|
40
|
-
expect(download.class.file_path).to eq Rails.root.join("tmp", "cache", "downloads").to_s
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "is configurable" do
|
|
44
|
-
expect(Geoblacklight.configuration).to receive(:download_path).and_return("configured/path")
|
|
45
|
-
expect(download.class.file_path).to eq "configured/path"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe "#download_exists?" do
|
|
50
|
-
it "returns false if file does not exist" do
|
|
51
|
-
expect(File).to receive(:file?).and_return(false)
|
|
52
|
-
expect(download.download_exists?).to be_falsey
|
|
53
|
-
end
|
|
54
|
-
it "returns true if file does not exist" do
|
|
55
|
-
expect(File).to receive(:file?).and_return(true)
|
|
56
|
-
expect(download.download_exists?).to be_truthy
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
describe "#get" do
|
|
60
|
-
before do
|
|
61
|
-
allow(File).to receive(:file?).and_return(true)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "returns filename if download exists" do
|
|
65
|
-
expect(download.get).to eq download.file_name
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
context "when the file has not already been downloaded" do
|
|
69
|
-
let(:connection) { instance_double(Faraday::Connection) }
|
|
70
|
-
let(:response) { instance_double(Faraday::Response) }
|
|
71
|
-
|
|
72
|
-
before do
|
|
73
|
-
allow(File).to receive(:file?).and_return(false)
|
|
74
|
-
allow(connection).to receive(:get).and_return(object: "file")
|
|
75
|
-
allow(Faraday).to receive(:new).and_return(connection)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "calls create_download_file if it does not exist" do
|
|
79
|
-
allow(File).to receive(:open).with("#{download.file_path_and_name}.tmp", "wb").and_return("")
|
|
80
|
-
allow(File).to receive(:rename)
|
|
81
|
-
|
|
82
|
-
expect(download.get).to eq "test-shapefile.zip"
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
describe "#create_download_file" do
|
|
87
|
-
let(:file) { instance_double(File) }
|
|
88
|
-
let(:shapefile) { OpenStruct.new(headers: {"content-type" => "application/zip"}) }
|
|
89
|
-
let(:connection) { instance_double(Faraday::Connection) }
|
|
90
|
-
let(:response) { instance_double(Faraday::Response) }
|
|
91
|
-
|
|
92
|
-
before do
|
|
93
|
-
allow(file).to receive(:write)
|
|
94
|
-
allow(Faraday).to receive(:new).and_return(connection)
|
|
95
|
-
allow(connection).to receive(:get).and_return(shapefile)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "creates the file, write it, and then rename from tmp if everything is ok" do
|
|
99
|
-
allow(File).to receive(:open).with("#{download.file_path_and_name}.tmp", "wb").and_yield(file).and_return("")
|
|
100
|
-
allow(File).to receive(:rename)
|
|
101
|
-
|
|
102
|
-
expect(download.create_download_file).to eq download.file_name
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
context "when the file received is not of the type requested" do
|
|
106
|
-
let(:bad_file) { OpenStruct.new(headers: {"content-type" => "bad/file"}) }
|
|
107
|
-
|
|
108
|
-
before do
|
|
109
|
-
allow(connection).to receive(:get).and_return(bad_file)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it "creates the file in fs and delete it if the content headers are not correct" do
|
|
113
|
-
allow(File).to receive(:delete).with("#{download.file_path_and_name}.tmp").and_return(nil)
|
|
114
|
-
|
|
115
|
-
expect do
|
|
116
|
-
download.create_download_file
|
|
117
|
-
end.to raise_error(Geoblacklight::Exceptions::ExternalDownloadFailed,
|
|
118
|
-
"Wrong download type")
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
context "when the MIME type has more information encoded" do
|
|
123
|
-
let(:geojson) { OpenStruct.new(headers: {"content-type" => "application/json;charset=utf-8"}) }
|
|
124
|
-
|
|
125
|
-
before do
|
|
126
|
-
allow(connection).to receive(:get).and_return(geojson)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it "accepts response MIME type that is more complex than requested" do
|
|
130
|
-
allow(File).to receive(:open).with("#{download.file_path_and_name}.tmp", "wb").and_return("")
|
|
131
|
-
allow(File).to receive(:rename)
|
|
132
|
-
|
|
133
|
-
expect(download.create_download_file).to eq download.file_name
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
describe "#initiate_download" do
|
|
138
|
-
let(:faraday_request) { instance_double(Faraday::Request) }
|
|
139
|
-
let(:faraday_request_options) { OpenStruct.new(timeout: nil, open_timeout: nil) }
|
|
140
|
-
|
|
141
|
-
before do
|
|
142
|
-
allow(faraday_request).to receive(:params=)
|
|
143
|
-
allow(faraday_request).to receive(:options).and_return(faraday_request_options)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
it "request download from server" do
|
|
147
|
-
allow(faraday_connection).to receive(:get).and_yield(faraday_request).and_return(faraday_response)
|
|
148
|
-
allow(Faraday).to receive(:new).with(url: "http://www.example.com/wms").and_return(faraday_connection)
|
|
149
|
-
|
|
150
|
-
expect(download.initiate_download).to eq faraday_response
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it "raises Geoblacklight::Exceptions::ExternalDownloadFailed with a connection failure" do
|
|
154
|
-
expect(faraday_connection).to receive(:url_prefix).and_return "http://www.example.com/wms"
|
|
155
|
-
expect(faraday_connection).to receive(:get).and_raise(Faraday::ConnectionFailed.new("Failed"))
|
|
156
|
-
expect(Faraday).to receive(:new).with(url: "http://www.example.com/wms").and_return(faraday_connection)
|
|
157
|
-
expect { download.initiate_download }.to raise_error(Geoblacklight::Exceptions::ExternalDownloadFailed)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
it "raises Geoblacklight::Exceptions::ExternalDownloadFailed with a connection timout" do
|
|
161
|
-
expect(faraday_connection).to receive(:url_prefix).and_return "http://www.example.com/wms"
|
|
162
|
-
expect(faraday_connection).to receive(:get).and_raise(Faraday::TimeoutError)
|
|
163
|
-
expect(Faraday).to receive(:new).with(url: "http://www.example.com/wms").and_return(faraday_connection)
|
|
164
|
-
expect { download.initiate_download }.to raise_error(Geoblacklight::Exceptions::ExternalDownloadFailed)
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
describe "#url_with_params" do
|
|
168
|
-
let(:options) do
|
|
169
|
-
{
|
|
170
|
-
service_type: "wms",
|
|
171
|
-
request_params: {
|
|
172
|
-
service: "wfs",
|
|
173
|
-
version: "2.0.0",
|
|
174
|
-
request: "GetFeature",
|
|
175
|
-
srsName: "EPSG:4326",
|
|
176
|
-
outputformat: "SHAPE-ZIP",
|
|
177
|
-
typeName: ""
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "creates a download url with params" do
|
|
183
|
-
expect(download.url_with_params).to eq "http://www.example.com/wms/?ser" \
|
|
184
|
-
"vice=wfs&version=2.0.0&request=GetFeature&srsName=EPSG%3A4326&output" \
|
|
185
|
-
"format=SHAPE-ZIP&typeName="
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
require "rake"
|
|
5
|
-
require "fileutils"
|
|
6
|
-
|
|
7
|
-
RSpec.describe "geoblacklight.rake" do
|
|
8
|
-
describe "geoblacklight:downloads:mkdir" do
|
|
9
|
-
before do
|
|
10
|
-
Rails.application.load_tasks
|
|
11
|
-
FileUtils.rm_rf Rails.root.join("tmp", "cache", "downloads")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "creates the tmp/cache/downloads directory" do
|
|
15
|
-
Rake::Task["geoblacklight:downloads:mkdir"].invoke
|
|
16
|
-
expect(File.directory?(Rails.root.join("tmp", "cache", "downloads")))
|
|
17
|
-
.to be true
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|