blacklight-maps 0.5.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +99 -0
  4. data/.solr_wrapper.yml +7 -0
  5. data/.travis.yml +19 -16
  6. data/Gemfile +40 -7
  7. data/README.md +13 -12
  8. data/Rakefile +35 -32
  9. data/app/assets/images/blacklight/maps.svg +1 -0
  10. data/app/assets/javascripts/blacklight-maps.js +1 -4
  11. data/app/assets/javascripts/blacklight-maps/blacklight-maps-browse.js +7 -8
  12. data/app/assets/stylesheets/blacklight_maps/blacklight-maps.scss +1 -2
  13. data/app/assets/stylesheets/blacklight_maps/default.scss +7 -10
  14. data/app/helpers/blacklight/blacklight_maps_helper_behavior.rb +81 -86
  15. data/app/helpers/blacklight_maps_helper.rb +2 -0
  16. data/app/views/catalog/_show_maplet_default.html.erb +8 -9
  17. data/app/views/catalog/map.html.erb +2 -2
  18. data/blacklight-maps.gemspec +27 -26
  19. data/config/locales/blacklight-maps-zh.yml +7 -7
  20. data/config/locales/blacklight-maps.ar.yml +21 -0
  21. data/config/locales/blacklight-maps.de.yml +21 -0
  22. data/config/locales/blacklight-maps.en.yml +1 -1
  23. data/config/locales/blacklight-maps.es.yml +21 -0
  24. data/config/locales/blacklight-maps.fr.yml +8 -8
  25. data/config/locales/blacklight-maps.hu.yml +21 -0
  26. data/config/locales/blacklight-maps.it.yml +8 -8
  27. data/config/locales/blacklight-maps.nl.yml +21 -0
  28. data/config/locales/blacklight-maps.pt-BR.yml +21 -0
  29. data/config/locales/blacklight-maps.sq.yml +21 -0
  30. data/config/routes.rb +3 -2
  31. data/lib/blacklight/maps.rb +8 -2
  32. data/lib/blacklight/maps/controller.rb +27 -0
  33. data/lib/blacklight/maps/engine.rb +12 -13
  34. data/lib/blacklight/maps/export.rb +112 -93
  35. data/lib/blacklight/maps/geometry.rb +30 -18
  36. data/lib/blacklight/maps/maps_search_builder.rb +4 -3
  37. data/lib/blacklight/maps/render_constraints_override.rb +63 -29
  38. data/lib/blacklight/maps/version.rb +3 -1
  39. data/lib/generators/blacklight_maps/install_generator.rb +38 -31
  40. data/lib/generators/blacklight_maps/templates/search_history_controller.rb +2 -0
  41. data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/schema.xml +0 -0
  42. data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/solrconfig.xml +0 -0
  43. data/lib/railties/blacklight_maps.rake +10 -7
  44. data/spec/controllers/catalog_controller_spec.rb +20 -10
  45. data/spec/fixtures/sample_solr_documents.yml +909 -906
  46. data/spec/helpers/blacklight_maps_helper_spec.rb +60 -108
  47. data/spec/lib/blacklight/maps/export_spec.rb +109 -143
  48. data/spec/lib/blacklight/maps/geometry_spec.rb +34 -21
  49. data/spec/lib/blacklight/maps/maps_search_builder_spec.rb +17 -21
  50. data/spec/lib/blacklight/maps/render_constraints_override_spec.rb +42 -69
  51. data/spec/spec_helper.rb +19 -21
  52. data/spec/system/index_view_spec.rb +127 -0
  53. data/spec/system/initial_view_spec.rb +28 -0
  54. data/spec/system/map_view_spec.rb +50 -0
  55. data/spec/system/show_view_maplet_spec.rb +78 -0
  56. data/spec/test_app_templates/lib/generators/test_app_generator.rb +6 -21
  57. data/vendor/assets/images/layers-2x.png +0 -0
  58. data/vendor/assets/images/layers.png +0 -0
  59. data/vendor/assets/images/marker-icon-2x.png +0 -0
  60. data/vendor/assets/images/marker-icon.png +0 -0
  61. data/vendor/assets/images/marker-shadow.png +0 -0
  62. data/vendor/assets/javascripts/leaflet.js.erb +13922 -0
  63. data/vendor/assets/javascripts/leaflet.markercluster.js +3 -0
  64. data/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
  65. data/vendor/assets/stylesheets/MarkerCluster.css +14 -0
  66. data/vendor/assets/stylesheets/leaflet.css +635 -0
  67. metadata +86 -91
  68. data/config/jetty.yml +0 -7
  69. data/lib/blacklight/maps/controller_override.rb +0 -20
  70. data/lib/generators/blacklight_maps/templates/saved_searches_controller.rb +0 -5
  71. data/spec/features/initial_view_spec.rb +0 -21
  72. data/spec/features/maps_spec.rb +0 -202
  73. data/spec/features/show_view_maplet_spec.rb +0 -93
  74. data/spec/test_app_templates/Gemfile.extra +0 -5
