geo_combine 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +53 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +20 -0
  5. data/.rubocop_todo.yml +165 -0
  6. data/Gemfile +3 -1
  7. data/README.md +15 -1
  8. data/Rakefile +4 -2
  9. data/bin/geocombine +1 -0
  10. data/geo_combine.gemspec +5 -0
  11. data/lib/geo_combine/bounding_box.rb +7 -1
  12. data/lib/geo_combine/ckan_metadata.rb +10 -8
  13. data/lib/geo_combine/cli.rb +3 -1
  14. data/lib/geo_combine/esri_open_data.rb +2 -0
  15. data/lib/geo_combine/exceptions.rb +3 -0
  16. data/lib/geo_combine/fgdc.rb +2 -2
  17. data/lib/geo_combine/formats.rb +2 -0
  18. data/lib/geo_combine/formatting.rb +3 -1
  19. data/lib/geo_combine/geo_blacklight_harvester.rb +20 -13
  20. data/lib/geo_combine/geoblacklight.rb +20 -6
  21. data/lib/geo_combine/geometry_types.rb +2 -0
  22. data/lib/geo_combine/iso19139.rb +2 -1
  23. data/lib/geo_combine/ogp.rb +13 -11
  24. data/lib/geo_combine/railtie.rb +2 -0
  25. data/lib/geo_combine/subjects.rb +2 -0
  26. data/lib/geo_combine/version.rb +3 -1
  27. data/lib/geo_combine.rb +4 -3
  28. data/lib/tasks/geo_combine.rake +47 -26
  29. data/lib/xslt/fgdc2html.xsl +38 -9
  30. data/spec/features/fgdc2html_spec.rb +53 -1
  31. data/spec/features/iso2html_spec.rb +10 -1
  32. data/spec/fixtures/docs/princeton_fgdc.xml +374 -0
  33. data/spec/fixtures/docs/repos.json +3224 -0
  34. data/spec/fixtures/docs/simple_xml.xml +10 -0
  35. data/spec/fixtures/docs/simple_xslt.xsl +11 -0
  36. data/spec/fixtures/docs/stanford_iso.xml +652 -0
  37. data/spec/fixtures/docs/tufts_fgdc.xml +977 -0
  38. data/spec/fixtures/indexing/basic_geoblacklight.json +27 -0
  39. data/spec/fixtures/indexing/geoblacklight.json +33 -0
  40. data/spec/fixtures/indexing/layers.json +16119 -0
  41. data/spec/fixtures/indexing/test.txt +1 -0
  42. data/spec/fixtures/json_docs.rb +2 -0
  43. data/spec/fixtures/xml_docs.rb +9 -1659
  44. data/spec/helpers.rb +7 -7
  45. data/spec/lib/geo_combine/bounding_box_spec.rb +18 -0
  46. data/spec/lib/geo_combine/ckan_metadata_spec.rb +34 -11
  47. data/spec/lib/geo_combine/esri_open_data_spec.rb +23 -2
  48. data/spec/lib/geo_combine/fgdc_spec.rb +41 -10
  49. data/spec/lib/geo_combine/formatting_spec.rb +13 -5
  50. data/spec/lib/geo_combine/geo_blacklight_harvester_spec.rb +32 -28
  51. data/spec/lib/geo_combine/geoblacklight_spec.rb +41 -11
  52. data/spec/lib/geo_combine/iso19139_spec.rb +26 -14
  53. data/spec/lib/geo_combine/ogp_spec.rb +28 -8
  54. data/spec/lib/geo_combine_spec.rb +7 -4
  55. data/spec/lib/tasks/geo_combine_spec.rb +45 -0
  56. data/spec/spec_helper.rb +19 -84
  57. data/spec/support/fixtures.rb +9 -0
  58. metadata +102 -7
  59. data/.coveralls.yml +0 -1
  60. data/.travis.yml +0 -8
data/spec/helpers.rb CHANGED
@@ -1,17 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  module Helpers
4
6
  # From https://gist.github.com/ascendbruce/7070951
5
7
  def valid_json?(json)
6
- begin
7
- JSON.parse(json)
8
- return true
9
- rescue Exception => e
10
- return false
11
- end
8
+ JSON.parse(json)
9
+ true
10
+ rescue Exception => e
11
+ false
12
12
  end
13
13
 
14
14
  def trim(text)
15
- %r/\A\s+#{text}\s+\Z/
15
+ /\A\s+#{text}\s+\Z/
16
16
  end
17
17
  end
@@ -1,58 +1,76 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GeoCombine::BoundingBox do
4
6
  subject(:valid) do
