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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -1
  3. data/app/assets/stylesheets/geoblacklight/record.css +37 -1
  4. data/app/components/geoblacklight/document/download_link_component.html.erb +6 -0
  5. data/app/components/geoblacklight/document/download_link_component.rb +66 -0
  6. data/app/components/geoblacklight/document/download_links_component.html.erb +8 -0
  7. data/app/components/geoblacklight/document/download_links_component.rb +59 -0
  8. data/app/components/geoblacklight/document/sidebar_component.html.erb +3 -9
  9. data/app/components/geoblacklight/document/sidebar_component.rb +6 -11
  10. data/app/components/geoblacklight/login_link_component.html.erb +3 -5
  11. data/app/javascript/geoblacklight/core.js +0 -2
  12. data/app/javascript/geoblacklight/index.js +0 -2
  13. data/app/javascript/geoblacklight/leaflet/inspection.js +5 -4
  14. data/app/models/concerns/geoblacklight/solr_document.rb +1 -2
  15. data/config/locales/geoblacklight.en.yml +5 -14
  16. data/lib/generators/geoblacklight/install_generator.rb +4 -9
  17. data/lib/generators/geoblacklight/templates/settings.yml +1 -15
  18. data/lib/geoblacklight/configuration/settings_builder.rb +0 -3
  19. data/lib/geoblacklight/configuration.rb +0 -10
  20. data/lib/geoblacklight/exceptions.rb +0 -23
  21. data/lib/geoblacklight/references.rb +0 -80
  22. data/lib/geoblacklight/version.rb +1 -1
  23. data/lib/geoblacklight.rb +0 -1
  24. data/lib/tasks/geoblacklight.rake +0 -30
  25. data/spec/components/geoblacklight/document/sidebar_component_spec.rb +1 -1
  26. data/spec/components/geoblacklight/download_links_component_spec.rb +59 -85
  27. data/spec/features/index_view_spec.rb +0 -33
  28. data/spec/features/layer_inspection_spec.rb +0 -10
  29. data/spec/features/layer_opacity_spec.rb +0 -7
  30. data/spec/lib/geoblacklight/configuration/settings_builder_spec.rb +0 -2
  31. data/spec/lib/geoblacklight/references_spec.rb +1 -57
  32. data/spec/models/concerns/geoblacklight/solr_document_spec.rb +0 -7
  33. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  34. data/template.rb +1 -1
  35. metadata +6 -28
  36. data/app/components/geoblacklight/download_links_component.html.erb +0 -31
  37. data/app/components/geoblacklight/download_links_component.rb +0 -87
  38. data/app/controllers/download_controller.rb +0 -76
  39. data/app/javascript/geoblacklight/controllers/downloads_controller.js +0 -64
  40. data/lib/geoblacklight/download/csv_download.rb +0 -22
  41. data/lib/geoblacklight/download/geojson_download.rb +0 -24
  42. data/lib/geoblacklight/download/geotiff_download.rb +0 -22
  43. data/lib/geoblacklight/download/kmz_download.rb +0 -24
  44. data/lib/geoblacklight/download/shapefile_download.rb +0 -22
  45. data/lib/geoblacklight/download.rb +0 -110
  46. data/lib/geoblacklight/routes/downloadable.rb +0 -15
  47. data/spec/controllers/download_controller_spec.rb +0 -99
  48. data/spec/features/download_layer_spec.rb +0 -96
  49. data/spec/features/esri_viewer_spec.rb +0 -43
  50. data/spec/features/index_map_spec.rb +0 -40
  51. data/spec/features/layer_with_no_references_spec.rb +0 -10
  52. data/spec/features/linkified_attribute_table_spec.rb +0 -13
  53. data/spec/features/multiple_downloads_spec.rb +0 -17
  54. data/spec/features/show_page_download_spec.rb +0 -22
  55. data/spec/lib/geoblacklight/download/csv_download_spec.rb +0 -21
  56. data/spec/lib/geoblacklight/download/geojson_download_spec.rb +0 -22
  57. data/spec/lib/geoblacklight/download/geotiff_download_spec.rb +0 -25
  58. data/spec/lib/geoblacklight/download/kmz_download_spec.rb +0 -22
  59. data/spec/lib/geoblacklight/download/shapefile_download_spec.rb +0 -21
  60. data/spec/lib/geoblacklight/download_spec.rb +0 -188
  61. data/spec/tasks/geoblacklight_spec.rb +0 -20
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- # Display expandable file download links in sidebar
5
- class DownloadLinksComponent < ViewComponent::Base
6
- attr_reader :document
7
-
8
- def initialize(document:)
9
- @document = document
10
- super()
11
- end
12
-
13
- def render?
14
- downloadable? && (document.direct_download.present? || document.iiif_download.present? || document.download_types.present?)
15
- end
16
-
17
- def downloadable?
18
- helpers.document_available?(@document) && @document.downloadable?
19
- end
20
-
21
- def download_link_file(label, id, url)
22
- link_to(
23
- label,
24
- url,
25
- "contentUrl" => url,
26
- :data => {
27
- download: "trigger",
28
- download_type: "direct",
29
- download_id: id
30
- }
31
- )
32
- end
33
-
34
- # Generates the link markup for the IIIF JPEG download
35
- # @return [String]
36
- def download_link_iiif
37
- link_to(
38
- download_text("JPG"),
39
- iiif_jpg_url,
40
- "contentUrl" => iiif_jpg_url,
41
- :data => {
42
- download: "trigger"
43
- }
44
- )
45
- end
46
-
47
- def download_link_generated(download_type, document)
48
- link_to(
49
- t("geoblacklight.download.export_link", download_format: export_format_label(download_type)),
50
- "",
51
- data: {
52
- download_path: download_path(document.id, type: download_type),
53
- download: "trigger",
54
- action: "downloads#download:once",
55
- download_type: download_type,
56
- download_id: document.id,
57
- download_preparing_message: t("geoblacklight.download.preparing"),
58
- download_ready_message: t("geoblacklight.download.ready", type: download_type),
59
- download_failed_message: t("geoblacklight.download.failed", type: download_type)
60
- }
61
- )
62
- end
63
-
64
- ##
65
- # Wraps download text with proper_case_format
66
- #
67
- def download_text(format)
68
- download_format = proper_case_format(format)
69
- value = t("geoblacklight.download.download_link", download_format: download_format)
70
- value.html_safe
71
- end
72
-
73
- # Format labels are customized for exports - look up the appropriate key.
74
- def export_format_label(format)
75
- t("geoblacklight.download.export_#{format.to_s.parameterize(separator: "_")}_link")
76
- end
77
-
78
- # Looks up properly formatted names for formats
79
- def proper_case_format(format)
80
- t("geoblacklight.formats.#{format.to_s.parameterize(separator: "_")}")
81
- end
82
-
83
- def iiif_jpg_url
84
- @document.references.iiif.endpoint.sub! "info.json", "full/full/0/default.jpg"
85
- end
86
- end
87
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class DownloadController < ApplicationController
4
- include Blacklight::Catalog
5
-
6
- rescue_from Geoblacklight::Exceptions::ExternalDownloadFailed do |exception|
7
- Geoblacklight.logger.error exception.message + " " + exception.url
8
- flash.now[:danger] = view_context
9
- .tag.span(t("geoblacklight.download.error"),
10
- data: {
11
- download: "error",
12
- download_id: params[:id],
13
- download_type: "generated-#{params[:type]}"
14
- })
15
- respond_to do |format|
16
- format.json { render json: [flash, ""], response: response, status: 500 }
17
- format.html { render json: [flash, ""], response: response, status: 500 }
18
- end
19
- end
20
-
21
- def show
22
- @document = search_service.fetch params[:id]
23
- restricted_should_authenticate
24
- response = check_type
25
- validate response
26
- respond_to do |format|
27
- format.json { render json: [flash, download_file_path(response)], response: response }
28
- format.html { render json: [flash, download_file_path(response)], response: response }
29
- end
30
- end
31
-
32
- def file
33
- # Grab the solr document to check if it should be public or not
34
- @document = search_service.fetch(file_name_to_id(params[:id]))
35
- restricted_should_authenticate
36
- send_file download_file_path_and_name, x_sendfile: true
37
- end
38
-
39
- private
40
-
41
- def download_file_path_and_name
42
- "#{Geoblacklight::Download.file_path}/#{params[:id]}.#{params[:format]}"
43
- end
44
-
45
- def check_type
46
- case params[:type]
47
- when "shapefile"
48
- Geoblacklight::ShapefileDownload.new(@document).get
49
- when "kmz"
50
- Geoblacklight::KmzDownload.new(@document).get
51
- when "geojson"
52
- Geoblacklight::GeojsonDownload.new(@document).get
53
- when "geotiff"
54
- Geoblacklight::GeotiffDownload.new(@document).get
55
- when "csv"
56
- Geoblacklight::CsvDownload.new(@document).get
57
- end
58
- end
59
-
60
- def validate(response)
61
- flash.now[:success] = view_context.link_to(t("geoblacklight.download.success", title: response),
62
- download_file_path(response),
63
- data: {download: "trigger",
64
- download_id: params[:id],
65
- download_type: "generated-#{params[:type]}"})
66
- end
67
-
68
- # Checks whether a document is public, if not require user to authenticate
69
- def restricted_should_authenticate
70
- authenticate_user! unless @document.public?
71
- end
72
-
73
- def file_name_to_id(file_name)
74
- file_name.split("-")[0..-2].join("-")
75
- end
76
- end
@@ -1,64 +0,0 @@
1
- import { Controller } from "@hotwired/stimulus"
2
-
3
- export default class extends Controller {
4
- download(ev) {
5
- ev.preventDefault()
6
- if (this.downloading) {
7
- return
8
- }
9
- this.downloading = true
10
- ev.target.classList.add("download-in-progress")
11
- const url = ev.target.dataset.downloadPath
12
- ev.target.removeAttribute("href")
13
- ev.target.innerHTML = `<div class="spinner-border spinner-border-sm float-end"></div> ${ev.target.dataset.downloadPreparingMessage}`
14
-
15
- fetch(url)
16
- .then((response) => {
17
- if (!response.ok) {
18
- return response.json().then((errorData) => {
19
- const exception = new Error("Network response was not ok")
20
- exception.data = errorData // Attach the parsed JSON data to the error object
21
- throw exception
22
- })
23
- }
24
- return response.json()
25
- })
26
- .then((data) => this.complete(data, ev.target))
27
- .catch((error) => this.error(error, ev.target))
28
- }
29
-
30
- complete(data, target) {
31
- this.downloading = false
32
- target.classList.remove("download-in-progress")
33
- target.classList.add("download-complete")
34
- target.innerHTML = target.dataset.downloadReadyMessage
35
- target.href = data[1]
36
- this.renderMessage(data[0])
37
- //target.click();
38
- }
39
-
40
- error(exception, target) {
41
- this.downloading = false
42
- target.classList.remove("download-in-progress")
43
- target.classList.add("download-complete")
44
- target.innerHTML = target.dataset.downloadFailedMessage
45
- console.log(exception)
46
-
47
- this.renderMessage(exception.data[0])
48
- }
49
-
50
- renderMessage(message) {
51
- let flashContainer = document.querySelector("div.flash_messages")
52
- if (!flashContainer) {
53
- flashContainer = document.createElement("div")
54
- flashContainer.className = "flash_messages"
55
- document.getElementById("document").prepend(flashContainer)
56
- }
57
- Object.entries(message).forEach(([idx, msg]) => {
58
- const flash = document.createElement("div")
59
- flash.className = `alert alert-${msg[0]} alert-dismissible fade show`
60
- flash.innerHTML = `${msg[1]}<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>`
61
- flashContainer.appendChild(flash)
62
- })
63
- }
64
- }
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- class CsvDownload < Geoblacklight::Download
5
- CSV_DOWNLOAD_PARAMS = {service: "wfs",
6
- version: "2.0.0",
7
- request: "GetFeature",
8
- srsName: "EPSG:4326",
9
- outputformat: "csv"}.freeze
10
-
11
- def initialize(document, options = {})
12
- request_params = CSV_DOWNLOAD_PARAMS.merge(typeName: document.wxs_identifier)
13
- super(document, {
14
- type: "csv",
15
- extension: "csv",
16
- request_params: request_params,
17
- content_type: "text/csv",
18
- service_type: "wfs"
19
- }.merge(options))
20
- end
21
- end
22
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- class GeojsonDownload < Geoblacklight::Download
5
- GEOJSON_DOWNLOAD_PARAMS = {
6
- service: "wfs",
7
- version: "2.0.0",
8
- request: "GetFeature",
9
- srsName: "EPSG:4326",
10
- outputformat: "application/json"
11
- }.freeze
12
-
13
- def initialize(document, options = {})
14
- request_params = GEOJSON_DOWNLOAD_PARAMS.merge(typeName: document.wxs_identifier)
15
- super(document, {
16
- type: "geojson",
17
- extension: "geojson",
18
- request_params: request_params,
19
- content_type: "application/json",
20
- service_type: "wfs"
21
- }.merge(options))
22
- end
23
- end
24
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- class GeotiffDownload < Geoblacklight::Download
5
- GEOTIFF_DOWNLOAD_PARAMS = {
6
- format: "image/geotiff",
7
- width: 4096
8
- }.freeze
9
-
10
- def initialize(document, options = {})
11
- request_params = GEOTIFF_DOWNLOAD_PARAMS.merge(layers: document.wxs_identifier)
12
- super(document, {
13
- type: "geotiff",
14
- extension: "tif",
15
- request_params: request_params,
16
- content_type: "image/geotiff",
17
- service_type: "wms",
18
- reflect: true
19
- }.merge(options))
20
- end
21
- end
22
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- class KmzDownload < Geoblacklight::Download
5
- KMZ_DOWNLOAD_PARAMS = {service: "wms",
6
- version: "1.1.0",
7
- request: "GetMap",
8
- srsName: "EPSG:3857",
9
- format: "application/vnd.google-earth.kmz",
10
- width: 2000, height: 2000}.freeze
11
-
12
- def initialize(document, options = {})
13
- bbox_wsen = document.geometry.bounding_box
14
- request_params = KMZ_DOWNLOAD_PARAMS.merge(layers: document.wxs_identifier, bbox: bbox_wsen)
15
- super(document, {
16
- type: "kmz",
17
- extension: "kmz",
18
- request_params: request_params,
19
- content_type: "application/vnd.google-earth.kmz",
20
- service_type: "wms"
21
- }.merge(options))
22
- end
23
- end
24
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- class ShapefileDownload < Geoblacklight::Download
5
- SHAPEFILE_DOWNLOAD_PARAMS = {service: "wfs",
6
- version: "2.0.0",
7
- request: "GetFeature",
8
- srsName: "EPSG:4326",
9
- outputformat: "SHAPE-ZIP"}.freeze
10
-
11
- def initialize(document, options = {})
12
- request_params = SHAPEFILE_DOWNLOAD_PARAMS.merge(typeName: document.wxs_identifier)
13
- super(document, {
14
- type: "shapefile",
15
- extension: "zip",
16
- request_params: request_params,
17
- content_type: "application/zip",
18
- service_type: "wfs"
19
- }.merge(options))
20
- end
21
- end
22
- end
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- class Download
5
- def initialize(document, options = {})
6
- @document = document
7
- @options = options
8
- end
9
-
10
- def downloadable?
11
- @document.downloadable?
12
- end
13
-
14
- def file_name
15
- "#{@document.id}-#{@options[:type]}.#{@options[:extension]}"
16
- end
17
-
18
- def self.file_path
19
- Geoblacklight.configuration.download_path
20
- end
21
-
22
- def file_path_and_name
23
- "#{self.class.file_path}/#{file_name}"
24
- end
25
-
26
- def download_exists?
27
- File.file?(file_path_and_name)
28
- end
29
-
30
- def get
31
- if download_exists?
32
- file_name
33
- else
34
- create_download_file
35
- end
36
- end
37
-
38
- ##
39
- # Creates temporary file on file system and renames it if download completes
40
- # successfully. Will raise and rescue if the wrong file format is downloaded
41
- # @return [String] filename of the completed download
42
- def create_download_file
43
- download = initiate_download
44
-
45
- File.open("#{file_path_and_name}.tmp", "wb") do |file|
46
- fail Geoblacklight::Exceptions::WrongDownloadFormat unless matches_mimetype?(download)
47
- file.write download.body
48
- end
49
- File.rename("#{file_path_and_name}.tmp", file_path_and_name)
50
- file_name
51
- rescue Geoblacklight::Exceptions::WrongDownloadFormat => error
52
- Geoblacklight.logger.error "#{error} expected #{@options[:content_type]} " \
53
- "received #{download.headers["content-type"]}"
54
- File.delete("#{file_path_and_name}.tmp")
55
- raise Geoblacklight::Exceptions::ExternalDownloadFailed, message: "Wrong download type"
56
- end
57
-
58
- ##
59
- # Initiates download from a remote source url using the `request_params`.
60
- # Will catch Faraday::ConnectionFailed and
61
- # Faraday::TimeoutError
62
- # @return [Faraday::Request] returns a Faraday::Request object
63
- def initiate_download
64
- conn = Faraday.new(url: url)
65
- conn.get do |request|
66
- request.params = @options[:request_params]
67
- request.options.timeout = timeout
68
- request.options.open_timeout = timeout
69
- end
70
- rescue Faraday::ConnectionFailed
71
- raise Geoblacklight::Exceptions::ExternalDownloadFailed,
72
- message: "Download connection failed",
73
- url: conn.url_prefix.to_s
74
- rescue Faraday::TimeoutError
75
- raise Geoblacklight::Exceptions::ExternalDownloadFailed,
76
- message: "Download timed out",
77
- url: conn.url_prefix.to_s
78
- end
79
-
80
- ##
81
- # Creates a download url for the object
82
- # @return [String]
83
- def url_with_params
84
- url + "/?" + URI.encode_www_form(@options[:request_params])
85
- end
86
-
87
- private
88
-
89
- def matches_mimetype?(download)
90
- MIME::Type.simplified(download.headers["content-type"]) == @options[:content_type]
91
- end
92
-
93
- ##
94
- # Returns timeout for the download request. `timeout` passed as an option to
95
- # the Geoblacklight::Download class
96
- # @return [Fixnum] download timeout in seconds
97
- def timeout
98
- @options[:timeout] || Geoblacklight.configuration.timeout_download
99
- end
100
-
101
- ##
102
- # URL for download
103
- # @return [String] URL that is checked in download
104
- def url
105
- url = @document.references.public_send(@options[:service_type]).endpoint
106
- url += "/reflect" if @options[:reflect]
107
- url
108
- end
109
- end
110
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geoblacklight
4
- module Routes
5
- class Downloadable
6
- def initialize(defaults = {})
7
- @defaults = defaults
8
- end
9
-
10
- def call(mapper, _options = {})
11
- mapper.get "file/:id", action: "file", as: :file
12
- end
13
- end
14
- end
15
- end
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe DownloadController, type: :controller do
6
- describe "#file" do
7
- describe "restricted file" do
8
- it "redirects to login for authentication" do
9
- get :file, params: {id: "stanford-cg357zz0321-shapefile", format: "zip"}
10
- expect(response).to have_http_status :unauthorized
11
- end
12
- end
13
- describe "public file" do
14
- it "initiates download" do
15
- allow(controller).to receive(:render) # Needed for testing with Rails 4
16
- expect(controller).to receive(:send_file)
17
- get :file, params: {id: "mit-f6rqs4ucovjk2-shapefile", format: "zip"}
18
- end
19
- end
20
- end
21
- describe "#show" do
22
- describe "restricted file" do
23
- it "redirects to login for authentication" do
24
- get :show, params: {id: "stanford-cg357zz0321", format: "json"}
25
- expect(response).to have_http_status :unauthorized
26
- end
27
- end
28
- describe "public file" do
29
- let(:shapefile_download) { instance_double(Geoblacklight::ShapefileDownload) }
30
-
31
- before do
32
- allow(Geoblacklight::ShapefileDownload).to receive(:new).and_return(shapefile_download)
33
- end
34
-
35
- it "initiates download creation" do
36
- allow(shapefile_download).to receive(:get).and_return("success")
37
- get :show, params: {id: "mit-f6rqs4ucovjk2", type: "shapefile"}
38
- expect(response).to have_http_status :ok
39
- end
40
- end
41
-
42
- context "when requesting GeoJSON files" do
43
- let(:id) { "tufts-cambridgegrid100-04" }
44
- let(:type) { "geojson" }
45
- let(:geojson_download) { instance_double(Geoblacklight::GeojsonDownload) }
46
-
47
- before do
48
- allow(geojson_download).to receive(:get).and_return("file.json")
49
- allow(Geoblacklight::GeojsonDownload).to receive(:new).and_return(geojson_download)
50
- end
51
-
52
- it "downloads the files and notifies the user" do
53
- expect(Geoblacklight::GeojsonDownload).to receive(:new)
54
- get :show, params: {id: id, type: type}
55
-
56
- expect(response.body).to include "success"
57
- expect(response.body).to include "Your file file.json is ready for download"
58
- end
59
- end
60
-
61
- context "when requesting GeoTIFF files" do
62
- let(:id) { "tufts-cambridgegrid100-04" }
63
- let(:type) { "geotiff" }
64
- let(:geotiff_download) { instance_double(Geoblacklight::GeotiffDownload) }
65
-
66
- before do
67
- allow(geotiff_download).to receive(:get).and_return("file.tiff")
68
- allow(Geoblacklight::GeotiffDownload).to receive(:new).and_return(geotiff_download)
69
- end
70
-
71
- it "downloads the files and notifies the user" do
72
- expect(Geoblacklight::GeotiffDownload).to receive(:new)
73
- get :show, params: {id: id, type: type}
74
-
75
- expect(response.body).to include "success"
76
- expect(response.body).to include "Your file file.tiff is ready for download"
77
- end
78
- end
79
-
80
- context "when requesting CSV files" do
81
- let(:id) { "tufts-cambridgegrid100-04" }
82
- let(:type) { "csv" }
83
- let(:csv_download) { instance_double(Geoblacklight::CsvDownload) }
84
-
85
- before do
86
- allow(csv_download).to receive(:get).and_return("file.csv")
87
- allow(Geoblacklight::CsvDownload).to receive(:new).and_return(csv_download)
88
- end
89
-
90
- it "downloads the files and notifies the user" do
91
- expect(Geoblacklight::CsvDownload).to receive(:new)
92
- get :show, params: {id: id, type: type}
93
-
94
- expect(response.body).to include "success"
95
- expect(response.body).to include "Your file file.csv is ready for download"
96
- end
97
- end
98
- end
99
- end
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.feature "Download layer" do
6
- let(:shapefile_download) { instance_double(Geoblacklight::ShapefileDownload) }
7
- let(:kmz_download) { instance_double(Geoblacklight::KmzDownload) }
8
- let(:csv_download) { instance_double(Geoblacklight::CsvDownload) }
9
-
10
- before do
11
- allow(Geoblacklight::ShapefileDownload).to receive(:new).and_return(shapefile_download)
12
- allow(Geoblacklight::KmzDownload).to receive(:new).and_return(kmz_download)
13
- allow(Geoblacklight::CsvDownload).to receive(:new).and_return(csv_download)
14
- end
15
-
16
- # cleanup any downloaded files
17
- after do
18
- FileUtils.rm("tufts-cambridgegrid100-04-shapefile.zip", force: true)
19
- FileUtils.rm("tufts-cambridgegrid100-04-kmz.kmz", force: true)
20
- end
21
-
22
- scenario "clicking initial shapefile download button should trigger download", js: true do
23
- allow(shapefile_download).to receive(:get).and_return("tufts-cambridgegrid100-04-shapefile.zip")
24
- visit solr_document_path("tufts-cambridgegrid100-04")
25
- find("#downloads-button").click
26
- find('a[data-download-type="shapefile"]', text: "Export Shapefile").click
27
- expect(page).to have_css(
28
- 'a[href="/download/file/tufts-cambridgegrid100-04-shapefile.zip"]',
29
- text: "Your file tufts-cambridgegrid100-04-shapefile.zip is ready for download"
30
- )
31
- end
32
-
33
- scenario "failed download should return message with link to layer", js: true do
34
- allow(shapefile_download).to receive(:get).and_raise(Geoblacklight::Exceptions::ExternalDownloadFailed.new(
35
- message: "Failed", url: "http://www.example.com/failed"
36
- ))
37
- visit solr_document_path("mit-f6rqs4ucovjk2")
38
- find("#downloads-button").click
39
- find('#downloads-collapse a[data-download-type="shapefile"]', text: "Export Shapefile").click
40
- expect(page).to have_text "Download failed (shapefile)"
41
- expect(page).to have_css "div.alert.alert-danger", text: "Sorry, the requested file could not be downloaded."
42
- end
43
-
44
- scenario "clicking kmz download button should trigger download", js: true do
45
- allow(kmz_download).to receive(:get).and_return("tufts-cambridgegrid100-04-kmz.kmz")
46
- visit solr_document_path("tufts-cambridgegrid100-04")
47
- find("#downloads-button").click
48
- find('#downloads-collapse a[data-download-type="kmz"]', text: "Export KMZ").click
49
- expect(page).to have_css(
50
- 'a[href="/download/file/tufts-cambridgegrid100-04-kmz.kmz"]',
51
- text: "Your file tufts-cambridgegrid100-04-kmz.kmz is ready for download"
52
- )
53
- end
54
-
55
- scenario "jpg download option should be present under toggle" do
56
- visit solr_document_path("princeton-02870w62c")
57
- find("#downloads-button").click
58
- expect(page).to have_css("#downloads-collapse a", text: "Original JPG")
59
- end
60
-
61
- scenario "clicking jpg download button should redirect to external image" do
62
- visit solr_document_path("princeton-02870w62c")
63
- find("#downloads-button").click
64
- expect(page).to have_css(
65
- "#downloads-collapse a[href='https://iiif-cloud.princeton.edu/iiif/2/6c%2F52%2F12%2F6c5212e81bc845f59bb1cdc740a88bad%2Fintermediate_file/full/full/0/default.jpg']", text: "Original JPG"
66
- )
67
- end
68
-
69
- scenario "options should be available under toggle" do
70
- visit solr_document_path("tufts-cambridgegrid100-04")
71
- find("#downloads-button").click
72
- expect(page).to have_css('#downloads-collapse a[data-download-type="shapefile"]', text: "Export Shapefile")
73
- expect(page).to have_css('#downloads-collapse a[data-download-type="kmz"]', text: "Export KMZ")
74
- end
75
-
76
- scenario "restricted layer should not have download available to non logged in user" do
77
- visit solr_document_path("stanford-cg357zz0321")
78
- expect(page).to have_css "a", text: "Login to View and Download"
79
- expect(page).not_to have_css "button", text: "Download"
80
- end
81
-
82
- scenario "restricted layer should have download available to logged in user" do
83
- sign_in
84
- visit solr_document_path("stanford-cg357zz0321")
85
- expect(page).not_to have_css "a", text: "Login to view and download"
86
- expect(page).to have_css "button", text: "Download"
87
- end
88
-
89
- scenario "layer with direct download and wms/wfs should include all download types" do
90
- sign_in
91
- visit solr_document_path("stanford-cg357zz0321")
92
- find("#downloads-button").click
93
- expect(page).to have_css("#downloads-collapse a", text: "Original")
94
- expect(page).to have_css("#downloads-collapse a", text: "Export")
95
- end
96
- end