@@ -1,170 +1,122 @@
1
- # -*- encoding : utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe BlacklightMapsHelper do
5
-
6
+ let(:query_term) { 'Tibet' }
7
+ let(:mock_controller) { CatalogController.new }
6
8
  let(:blacklight_config) { Blacklight::Configuration.new }
7
- let(:search_state) { Blacklight::SearchState.new({}, blacklight_config) }
8
-
9
- def create_response
10
- raw_response = eval(mock_query_response)
11
- Blacklight::Solr::Response.new(raw_response, raw_response['params'])
9
+ let(:maps_config) { blacklight_config.view.maps }
10
+ let(:search_service) do
11
+ Blacklight::SearchService.new(config: blacklight_config, user_params: { q: query_term })
12
12
  end
13
-
14
- let(:r) { create_response }
15
- let(:geojson_hash) { { type: 'Feature', geometry: { type: 'Point', coordinates: [91.117212, 29.646923] }, properties: { placename: 'Tibet' } } }
13
+ let(:response) { search_service.search_results[0] }
14
+ let(:docs) { response.aggregations[maps_config.geojson_field].items }
16
15
  let(:coords) { [91.117212, 29.646923] }
16
+ let(:geojson_hash) do
17
+ { type: 'Feature', geometry: { type: 'Point', coordinates: coords }, properties: { placename: query_term } }
18
+ end
17
19
  let(:bbox) { [78.3955448, 26.8548157, 99.116241, 36.4833345] }
18
20
 
19
- before :each do
21
+ before do
22
+ mock_controller.request = ActionDispatch::TestRequest.create
23
+ allow(helper).to receive_messages(controller: mock_controller, action_name: 'index')
20
24
  allow(helper).to receive_messages(blacklight_config: blacklight_config)
21
- CatalogController.blacklight_config = Blacklight::Configuration.new
22
- @request = ActionDispatch::TestRequest.new
23
- @catalog = CatalogController.new
24
- allow(helper).to receive_messages(blacklight_configuration_context: Blacklight::Configuration::Context.new(@catalog))
25
- allow(helper).to receive(:search_state).and_return(search_state)
26
- @catalog.request = @request
27
- @catalog.action_name = "index"
28
- helper.instance_variable_set(:@_controller, @catalog)
29
- @docs = r.aggregations[blacklight_config.view.maps.geojson_field].items
25
+ allow(helper).to receive_messages(blacklight_configuration_context: Blacklight::Configuration::Context.new(mock_controller))
26
+ allow(helper).to receive(:search_state).and_return Blacklight::SearchState.new({}, blacklight_config, mock_controller)
27
+ blacklight_config.add_facet_field 'geojson_ssim', limit: -2, label: 'GeoJSON', show: false
28
+ blacklight_config.add_facet_fields_to_solr_request!
30
29
  end
31
30
 
32
- describe "blacklight_map_tag" do
33
-
34
- context "with default values" do
31
+ describe 'blacklight_map_tag' do
32
+ context 'with default values' do
35
33
  subject { helper.blacklight_map_tag('blacklight-map') }
36
- it { should have_selector "div#blacklight-map" }
37
- it { should have_selector "div[data-maxzoom='#{blacklight_config.view.maps.maxzoom}']" }
38
- it { should have_selector "div[data-tileurl='#{blacklight_config.view.maps.tileurl}']" }
39
- it { should have_selector "div[data-mapattribution='#{blacklight_config.view.maps.mapattribution}']" }
34
+
35
+ it { is_expected.to have_selector 'div#blacklight-map' }
36
+ it { is_expected.to have_selector "div[data-maxzoom='#{maps_config.maxzoom}']" }
37
+ it { is_expected.to have_selector "div[data-tileurl='#{maps_config.tileurl}']" }
38
+ it { is_expected.to have_selector "div[data-mapattribution='#{maps_config.mapattribution}']" }
40
39
  end
41
40
 