5
7
  described_class.new(west: -180, east: 180, north: 90, south: -90)
6
8
  end
9
+
7
10
  describe '#to_envelope' do
8
11
  it 'returns a valid envelope syntax' do
9
12
  expect(valid.to_envelope).to eq 'ENVELOPE(-180.0, 180.0, 90.0, -90.0)'
10
13
  end
11
14
  end
15
+
12
16
  describe '#valid?' do
13
17
  context 'when valid' do
14
18
  it { valid.valid? }
15
19
  end
20
+
16
21
  context 'when south > north' do
17
22
  subject(:invalid) do
18
23
  described_class.new(west: -180, east: 180, north: 33, south: 34)
19
24
  end
25
+
20
26
  it { expect { invalid.valid? }.to raise_error GeoCombine::Exceptions::InvalidGeometry }
21
27
  end
28
+
22
29
  context 'when west > east' do
23
30
  subject(:invalid) do
24
31
  described_class.new(west: 10, east: -20, north: 90, south: -90)
25
32
  end
33
+
26
34
  it { expect { invalid.valid? }.to raise_error GeoCombine::Exceptions::InvalidGeometry }
27
35
  end
36
+
28
37
  context 'when west out of range' do
29
38
  subject(:invalid) do
30
39
  described_class.new(west: -181, east: 180, north: 90, south: -90)
31
40
  end
41
+
32
42
  it { expect { invalid.valid? }.to raise_error GeoCombine::Exceptions::InvalidGeometry }
33
43
  end
44
+
34
45
  context 'when east out of range' do
35
46
  subject(:invalid) do
36
47
  described_class.new(west: -180, east: 181, north: 90, south: -90)
37
48
  end
49
+
38
50
  it { expect { invalid.valid? }.to raise_error GeoCombine::Exceptions::InvalidGeometry }
39
51
  end
52
+
40
53
  context 'when north out of range' do
41
54
  subject(:invalid) do
42
55
  described_class.new(west: -180, east: 180, north: 91, south: -90)
43
56
  end
57
+
44
58
  it { expect { invalid.valid? }.to raise_error GeoCombine::Exceptions::InvalidGeometry }
45
59
  end
60
+
46
61
  context 'when south out of range' do
47
62
  subject(:invalid) do
48
63
  described_class.new(west: -180, east: 180, north: 90, south: -91)
49
64
  end
65
+
50
66
  it { expect { invalid.valid? }.to raise_error GeoCombine::Exceptions::InvalidGeometry }
51
67
  end
52
68
  end
69
+
53
70
  describe '.from_envelope' do
54
71
  it { expect(described_class.from_envelope(valid.to_envelope).to_envelope).to eq valid.to_envelope }
55
72
  end
73
+
56
74
  describe '.from_string_delimiter' do
57
75
  it { expect(described_class.from_string_delimiter('-180, -90, 180, 90').to_envelope).to eq valid.to_envelope }
58
76
  end
@@ -1,63 +1,79 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GeoCombine::CkanMetadata do
4
6
  include JsonDocs
5
- let(:ckan_sample) { GeoCombine::CkanMetadata.new(ckan_metadata) }
7
+ let(:ckan_sample) { described_class.new(ckan_metadata) }
8
+
6
9
  describe '#to_geoblacklight' do
7
10
  it 'returns a GeoCombine::Geoblacklight' do
8
11
  expect(ckan_sample.to_geoblacklight).to be_an GeoCombine::Geoblacklight
9
12
  end
10
13
  end
14
+
11
15
  describe '#geoblacklight_terms' do
12
16
  describe 'builds a hash which maps metadata' do
13
17
  let(:metadata) { ckan_sample.instance_variable_get(:@metadata) }
18
+
14
19
  it 'with dc_identifier_s' do
15
20
  expect(ckan_sample.geoblacklight_terms).to include(dc_identifier_s: metadata['id'])
16
21
  end
22
+
17
23
  it 'with dc_title_s' do
18
24
  expect(ckan_sample.geoblacklight_terms).to include(dc_title_s: metadata['title'])
19
25
  end
26
+
20
27
  it 'with dc_rights_s' do
21
28
  expect(ckan_sample.geoblacklight_terms).to include(dc_rights_s: 'Public')
22
29
  end
30
+
23
31
  it 'with dct_provenance_s' do
24
32
  expect(ckan_sample.geoblacklight_terms).to include(dct_provenance_s: metadata['organization']['title'])
25
33
  end
34
+
26
35
  it 'with layer_slug_s' do