42
- context "with custom values" do
43
- subject { helper.blacklight_map_tag('blacklight-map', data: {maxzoom: 6, tileurl: 'http://example.com/', mapattribution: 'hello world' }) }
44
- it { should have_selector "div[data-maxzoom='6'][data-tileurl='http://example.com/'][data-mapattribution='hello world']" }
41
+ context 'with custom values' do
42
+ subject { helper.blacklight_map_tag('blacklight-map', data: { maxzoom: 6, tileurl: 'http://example.com/', mapattribution: 'hello world' }) }
43
+
44
+ it { is_expected.to have_selector "div[data-maxzoom='6'][data-tileurl='http://example.com/'][data-mapattribution='hello world']" }
45
45
  end
46
46
 
47
- context "when a block is provided" do
47
+ context 'when a block is provided' do
48
48
  subject { helper.blacklight_map_tag('foo') { content_tag(:span, 'bar') } }
49
- it { should have_selector('div > span', text: 'bar') }
50
- end
51
49
 
50
+ it { is_expected.to have_selector('div > span', text: 'bar') }
51
+ end
52
52
  end
53
53
 
54
- describe "serialize_geojson" do
55
-
56
- it "should return geojson of documents" do
57
- expect(helper.serialize_geojson(@docs)).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
54
+ describe 'serialize_geojson' do
55
+ it 'returns geojson of documents' do
56
+ expect(helper.serialize_geojson(docs)).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
58
57
  end
59
-
60
58
  end
61
59
 
62
- describe "placename_value" do
63
-
64
- it "should return the placename value" do
65
- expect(helper.placename_value(geojson_hash)).to eq('Tibet')
60
+ describe 'placename_value' do
61
+ it 'returns the placename value' do
62
+ expect(helper.placename_value(geojson_hash)).to eq(query_term)
66
63
  end
67
-
68
64
  end
69
65
 
70
- describe "link_to_bbox_search" do
71
-
72
- it "should create a spatial search link" do
66
+ describe 'link_to_bbox_search' do
67
+ it 'creates a spatial search link' do
73
68
  expect(helper.link_to_bbox_search(bbox)).to include('catalog?coordinates')
74
69
  expect(helper.link_to_bbox_search(bbox)).to include('spatial_search_type=bbox')
75
70
  end
76
71
 
77
- it "should include the default_document_index_view_type in the params" do
72
+ it 'includes the default_document_index_view_type in the params' do
78
73
  expect(helper.link_to_bbox_search(bbox)).to include('view=list')
79
74
  end
80
-
81
75
  end
82
76
 
83
- describe "link_to_placename_field" do
77
+ describe 'link_to_placename_field' do
78
+ subject { helper.link_to_placename_field(query_term, maps_config.placename_field) }
84
79
 
85
- it "should create a link to the placename field" do
86
- expect(helper.link_to_placename_field('Tibet', blacklight_config.view.maps.placename_field)).to include("catalog?f%5B#{blacklight_config.view.maps.placename_field}%5D%5B%5D=Tibet")
87
- end
80
+ it { is_expected.to include("catalog?f%5B#{maps_config.placename_field}%5D%5B%5D=Tibet") }
81
+ it { is_expected.to include('view=list') }
88
82
 
89
- it "should create a link to the placename field using the display value" do
90
- expect(helper.link_to_placename_field('Tibet', blacklight_config.view.maps.placename_field, 'foo')).to include('">foo</a>')
83
+ it 'creates a link to the placename field using the display value' do
84
+ expect(helper.link_to_placename_field(query_term, maps_config.placename_field, 'foo')).to include('">foo</a>')
91
85
  end
92
-
93
- it "should include the default_document_index_view_type in the params" do
94
- expect(helper.link_to_placename_field('Tibet', blacklight_config.view.maps.placename_field)).to include('view=list')
95
- end
96
-
97
86
  end
98
87
 
99
- describe "link_to_point_search" do
100
-
101
- it "should create a link to a coordinate point" do
88
+ describe 'link_to_point_search' do
89
+ it 'creates a link to a coordinate point' do
102
90
  expect(helper.link_to_point_search(coords)).to include('catalog?coordinates')
103
91
  expect(helper.link_to_point_search(coords)).to include('spatial_search_type=point')
104
92
  end
105
93
 
106
- it "should include the default_document_index_view_type in the params" do
94
+ it 'includes the default_document_index_view_type in the params' do
107
95
  expect(helper.link_to_point_search(coords)).to include('view=list')
108
96
  end
109
-
110
- end
111
-
112
- describe "map_facet_field" do
113
-
114
- it "should return the correct facet field" do
115
- expect(helper.map_facet_field).to eq(blacklight_config.view.maps.geojson_field)
116
- end
117
-
118
- end
119
-
120
- describe "map_facet_values" do
121
-
122
- before do
123
- @response = r
124
- end
125
-
126
- it "should return an array of Blacklight::Solr::Response::Facets::FacetItem items" do
127
- expect(helper.map_facet_values.class).to eq(Array)
128
- expect(helper.map_facet_values.first.class).to eq(Blacklight::Solr::Response::Facets::FacetItem)
129
- expect(helper.map_facet_values.length).to eq(5)
130
- end
131
-
132
97
  end
133
98
 
134
- describe "render_placename_heading" do
135
-
136
- it "should return the placename heading" do
137
- expect(helper.render_placename_heading(geojson_hash)).to eq('Tibet')
99
+ describe 'render_placename_heading' do
100
+ it 'returns the placename heading' do
101
+ expect(helper.render_placename_heading(geojson_hash)).to eq(query_term)
138
102
  end
139
-
140
103
  end
141
104
 
142
- describe "render_index_mapview" do
105
+ describe 'render_index_mapview' do
106
+ before { helper.instance_variable_set(:@response, response) }
143
107
 
144
- before do
145
- @response = r
146
- end
147
-
148
- it "should render the 'catalog/index_mapview' partial" do
108
+ it 'renders the "catalog/index_mapview" partial' do
149
109
  expect(helper.render_index_mapview).to include("$('#blacklight-index-map').blacklight_leaflet_map")
150
110
  end
151
-
152
111
  end
153
112
 
154
- describe "render_spatial_search_link" do
155
-
156
- it "should return link_to_bbox_search if bbox coordinates are passed" do
113
+ describe 'render_spatial_search_link' do
114
+ it 'returns link_to_bbox_search if bbox coordinates are passed' do
157
115
  expect(helper.render_spatial_search_link(bbox)).to include('spatial_search_type=bbox')
158
116
  end
159
117
 
160
- it "should return link_to_point_search if point coordinates are passed" do
118
+ it 'returns link_to_point_search if point coordinates are passed' do
161
119
  expect(helper.render_spatial_search_link(coords)).to include('spatial_search_type=point')
162
120
  end
163
-
164
121
  end
165
-
166
- def mock_query_response
167
- %({"responseHeader"=>{"status"=>0, "QTime"=>14, "params"=>{"q"=>"tibet", "spellcheck.q"=>"tibet", "qt"=>"search", "wt"=>"ruby", "rows"=>"10"}}, "response"=>{"numFound"=>2, "start"=>0, "maxScore"=>0.016135123, "docs"=>[{"published_display"=>["Dharamsala, H.P."], "author_display"=>"Thub-bstan-yar-ʼphel, Rnam-grwa", "lc_callnum_display"=>["DS785 .T475 2005"], "pub_date"=>["2005"], "format"=>"Book", "material_type_display"=>["a-e, iv, ii, 407 p."], "title_display"=>"Bod gaṅs can gyi rgyal rabs mdor bsdus dris lan brgya pa rab gsal śel gyi me loṅ źes bya ba bźugs so", "id"=>"2008308202", "subject_geo_facet"=>["Tibet"], "language_facet"=>["Tibetan"], "geojson"=>["{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[91.117212, 29.646923]},\\"properties\\":{\\"placename\\":\\"Tibet\\"}}", "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[78.3955448, 26.8548157], [99.116241, 26.8548157], [99.116241, 36.4833345], [78.3955448, 36.4833345], [78.3955448, 26.8548157]]]},\\"bbox\\":[78.3955448,26.8548157,99.116241,36.4833345]}"], "coordinates"=>["91.117212 29.646923", "78.3955448 26.8548157 99.116241 36.4833345"], "score"=>0.016135123}, {"published_display"=>["Dharamsala, Distt. Kangra, H.P."], "pub_date"=>["2007"], "format"=>"Book", "title_display"=>"Ses yon", "material_type_display"=>["xii, 419 p."], "id"=>"2008308478", "subject_geo_facet"=>["China", "Tibet", "India"], "subject_topic_facet"=>["Education and state", "Tibetans", "Tibetan language", "Teaching"], "language_facet"=>["Tibetan"], "geojson"=>["{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[104.195397,35.86166]},\\"properties\\":{\\"placename\\":\\"China\\"}}", "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[91.117212,29.646923]},\\"properties\\":{\\"placename\\":\\"Tibet\\"}}", "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[78.96288,20.593684]},\\"properties\\":{\\"placename\\":\\"India\\"}}","{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},\\"bbox\\":[68.162386,6.7535159,97.395555,35.5044752]}"], "coordinates"=>["68.162386 6.7535159 97.395555 35.5044752", "104.195397 35.86166", "91.117212 29.646923", "78.96288 20.593684"], "score"=>0.0026767207}]}, "facet_counts"=>{"facet_queries"=>{}, "facet_fields"=>{"format"=>["Book", 2], "lc_1letter_facet"=>["D - World History", 1], "lc_alpha_facet"=>["DS", 1], "lc_b4cutter_facet"=>["DS785", 1], "language_facet"=>["Tibetan", 2], "pub_date"=>["2005", 1, "2007", 1], "subject_era_facet"=>[], "subject_geo_facet"=>["China", 1, "India", 1, "Tibet", 1, "Tibet (China)", 1], "coordinates"=>["91.117212 29.646923", 2, "78.3955448 26.8548157 99.116241 36.4833345", 1, "68.162386 6.7535159 97.395555 35.5044752", 1, "104.195397 35.86166", 1, "78.96288 20.593684", 1], "geojson"=>["{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[91.117212, 29.646923]},\\"properties\\":{\\"placename\\":\\"Tibet\\"}}", 2, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[78.3955448, 26.8548157], [99.116241, 26.8548157], [99.116241, 36.4833345], [78.3955448, 36.4833345], [78.3955448, 26.8548157]]]},\\"bbox\\":[78.3955448,26.8548157,99.116241,36.4833345]}", 1, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[104.195397,35.86166]},\\"properties\\":{\\"placename\\":\\"China\\"}}", 1, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Point\\",\\"coordinates\\":[78.96288,20.593684]},\\"properties\\":{\\"placename\\":\\"India\\"}}", 1, "{\\"type\\":\\"Feature\\",\\"geometry\\":{\\"type\\":\\"Polygon\\",\\"coordinates\\":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},\\"bbox\\":[68.162386,6.7535159,97.395555,35.5044752]}", 1], "subject_topic_facet"=>["Education and state", 1, "Teaching", 1, "Tibetan language", 1, "Tibetans", 1]}, "facet_dates"=>{}, "facet_ranges"=>{}}, "spellcheck"=>{"suggestions"=>["tibet", {"numFound"=>1, "startOffset"=>0, "endOffset"=>5, "origFreq"=>2, "suggestion"=>[{"word"=>"tibetan", "freq"=>6}]}, "correctlySpelled", true]}})
168
- end
169
-
170
122
  end