27
36
  expect(ckan_sample.geoblacklight_terms).to include(layer_slug_s: metadata['name'])
28
37
  end
38
+
29
39
  it 'with solr_geom' do
30
40
  expect(ckan_sample.geoblacklight_terms).to include(solr_geom: 'ENVELOPE(-158.2, -105.7, 59.2, 8.9)')
31
41
  end
42
+
32
43
  it 'with dc_subject_sm' do
33
44
  expect(ckan_sample.geoblacklight_terms[:dc_subject_sm].length).to eq 63
34
45
  end
46
+
35
47
  context 'with no information resources' do
36
48
  let(:ckan_sample) do
37
- ckan = GeoCombine::CkanMetadata.new(ckan_metadata)
49
+ ckan = described_class.new(ckan_metadata)
38
50
  metadata = ckan.instance_variable_get('@metadata')
39
51
  metadata['resources'].delete_if { |resource| resource['resource_locator_function'] == 'information' }
40
52
  ckan
41
53
  end
54
+
42
55
  it 'has no url (home page) in dct_references_s' do
43
56
  expect(JSON.parse(ckan_sample.geoblacklight_terms[:dct_references_s])).not_to include('http://schema.org/url')
44
57
  end
45
58
  end
59
+
46
60
  context 'with no download resources' do
47
61
  let(:ckan_sample) do
48
- ckan = GeoCombine::CkanMetadata.new(ckan_metadata)
62
+ ckan = described_class.new(ckan_metadata)
49
63
  metadata = ckan.instance_variable_get('@metadata')
50
64
  metadata['resources'].delete_if { |resource| resource['resource_locator_function'] == 'download' }
51
65
  ckan
52
66
  end
67
+
53
68
  it 'has no downloadUrl in dct_references_s' do
54
- expect(ckan_sample.downloadable?).to be_falsey
69
+ expect(ckan_sample).not_to be_downloadable
55
70
  expect(JSON.parse(ckan_sample.geoblacklight_terms[:dct_references_s])).not_to include('http://schema.org/downloadUrl')
56
71
  end
57
72
  end
73
+
58
74
  context 'with a ZIP download' do
59
75
  let(:ckan_sample) do
60
- ckan = GeoCombine::CkanMetadata.new(ckan_metadata)
76
+ ckan = described_class.new(ckan_metadata)
61
77
  metadata = ckan.instance_variable_get('@metadata')