@@ -1,228 +1,194 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe "BlacklightMaps::GeojsonExport" do
3
+ require 'spec_helper'
4
4
 
5
- before do
6
- CatalogController.blacklight_config = Blacklight::Configuration.new
7
- @controller = CatalogController.new
8
- @action = "index"
9
- @request = ActionDispatch::TestRequest.new
10
- @controller.request = @request
11
- @response = ActionDispatch::TestResponse.new
12
- expect(@response).to receive(:docs).and_return([{ "published_display"=>["Dharamsala, Distt. Kangra, H.P."], "pub_date"=>["2007"], "format"=>"Book", "title_display"=>"Ses yon", "material_type_display"=>["xii, 419 p."], "id"=>"2008308478", "placename_field"=>["China", "Tibet", "India"], "subject_topic_facet"=>["Education and state", "Tibetans", "Tibetan language", "Teaching"], "language_facet"=>["Tibetan"], "geojson"=>["{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[104.195397,35.86166]},\"properties\":{\"placename\":\"China\"}}", "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[91.117212,29.646923]},\"properties\":{\"placename\":\"Tibet\"}}", "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[78.96288,20.593684]},\"properties\":{\"placename\":\"India\"}}"], "coordinates"=>["68.162386 6.7535159 97.395555 35.5044752", "104.195397 35.86166", "91.117212 29.646923", "20.593684,78.96288"], "score"=>0.0026767207 }])
5
+ describe BlacklightMaps::GeojsonExport do
6
+ let(:controller) { CatalogController.new }
7
+ let(:action) { :index }
8
+ let(:response_docs) do
9
+ YAML.safe_load(File.open(File.join(fixture_path, 'sample_solr_documents.yml')))
13
10
  end
11
+ let(:export) { described_class.new(controller, action, response_docs, foo: 'bar') }
14
12
 
15
- # TODO: use @response.facet_by_field_name('geojson').items instead of @response
16
- # then refactor build_geojson_features and to_geojson specs
17
- subject {BlacklightMaps::GeojsonExport.new(@controller, @action, @response.docs, {foo:'bar'})}
13
+ before { controller.request = ActionDispatch::TestRequest.create }
18
14
 
19
- it "should instantiate GeojsonExport" do
20
- expect(subject.class).to eq(::BlacklightMaps::GeojsonExport)
15
+ it 'instantiates a GeojsonExport instance' do
16
+ expect(export.class).to eq(::BlacklightMaps::GeojsonExport)
21
17
  end
22
18
 
23
- describe "return config settings" do
24
-
25
- it "should return maps config" do
26
- expect(subject.send(:blacklight_maps_config).class).to eq(::Blacklight::Configuration::ViewConfig)
27
- end
28
-
29
- it "should return geojson_field" do
30
- expect(subject.send(:geojson_field)).to eq('geojson')
31
- end
32
-
33
- it "should return coordinates_field" do
34
- expect(subject.send(:coordinates_field)).to eq('coordinates')
35
- end
36
-
37
- it "should return search_mode" do
38
- expect(subject.send(:search_mode)).to eq('placename')
19
+ describe 'return config settings' do
20
+ it 'returns maps config' do
21
+ expect(export.send(:maps_config).class).to eq(::Blacklight::Configuration::ViewConfig)
39
22
  end
40
23
 
41
- it "should return facet_mode" do
42
- expect(subject.send(:facet_mode)).to eq('geojson')
24
+ it 'returns geojson_field' do
25
+ expect(export.send(:geojson_field)).to eq('geojson_ssim')
43
26
  end
44
27
 
45
- it "should return placename_property" do
46
- expect(subject.send(:placename_property)).to eq('placename')
28
+ it 'returns coordinates_field' do
29
+ expect(export.send(:coordinates_field)).to eq('coordinates_srpt')
47
30
  end
48
31
 
49
- it "should create an @options instance variable" do
50
- expect(subject.instance_variable_get("@options")[:foo]).to eq('bar')
32
+ it 'creates an @options instance variable' do
33
+ expect(export.instance_variable_get('@options')[:foo]).to eq('bar')
51
34
  end
52
-
53
35
  end
54
36
 
55
- describe "build_feature_from_geojson" do
56
-
57
- describe "point feature" do
58
-
59
- before do
60
- @output = subject.send(:build_feature_from_geojson, '{"type":"Feature","geometry":{"type":"Point","coordinates":[104.195397,35.86166]},"properties":{"placename":"China"}}', 1)
61
- end
37
+ describe 'build_feature_from_geojson' do
38
+ describe 'point feature' do
39
+ let(:geojson) { '{"type":"Feature","geometry":{"type":"Point","coordinates":[104.195397,35.86166]},"properties":{"placename":"China"}}' }
40
+ let(:point_feature) { export.send(:build_feature_from_geojson, geojson, 1) }
62
41
 
63
- it "should have a hits property with the right value" do
64
- expect(@output[:properties]).to have_key(:hits)
65
- expect(@output[:properties][:hits]).to eq(1)
42
+ it 'has a hits property with the right value' do
43
+ expect(point_feature[:properties][:hits]).to eq(1)
66
44
  end
67
45
 
68
- it "should have a popup property" do
69
- expect(@output[:properties]).to have_key(:popup)
46
+ it 'has a popup property' do
47
+ expect(point_feature[:properties]).to have_key(:popup)
70
48
  end
71
-
72
49
  end
73
50
 
74
- describe "bbox feature" do
75
-
76
- describe "catalog#index view" do
77
-
78
- before do
79
- @output = subject.send(:build_feature_from_geojson, '{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},"bbox":[68.162386, 6.7535159, 97.395555, 35.5044752]}', 1)
80
- end
51
+ describe 'bbox feature' do
52
+ describe 'catalog#index view' do
53
+ let(:geojson) { '{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]},"bbox":[68.162386, 6.7535159, 97.395555, 35.5044752]}' }
54
+ let(:bbox_feature) { export.send(:build_feature_from_geojson, geojson, 1) }
81
55
 
82
- it "should set the center point as the coordinates" do
83
- expect(@output[:geometry][:coordinates]).to eq([82.7789705, 21.12899555])
56
+ it 'sets the center point as the coordinates' do
57
+ expect(bbox_feature[:geometry][:coordinates]).to eq([82.7789705, 21.12899555])
84
58
  end
85
59
 
86
- it "should change the geometry type to 'Point'" do
87
- expect(@output[:geometry][:type]).to eq("Point")
88
- expect(@output[:bbox]).to be_nil
60
+ it "changes the geometry type to 'Point'" do
61
+ expect(bbox_feature[:geometry][:type]).to eq('Point')
62
+ expect(bbox_feature[:bbox]).to be_nil
89
63
  end
90
-
91
64
  end
92
-
93
65
  end
94
-
95
66
  end
96
67
 
97
- describe "build_feature_from_coords" do
98
-
99
- describe "point feature" do
100
-
101
- before do
102
- @output = subject.send(:build_feature_from_coords, '35.86166,104.195397', 1)
103
- end
68
+ describe 'build_feature_from_coords' do
69
+ describe 'point feature' do
70
+ let(:point_feature) { export.send(:build_feature_from_coords, '35.86166,104.195397', 1) }
104
71
 