62
78
  metadata['resources'] = [
63
79
  {
@@ -68,43 +84,50 @@ RSpec.describe GeoCombine::CkanMetadata do
68
84
  ]
69
85
  ckan
70
86
  end
87
+
71
88
  it 'has a format and a download URL' do
72
- expect(ckan_sample.downloadable?).to be_truthy
89
+ expect(ckan_sample).to be_downloadable
73
90
  expect(ckan_sample.geoblacklight_terms).to include(dc_format_s: 'ZIP')
74
91
  expect(JSON.parse(ckan_sample.geoblacklight_terms[:dct_references_s])).to include('http://schema.org/downloadUrl' => 'https://example.com/layer.zip')
75
92
  end
76
93
  end
94
+
77
95
  context 'without any resources' do
78
96
  let(:ckan_sample) do
79
- ckan = GeoCombine::CkanMetadata.new(ckan_metadata)
97
+ ckan = described_class.new(ckan_metadata)
80
98
  metadata = ckan.instance_variable_get('@metadata')
81
99
  metadata.delete('resources')
82
100
  ckan
83
101
  end
102
+
84
103
  it 'has no urls in dct_references_s' do
85
- expect(ckan_sample.downloadable?).to be_falsey
104
+ expect(ckan_sample).not_to be_downloadable
86
105
  expect(JSON.parse(ckan_sample.geoblacklight_terms[:dct_references_s])).not_to include('http://schema.org/url')
87
106
  expect(JSON.parse(ckan_sample.geoblacklight_terms[:dct_references_s])).not_to include('http://schema.org/downloadUrl')
88
107
  end
89
108
  end
109
+
90
110
  context 'with very long descriptions' do
91
111
  let(:ckan_sample) do
92
- ckan = GeoCombine::CkanMetadata.new(ckan_metadata)
112
+ ckan = described_class.new(ckan_metadata)
93
113
  metadata = ckan.instance_variable_get('@metadata')
94
- metadata['notes'] = 'x' * 50000
114
+ metadata['notes'] = 'x' * 50_000
95
115
  ckan
96
116
  end
117
+
97
118
  it 'restricts the size' do
98
119
  expect(ckan_sample.geoblacklight_terms[:dc_description_s].length).to eq GeoCombine::CkanMetadata::MAX_STRING_LENGTH + 1
99
120
  end
100
121
  end
122
+
101
123
  context 'with no descriptions' do
102
124
  let(:ckan_sample) do
103
- ckan = GeoCombine::CkanMetadata.new(ckan_metadata)
125
+ ckan = described_class.new(ckan_metadata)
104
126
  metadata = ckan.instance_variable_get('@metadata')
105
127
  metadata['notes'] = nil
106
128
  ckan
107
129
  end
130
+
108
131
  it 'omits the description' do
109
132
  expect(ckan_sample.geoblacklight_terms).not_to include(:dc_description_s)
110
133
  end
@@ -1,83 +1,104 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GeoCombine::EsriOpenData do
4
6
  include JsonDocs
5
- let(:esri_sample) { GeoCombine::EsriOpenData.new(esri_opendata_metadata) }
7
+ let(:esri_sample) { described_class.new(esri_opendata_metadata) }
6
8
  let(:metadata) { esri_sample.instance_variable_get(:@metadata) }
9
+
7
10
  describe '#initialize' do
8
11
  it 'parses metadata argument JSON to Hash' do
9
12
  expect(esri_sample.instance_variable_get(:@metadata)).to be_an Hash
10
13
  end
14
+
11
15
  it 'puts extend data into @geometry' do
12
16
  expect(esri_sample.instance_variable_get(:@geometry)).to be_an Array
13
17
  end
14
18
  end
19
+
15
20
  describe '#to_geoblacklight' do
16
21
  it 'calls geoblacklight_terms to create a GeoBlacklight object' do
17
22
  expect(esri_sample).to receive(:geoblacklight_terms).and_return({})
18
23
  expect(esri_sample.to_geoblacklight).to be_an GeoCombine::Geoblacklight
19
24
  end
20
25
  end
26
+
21
27
  describe '#geoblacklight_terms' do
22
28
  describe 'builds a hash which maps metadata' do
23
29
  let(:metadata) { esri_sample.instance_variable_get(:@metadata) }
30
+
24
31
  it 'with dc_identifier_s' do
25
32
  expect(esri_sample.geoblacklight_terms).to include(dc_identifier_s: metadata['id'])
26
33
  end
34
+
27
35
  it 'with dc_title_s' do
28
36
  expect(esri_sample.geoblacklight_terms).to include(dc_title_s: metadata['name'])
29
37
  end
38
+
30
39
  it 'with dc_description_s sanitized' do
31
40
  expect(esri_sample).to receive(:sanitize_and_remove_lines).and_return 'sanitized'
32
41
  expect(esri_sample.geoblacklight_terms).to include(dc_description_s: 'sanitized')
33
42
  end
43
+
34
44
  it 'with dc_rights_s' do
35
45
  expect(esri_sample.geoblacklight_terms).to include(dc_rights_s: 'Public')
36
46
  end
47
+
37
48
  it 'with dct_provenance_s' do
38
49
  expect(esri_sample.geoblacklight_terms).to include(dct_provenance_s: metadata['owner'])
39
50
  end
51
+
40
52
  it 'with dct_references_s' do
41
53
  expect(esri_sample).to receive(:references).and_return ''
42
54
  expect(esri_sample.geoblacklight_terms).to include(:dct_references_s)
43
55
  end
56
+
44
57
  it 'with layer_id_s that is blank' do
45
58
  expect(esri_sample.geoblacklight_terms).to include(layer_id_s: '')
46
59
  end
60
+
47
61
  it 'with layer_geom_type_s' do
48
62
  expect(esri_sample.geoblacklight_terms).to include(layer_geom_type_s: metadata['geometry_type'])
49
63
  end
64
+
50
65
  it 'with layer_modified_dt' do
51
66
  expect(esri_sample.geoblacklight_terms).to include(layer_modified_dt: metadata['updated_at'])
52
67
  end
68
+
53
69
  it 'with layer_slug_s' do
54
70
  expect(esri_sample.geoblacklight_terms).to include(layer_slug_s: metadata['id'])
55
71
  end
72
+
56
73
  it 'with solr_geom' do
57
74
  expect(esri_sample).to receive(:envelope).and_return ''
58
75
  expect(esri_sample.geoblacklight_terms).to include(solr_geom: '')
59
76
  end
77
+
60
78
  it 'with dc_subject_sm' do
61
79
  expect(esri_sample.geoblacklight_terms).to include(dc_subject_sm: metadata['tags'])
62
80
  end
63
81
  end
64
82
  end
83
+
65
84
  describe '#references' do
66
85
  it 'converts references to a JSON string' do
67
86
  expect(esri_sample).to receive(:references_hash).and_return({})
68
87
  expect(esri_sample.references).to be_an String
69
88
  end
70
89
  end
90
+
71
91
  describe '#references_hash' do
72
92
  it 'builds out references' do
73
93
  expect(esri_sample.references_hash).to include('http://schema.org/url' => metadata['landing_page'])
74
94
  expect(esri_sample.references_hash).to include('http://resources.arcgis.com/en/help/arcgis-rest-api' => metadata['url'])
75
95
  end
76
96
  end
97
+
77
98
  describe '#envelope' do
78
99
  it 'creates an envelope for use in Solr' do
79
100
  expect(esri_sample.envelope).to be_an String
80
- expect(esri_sample.envelope).to match /ENVELOPE\(.+,.+,.+,.+\)/
101
+ expect(esri_sample.envelope).to match(/ENVELOPE\(.+,.+,.+,.+\)/)
81
102
  end
82
103
  end
83
104
  end
@@ -1,103 +1,134 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GeoCombine::Fgdc do
4
6
  include XmlDocs
5
- let(:fgdc_object){ GeoCombine::Fgdc.new(tufts_fgdc) }
7
+ let(:fgdc_object) { described_class.new(tufts_fgdc) }
8
+
6
9
  describe '#initialize' do
7
10
  it 'returns an instantiated Fgdc object' do
8
- expect(fgdc_object).to be_an GeoCombine::Fgdc
11
+ expect(fgdc_object).to be_an described_class
9
12
  end
10
13
  end
14
+
11
15
  describe '#xsl_geoblacklight' do
12
- it 'should be defined' do
16
+ it 'is defined' do
13
17
  expect(fgdc_object.xsl_geoblacklight).to be_an Nokogiri::XSLT::Stylesheet
14
18
  end
15
19
  end
16
- describe '#xsl_html'do
17
- it 'should be defined' do
20
+
21
+ describe '#xsl_html' do
22
+ it 'is defined' do
18
23
  expect(fgdc_object.xsl_html).to be_an Nokogiri::XSLT::Stylesheet
19
24
  end
20
25
  end
26
+
21
27
  describe '#to_geoblacklight' do
22
28
  let(:fgdc_geobl) { fgdc_object.to_geoblacklight }
29
+
23
30
  it 'returns a GeoCombine::Geoblacklight object' do
24
31
  expect(fgdc_geobl).to be_an GeoCombine::Geoblacklight
25
32
  end
33
+
26
34
  it 'is not valid due to bad modification date but valid otherwise' do
27
35
  expect { fgdc_geobl.valid? }.to raise_error(JSON::Schema::ValidationError, /layer_modified_dt/)
28
36
  fgdc_geobl.metadata.delete 'layer_modified_dt'
29
- expect(fgdc_geobl.valid?).to be_truthy
37
+ expect(fgdc_geobl).to be_valid
30
38
  end
39
+
31
40
  describe 'with GeoBlacklight-Schema fields' do
32
41
  it 'geoblacklight_version' do
33
42
  expect(fgdc_geobl.metadata['geoblacklight_version']).to eq '1.0'
34
43
  end
44
+
35
45
  it 'dc_identifier_s' do
36
46
  expect(fgdc_geobl.metadata['dc_identifier_s']).to eq 'http://www.geoportaligm.gob.ec/portal/'
37
47
  end
48
+
38
49
  it 'dc_title_s' do
39
50
  expect(fgdc_geobl.metadata['dc_title_s']).to eq 'Drilling Towers 50k Scale Ecuador 2011'
40
51
  end
52
+
41
53
  it 'dc_description_s' do
42
- expect(fgdc_geobl.metadata['dc_description_s']).to match /Ecuador created from/
54
+ expect(fgdc_geobl.metadata['dc_description_s']).to match(/Ecuador created from/)
43
55
  end
56
+
44
57
  it 'dc_rights_s' do
45
58
  expect(fgdc_geobl.metadata['dc_rights_s']).to eq 'Public'
46
59
  end
60
+
47
61
  it 'dct_provenance_s' do
48
62
  expect(fgdc_geobl.metadata['dct_provenance_s']).to eq 'Tufts'
49
63
  end
64
+
50
65
  it 'layer_id_s' do
51
66
  expect(fgdc_geobl.metadata['layer_id_s']).to eq 'urn:Ecuador50KDrillingTower11'
52
67
  end
68
+
53
69
  it 'layer_slug_s' do
54
70
  expect(fgdc_geobl.metadata['layer_slug_s']).to eq 'Tufts-Ecuador50KDrillingTower11'
55
71
  end
72
+
56
73
  it 'layer_modified_dt' do
57
74
  expect(fgdc_geobl.metadata['layer_modified_dt']).to eq '2013-08-13'
58
75
  end
76
+
59
77
  it 'dc_creator_sm' do
60
78
  expect(fgdc_geobl.metadata['dc_creator_sm']).to be_an Array
61
79
  expect(fgdc_geobl.metadata['dc_creator_sm']).to include 'Instituto Geografico Militar (Ecuador)'
62
80
  end
81
+
63
82
  it 'dc_format_s' do
64
83
  expect(fgdc_geobl.metadata['dc_format_s']).to eq 'Shapefile'
65
84
  end
85
+
66
86
  it 'dc_language_s' do
67
87
  expect(fgdc_geobl.metadata['dc_language_s']).to eq 'English'
68
88
  end
89
+
69
90
  it 'dc_type_s' do
70
91
  expect(fgdc_geobl.metadata['dc_type_s']).to eq 'Dataset'
71
92
  end
93
+
72
94
  it 'dc_subject_sm' do
73
95
  expect(fgdc_geobl.metadata['dc_subject_sm']).to be_an Array
74
- expect(fgdc_geobl.metadata['dc_subject_sm']).to include 'point', 'structure', 'economy', 'Drilling platforms', 'Oil well drilling'
96
+ expect(fgdc_geobl.metadata['dc_subject_sm']).to include 'point', 'structure', 'economy', 'Drilling platforms',
97
+ 'Oil well drilling'
75
98
  end
99
+
76
100
  it 'dc_spatial_sm' do
77
101
  expect(fgdc_geobl.metadata['dc_spatial_sm']).to be_an Array
78
- expect(fgdc_geobl.metadata['dc_spatial_sm']).to include 'Ecuador', 'República del Ecuador', 'Northern Hemisphere', 'Southern Hemisphere', 'Western Hemisphere', 'South America'
102
+ expect(fgdc_geobl.metadata['dc_spatial_sm']).to include 'Ecuador', 'República del Ecuador',
103
+ 'Northern Hemisphere', 'Southern Hemisphere', 'Western Hemisphere', 'South America'
79
104
  end
105
+
80
106
  it 'dct_issued_s' do
81
107
  expect(fgdc_geobl.metadata['dct_issued_s']).to eq '2011'
82
108
  end
109
+
83
110
  it 'dct_temporal_sm' do
84
111
  expect(fgdc_geobl.metadata['dct_temporal_sm']).to be_an Array
85
112
  expect(fgdc_geobl.metadata['dct_temporal_sm']).to include '2011'
86
113
  end
114
+
87
115
  it 'dct_isPartOf_sm' do
88
116
  expect(fgdc_geobl.metadata['dct_isPartOf_sm']).to be_an Array
89
117
  expect(fgdc_geobl.metadata['dct_isPartOf_sm']).to include 'Ecuador', 'Instituto Geografico Militar Data'
90
118
  end
119
+
91
120
  it 'solr_geom' do
92
121
  expect(fgdc_geobl.metadata['solr_geom']).to eq 'ENVELOPE(-79.904768, -79.904768, -1.377743, -1.377743)'
93
122
  end
123
+
94
124
  it 'solr_year_i' do
95
125
  expect(fgdc_geobl.metadata['solr_year_i']).to eq 2011
96
126
  end
97
127
  end
98
128
  end
129
+
99
130
  describe '#to_html' do
100
- it 'should create a transformation of the metadata as a String' do
131
+ it 'creates a transformation of the metadata as a String' do
101
132
  expect(fgdc_object.to_html).to be_an String
102
133
  end
103
134
  end
@@ -1,26 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GeoCombine::Formatting do
6
+ subject { Object.new.extend(described_class) }
7
+
4
8
  let(:dirty) { "<p>paragraph</p> \n on a new line" }
5
- subject { Object.new.extend(GeoCombine::Formatting) }
9
+
6
10
  describe '#sanitize' do
7
11
  it 'sanitizes a fragment' do
8
- expect(subject.sanitize(dirty)).to_not match('<p>')
12
+ expect(subject.sanitize(dirty)).not_to match('<p>')
9
13
  end
10
14
  end
15
+
11
16
  describe '#remove_lines' do
12
17
  it 'removes new lines' do
13
- expect(subject.remove_lines(dirty)).to_not match(/\n/)
18
+ expect(subject.remove_lines(dirty)).not_to match(/\n/)
14
19
  end
15
20
  end
21
+
16
22
  describe '#sanitize_and_remove_lines' do
17
23
  it 'returns a corrected string' do
18
- expect(subject.sanitize_and_remove_lines(dirty)).to_not match('<p>')
19
- expect(subject.sanitize_and_remove_lines(dirty)).to_not match(/\n/)
24
+ expect(subject.sanitize_and_remove_lines(dirty)).not_to match('<p>')
25
+ expect(subject.sanitize_and_remove_lines(dirty)).not_to match(/\n/)
20
26
  end
21
27
  end
28
+
22
29
  describe '#sluggify' do
23
30
  let(:preslug) { 'HARVARD...Co_0l' }
31
+
24
32
  it 'handles multiple . and _ and uppercase' do
25
33
  expect(subject.sluggify(preslug)).to eq 'harvard-co-0l'
26
34
  end
@@ -1,23 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'net/http'
3
4
  require 'spec_helper'
4
5
  require 'rsolr'
5
6
 
6
7
  RSpec.describe GeoCombine::GeoBlacklightHarvester do
8
+ subject(:harvester) { described_class.new(site_key) }
9
+
7
10
  let(:site_key) { :INSTITUTION }
8
11
  let(:stub_json_response) { '{}' }
9
12
  let(:stub_solr_connection) { double('RSolr::Connection') }
10
- subject(:harvester) { described_class.new(site_key) }
11
13
 
12
14
  before do
13
15
  allow(described_class).to receive(:config).and_return({
14
- INSTITUTION: {
15
- host: 'https://example.com/',
16
- params: {
17
- f: { dct_provenance_s: ['INSTITUTION'] }
18
- }
19
- }
20
- })
16
+ INSTITUTION: {
17
+ host: 'https://example.com/',
18
+ params: {
19
+ f: { dct_provenance_s: ['INSTITUTION'] }
20
+ }
21
+ }
22
+ })
21
23
  end
22
24
 
23
25
  describe 'initialization' do
@@ -49,15 +51,16 @@ RSpec.describe GeoCombine::GeoBlacklightHarvester do
49
51
  describe 'document tranformations' do
50
52
  let(:docs) do
51
53
  [
52
- { layer_slug_s: 'abc-123', _version_: '1', timestamp: '1999-12-31', score: 0.1 },
53
- { layer_slug_s: 'abc-321', dc_source_s: 'abc-123' }
54
+ { layer_slug_s: 'abc-123', _version_: '1', timestamp: '1999-12-31', score: 0.1,
55
+ solr_bboxtype__minX: -87.324704, solr_bboxtype__minY: 40.233691, solr_bboxtype__maxX: -87.174404, solr_bboxtype__maxY: 40.310695 },
56
+ { layer_slug_s: 'abc-321', dc_source_s: 'abc-123' }
54
57
  ]
55
58
  end
56
59
 
57
60
  context 'when a tranformer is set' do
58
61
  before do
59
62
  expect(described_class).to receive(:document_transformer).at_least(:once).and_return(
60
- ->(doc) {
63
+ lambda { |doc|
61
64
  doc.delete('_version_')
62
65
  doc
63
66
  }
@@ -68,7 +71,8 @@ RSpec.describe GeoCombine::GeoBlacklightHarvester do
68
71
  expect(stub_solr_connection).to receive(:update).with(
69
72
  hash_including(
70
73
  data: [
71
- { layer_slug_s: 'abc-123', timestamp: '1999-12-31', score: 0.1 },
74
+ { layer_slug_s: 'abc-123', timestamp: '1999-12-31', score: 0.1, solr_bboxtype__minX: -87.324704,
75
+ solr_bboxtype__minY: 40.233691, solr_bboxtype__maxX: -87.174404, solr_bboxtype__maxY: 40.310695 },
72
76
  { layer_slug_s: 'abc-321', dc_source_s: 'abc-123' }
73
77
  ].to_json
74
78
  )
@@ -79,7 +83,7 @@ RSpec.describe GeoCombine::GeoBlacklightHarvester do
79
83
  end
80
84
 
81
85
  context 'when no transformer is set' do
82
- it 'removes the _version_, timestamp, and score fields' do
86
+ it 'removes the _version_, timestamp, score, and solr_bboxtype__* fields' do
83
87
  expect(stub_solr_connection).to receive(:update).with(
84
88
  hash_including(
85
89
  data: [
@@ -125,7 +129,7 @@ RSpec.describe GeoCombine::GeoBlacklightHarvester do
125
129
  let(:first_docs) { [{ 'layer_slug_s' => 'abc-123' }, { 'layer_slug_s' => 'abc-321' }] }
126
130
  let(:second_docs) { [{ 'layer_slug_s' => 'xyz-123' }, { 'layer_slug_s' => 'xyz-321' }] }
127
131
  let(:stub_first_response) do
128
- { 'response' => { 'docs' => first_docs, 'pages' => { 'current_page' => 1, 'total_pages' => 2 } } }
132
+ { 'response' => { 'docs' => first_docs, 'pages' => { 'current_page' => 1, 'total_pages' => 2 } } }
129
133
  end
130
134
  let(:stub_second_response) do
131
135
  { 'response' => { 'docs' => second_docs, 'pages' => { 'current_page' => 2, 'total_pages' => 2 } } }
@@ -137,7 +141,8 @@ RSpec.describe GeoCombine::GeoBlacklightHarvester do
137
141
  URI('https://example.com?f%5Bdct_provenance_s%5D%5B%5D=INSTITUTION&format=json&per_page=100&page=2')
138
142
  ).and_return(stub_second_response.to_json)
139
143
  base_url = 'https://example.com?f%5Bdct_provenance_s%5D%5B%5D=INSTITUTION&format=json&per_page=100'
140
- docs = described_class::LegacyBlacklightResponse.new(response: stub_first_response, base_url: base_url).documents
144
+ docs = described_class::LegacyBlacklightResponse.new(response: stub_first_response,
145
+ base_url: base_url).documents
141
146
 
142
147
  expect(docs.to_a).to eq([first_docs, second_docs])
143
148
  end
@@ -154,19 +159,17 @@ RSpec.describe GeoCombine::GeoBlacklightHarvester do
154
159
 
155
160
  let(:first_results_response) do
156
161
  { 'data' => [
157
- { 'links' => { 'self' => 'https://example.com/catalog/abc-123' } },
158
- { 'links' => { 'self' => 'https://example.com/catalog/abc-321' } }
159
- ],
160
- 'links' => { 'next' => 'https://example.com/catalog.json?f%5Bdct_provenance_s%5D%5B%5D=INSTITUTION&per_page=100&page=2' }
161
- }
162
+ { 'links' => { 'self' => 'https://example.com/catalog/abc-123' } },
163
+ { 'links' => { 'self' => 'https://example.com/catalog/abc-321' } }
164
+ ],
165
+ 'links' => { 'next' => 'https://example.com/catalog.json?f%5Bdct_provenance_s%5D%5B%5D=INSTITUTION&per_page=100&page=2' } }
162
166
  end
163
167
 
164
168
  let(:second_results_response) do
165
169
  { 'data' => [
166
- { 'links' => { 'self' => 'https://example.com/catalog/xyz-123' } },
167
- { 'links' => { 'self' => 'https://example.com/catalog/xyz-321' } }
168
- ]
169
- }
170
+ { 'links' => { 'self' => 'https://example.com/catalog/xyz-123' } },
171
+ { 'links' => { 'self' => 'https://example.com/catalog/xyz-321' } }
172
+ ] }
170
173
  end
171
174
 
172
175
  describe '#documents' do
@@ -178,12 +181,13 @@ RSpec.describe GeoCombine::GeoBlacklightHarvester do
178
181
  end
179
182
 
180
183
  base_url = 'https://example.com?f%5Bdct_provenance_s%5D%5B%5D=INSTITUTION&format=json&per_page=100'
181
- docs = described_class::ModernBlacklightResponse.new(response: first_results_response, base_url: base_url).documents
184
+ docs = described_class::ModernBlacklightResponse.new(response: first_results_response,
185
+ base_url: base_url).documents
182
186
 
183
187
  expect(docs.to_a).to eq([
184
- [{ 'layer_slug_s' => 'abc-123' }, { 'layer_slug_s' => 'abc-321' }],
185
- [{ 'layer_slug_s' => 'xyz-123' }, { 'layer_slug_s' => 'xyz-321' }],
186
- ])
188
+ [{ 'layer_slug_s' => 'abc-123' }, { 'layer_slug_s' => 'abc-321' }],
189
+ [{ 'layer_slug_s' => 'xyz-123' }, { 'layer_slug_s' => 'xyz-321' }]
190
+ ])
187
191
  end
188
192
  end
189
193
  end