105
- it "should create a GeoJSON feature hash" do
106
- expect(@output.class).to eq(Hash)
107
- expect(@output[:type]).to eq("Feature")
72
+ it 'creates a GeoJSON feature hash' do
73
+ expect(point_feature.class).to eq(Hash)
74
+ expect(point_feature[:type]).to eq('Feature')
108
75
  end
109
76
 
110
- it "should have the right coordinates" do
111
- expect(@output[:geometry][:coordinates]).to eq([104.195397, 35.86166])
77
+ it 'has the right coordinates' do
78
+ expect(point_feature[:geometry][:coordinates]).to eq([104.195397, 35.86166])
112
79
  end
113
80
 
114
- it "should have a hits property with the right value" do
115
- expect(@output[:properties]).to have_key(:hits)
116
- expect(@output[:properties][:hits]).to eq(1)
81
+ it 'has a hits property with the right value' do
82
+ expect(point_feature[:properties][:hits]).to eq(1)
117
83
  end
118
84
 
119
- it "should have a popup property" do
120
- expect(@output[:properties]).to have_key(:popup)
85
+ it 'has a popup property' do
86
+ expect(point_feature[:properties]).to have_key(:popup)
121
87
  end
122
-
123
88
  end
124
89
 
125
- describe "bbox feature" do
126
-
127
- describe "catalog#index view" do
90
+ describe 'bbox feature' do
91
+ let(:basic_bbox) { 'ENVELOPE(68.162386, 97.395555, 35.5044752, 6.7535159)' }
128
92
 
129
- before do
130
- @output = subject.send(:build_feature_from_coords, '68.162386 6.7535159 97.395555 35.5044752', 1)
131
- end
93
+ describe 'catalog#index view' do
94
+ let(:bbox_feature) { export.send(:build_feature_from_coords, basic_bbox, 1) }
132
95
 
133
- it "should set the center point as the coordinates" do
134
- expect(@output[:geometry][:type]).to eq("Point")
135
- expect(@output[:geometry][:coordinates]).to eq([82.7789705, 21.12899555])
96
+ it 'sets the center point as the coordinates' do
97
+ expect(bbox_feature[:geometry][:type]).to eq('Point')
98
+ expect(bbox_feature[:geometry][:coordinates]).to eq([82.7789705, 21.12899555])
136
99
  end
137
100
 
138
- describe "bounding box that crosses the dateline" do
139
-
140
- before do
141
- @output = subject.send(:build_feature_from_coords, '1.162386 6.7535159 -179.395555 35.5044752', 1)
101
+ describe 'bounding box that crosses the dateline' do
102
+ let(:bbox_feature) do
103
+ export.send(:build_feature_from_coords,
104
+ 'ENVELOPE(1.162386, -179.395555, 35.5044752, 6.7535159)', 1)
142
105
  end
143
106
 
144
- it "should set a center point with a long value between -180 and 180" do
145
- expect(@output[:geometry][:coordinates]).to eq([90.88341550000001,21.12899555])
107
+ it 'sets a center point with a long value between -180 and 180' do
108
+ expect(bbox_feature[:geometry][:coordinates]).to eq([90.88341550000001, 21.12899555])
146
109
  end
147
-
148
110
  end
149
-
150
111
  end
151
112
 
152
- describe "catalog#show view" do
153
-
154
- before do
155
- @action = "show"
156
- @output = subject.send(:build_feature_from_coords, '68.162386 6.7535159 97.395555 35.5044752', 1)
157
- end
113
+ describe 'catalog#show view' do
114
+ let(:action) { :show }
115
+ let(:show_feature) { export.send(:build_feature_from_coords, basic_bbox, 1) }
158
116
 
159
- it "should convert the bbox string to a polygon coordinate array" do
160
- expect(@output[:geometry][:type]).to eq("Polygon")
161
- expect(@output[:geometry][:coordinates]).to eq([[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]])
117
+ it 'converts the bbox string to a polygon coordinate array' do
118
+ expect(show_feature[:geometry][:type]).to eq('Polygon')
119
+ expect(show_feature[:geometry][:coordinates]).to eq(
120
+ [[[68.162386, 6.7535159], [97.395555, 6.7535159], [97.395555, 35.5044752], [68.162386, 35.5044752], [68.162386, 6.7535159]]]
121
+ )
162
122
  end
163
123
 
164
- it "should set the bbox member" do
165
- expect(@output[:bbox]).to eq([68.162386, 6.7535159, 97.395555, 35.5044752])
124
+ it 'sets the bbox member' do
125
+ expect(show_feature[:bbox]).to eq([68.162386, 6.7535159, 97.395555, 35.5044752])
166
126
  end
167
-
168
127
  end
169
-
170
128
  end
171
-
172
129
  end
173
130
 
174
- describe "render_leaflet_popup_content" do
175
-
176
- describe "placename_facet search_mode" do
177
-
178
- it "should render the map_placename_search partial if the placename is present" do
179
- expect(subject.send(:render_leaflet_popup_content, {type:"Feature",geometry:{type:"Point",coordinates:[104.195397,35.86166]},properties:{placename:"China", hits:1}})).to include('href="/catalog?f%5Bplacename_field%5D%5B%5D=China')
131
+ describe 'render_leaflet_popup_content' do
132
+ describe 'placename_facet search_mode' do
133
+ let(:placename_popup) do
134
+ export.send(:render_leaflet_popup_content,
135
+ { type: 'Feature',
136
+ geometry: { type: 'Point', coordinates: [104.195397, 35.86166] },
137
+ properties: { placename: 'China', hits: 1 } })
138
+ end
139
+ let(:spatial_popup) do
140
+ export.send(:render_leaflet_popup_content,
141
+ { type: 'Feature',
142
+ geometry: { type: 'Point', coordinates: [104.195397, 35.86166] },
143
+ properties: { hits: 1 } })
180
144
  end
181
145
 
182
- it "should render the map_spatial_search partial if the placename is not present" do
183
- expect(subject.send(:render_leaflet_popup_content, {type:"Feature",geometry:{type:"Point",coordinates:[104.195397,35.86166]},properties:{hits:1}})).to include('href="/catalog?coordinates=35.86166%2C104.195397&amp;spatial_search_type=point')
146
+ it 'renders the map_placename_search partial if the placename is present' do
147
+ expect(placename_popup).to include('href="/catalog?f%5Bsubject_geo_ssim%5D%5B%5D=China')
184
148
  end
185
149
 
150
+ it 'renders the map_spatial_search partial if the placename is not present' do
151
+ expect(spatial_popup).to include('href="/catalog?coordinates=35.86166%2C104.195397&amp;spatial_search_type=point')
152
+ end
186
153
  end
187
154
 
188
- describe "coordinates search_mode" do
189
-
155
+ describe 'coordinates search_mode' do
190
156
  before do
191
157
  CatalogController.configure_blacklight do |config|
192
158
  config.view.maps.search_mode = 'coordinates'
193
159
  end
194
160
  end
195
161
 
196
- it "should render the map_spatial_search partial" do
197
- expect(subject.send(:render_leaflet_popup_content, {type:"Feature",geometry:{type:"Point",coordinates:[104.195397,35.86166]},properties:{hits:1}})).to include('href="/catalog?coordinates=35.86166%2C104.195397&amp;spatial_search_type=point')
162
+ let(:spatial_popup) do
163
+ export.send(:render_leaflet_popup_content,
164
+ { type: 'Feature',
165
+ geometry: { type: 'Point', coordinates: [104.195397, 35.86166] },
166
+ properties: { hits: 1 } })
198
167
  end
199
168
 
169
+ it 'renders the map_spatial_search partial' do
170
+ expect(spatial_popup).to include('href="/catalog?coordinates=35.86166%2C104.195397&amp;spatial_search_type=point')
171
+ end
200
172
  end
201
-
202
173
  end
203
174
 
204
- describe "build_geojson_features" do
205
-
206
- before do
207
- @action = "show"
175
+ describe 'build_geojson_features' do
176
+ let(:geojson_features) do
177
+ described_class.new(controller, :show, response_docs.first).send(:build_geojson_features)
208
178
  end
209
179
 
210
- it "should create an array of features" do
211
- expect(BlacklightMaps::GeojsonExport.new(@controller, @action, @response.docs[0]).send(:build_geojson_features).blank?).to be false
180
+ it 'creates an array of system' do
181
+ expect(geojson_features).not_to be_blank
212
182
  end
213
-
214
183
  end
215
184
 
216
- describe "to_geojson" do
217
-
218
- before do
219
- @action = "show"
185
+ describe 'to_geojson' do
186
+ let(:feature_collection) do
187
+ described_class.new(controller, :show, response_docs.first).send(:to_geojson)
220
188
  end
221
189
 
222
- it "should render feature collection as json" do
223
- expect(BlacklightMaps::GeojsonExport.new(@controller, @action, @response.docs[0]).send(:to_geojson)).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
190
+ it 'renders feature collection as json' do
191
+ expect(feature_collection).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
224
192
  end
225
-
226
193
  end
227
-
228
194
  end