geoblacklight 5.3.0 → 5.4.0

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/geoblacklight/document/sidebar_component.html.erb +3 -0
  3. data/app/components/geoblacklight/document/sidebar_component.rb +7 -0
  4. data/app/components/geoblacklight/download_links_component.html.erb +3 -0
  5. data/app/components/geoblacklight/download_links_component.rb +1 -1
  6. data/app/components/geoblacklight/item_map_viewer_component.rb +2 -2
  7. data/app/components/geoblacklight/location_leaflet_map_component.rb +2 -2
  8. data/app/components/geoblacklight/relations_component.html.erb +1 -1
  9. data/app/components/geoblacklight/static_map_component.rb +2 -2
  10. data/app/controllers/download_controller.rb +6 -0
  11. data/app/controllers/relation_controller.rb +1 -1
  12. data/app/helpers/geoblacklight_helper.rb +31 -3
  13. data/app/javascript/geoblacklight/controllers/leaflet_viewer_controller.js +18 -3
  14. data/app/javascript/geoblacklight/controllers/openlayers_viewer_controller.js +33 -2
  15. data/app/javascript/geoblacklight/leaflet/basemaps.js +0 -32
  16. data/app/javascript/geoblacklight/leaflet/inspection.js +5 -4
  17. data/app/javascript/geoblacklight/openlayers/basemaps.js +0 -20
  18. data/app/javascript/geoblacklight/openlayers/layers.js +1 -1
  19. data/app/models/concerns/geoblacklight/solr_document.rb +19 -2
  20. data/app/views/catalog/_metadata.html.erb +3 -0
  21. data/geoblacklight.gemspec +2 -2
  22. data/lib/generators/geoblacklight/templates/catalog_controller.rb +4 -5
  23. data/lib/generators/geoblacklight/templates/settings.yml +19 -0
  24. data/lib/geoblacklight/deprecated_configuration.rb +665 -0
  25. data/lib/geoblacklight/download.rb +3 -0
  26. data/lib/geoblacklight/engine.rb +13 -0
  27. data/lib/geoblacklight/references.rb +6 -1
  28. data/lib/geoblacklight/relation/ancestors.rb +3 -0
  29. data/lib/geoblacklight/relation/descendants.rb +3 -0
  30. data/lib/geoblacklight/relation/relation_response.rb +4 -1
  31. data/lib/geoblacklight/version.rb +1 -1
  32. data/lib/geoblacklight.rb +16 -0
  33. data/lib/tasks/geoblacklight.rake +9 -0
  34. data/package.json +1 -1
  35. data/solr/conf/solrconfig.xml +10 -10
  36. data/spec/features/configurable_basemap_spec.rb +68 -0
  37. data/spec/features/relations_spec.rb +2 -3
  38. data/spec/lib/geoblacklight/deprecated_configuration_spec.rb +680 -0
  39. data/spec/solr_config_spec.rb +41 -0
  40. data/spec/spec_helper.rb +24 -1
  41. metadata +12 -9
@@ -0,0 +1,680 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe Geoblacklight::DeprecatedConfiguration do
6
+ let(:root) { Pathname.new(Dir.mktmpdir) }
7
+
8
+ after { FileUtils.remove_entry(root) }
9
+
10
+ def write(path, contents = "")
11
+ full = root.join(path)
12
+ FileUtils.mkdir_p(full.dirname)
13
+ File.write(full, contents)
14
+ full
15
+ end
16
+
17
+ describe ".warn_about_templates" do
18
+ it "warns about an overridden template, naming the file and its replacement" do
19
+ write("app/views/catalog/_metadata.html.erb")
20
+
21
+ expect(Geoblacklight.deprecation).to receive(:warn).with(
22
+ "app/views/catalog/_metadata.html.erb overrides catalog/_metadata, which is removed in " \
23
+ "GeoBlacklight 6; use Geoblacklight::MetadataComponent instead"
24
+ )
25
+
26
+ described_class.warn_about_templates(root)
27
+ end
28
+
29
+ it "catches the relations templates whatever their handler" do
30
+ write("app/views/relation/index.json.jbuilder")
31
+
32
+ expect(Geoblacklight.deprecation).to receive(:warn).with(/index\.json\.jbuilder overrides relation\/index/)
33
+
34
+ described_class.warn_about_templates(root)
35
+ end
36
+
37
+ it "does not warn when the application has no overrides" do
38
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
39
+
40
+ described_class.warn_about_templates(root)
41
+ end
42
+
43
+ it "does not warn about templates GeoBlacklight 6 keeps" do
44
+ write("app/views/catalog/_home_text.html.erb")
45
+
46
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
47
+
48
+ described_class.warn_about_templates(root)
49
+ end
50
+ end
51
+
52
+ describe ".warn_about_routes" do
53
+ it "warns when the application's routes still name a removed constant" do
54
+ write("config/routes.rb", <<~RUBY)
55
+ Rails.application.routes.draw do
56
+ concern :gbl_downloadable, Geoblacklight::Routes::Downloadable.new
57
+ end
58
+ RUBY
59
+
60
+ expect(Geoblacklight.deprecation).to receive(:warn).with(
61
+ /config\/routes\.rb needs these changes before GeoBlacklight 6: GeoBlacklight 6 removes the generated download subsystem/
62
+ )
63
+
64
+ described_class.warn_about_routes(root)
65
+ end
66
+
67
+ it "stays quiet once the download routes are gone" do
68
+ write("config/routes.rb", "Rails.application.routes.draw do\nend\n")
69
+
70
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
71
+
72
+ described_class.warn_about_routes(root)
73
+ end
74
+
75
+ it "stays quiet when there is no routes file" do
76
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
77
+
78
+ described_class.warn_about_routes(root)
79
+ end
80
+
81
+ it "never lets an unreadable routes file stop the application booting" do
82
+ path = write("config/routes.rb", "")
83
+ allow(File).to receive(:read).with(path.to_s).and_raise(Errno::EACCES)
84
+
85
+ expect { described_class.warn_about_routes(root) }.not_to raise_error
86
+ end
87
+ end
88
+
89
+ describe ".warn_about_asset_references" do
90
+ it "reports every dead reference in a stylesheet as one warning" do
91
+ write("app/assets/stylesheets/application.bootstrap.scss", <<~SCSS)
92
+ @import '@geoblacklight/frontend/app/assets/stylesheets/geoblacklight/geoblacklight';
93
+ $logo-image: url("images/blacklight/logo.svg");
94
+ SCSS
95
+
96
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(
97
+ /application\.bootstrap\.scss needs these changes before GeoBlacklight 6: .*geoblacklight\/geoblacklight.*; .*logo\.svg/m
98
+ )
99
+
100
+ described_class.warn_about_asset_references(root)
101
+ end
102
+
103
+ it "looks at the Vite entrypoints too" do
104
+ write("app/javascript/stylesheets/geoblacklight.scss",
105
+ "@import '@geoblacklight/frontend/app/assets/stylesheets/geoblacklight/geoblacklight.scss';")
106
+
107
+ expect(Geoblacklight.deprecation).to receive(:warn).with(/app\/javascript\/stylesheets\/geoblacklight\.scss/)
108
+
109
+ described_class.warn_about_asset_references(root)
110
+ end
111
+
112
+ it "stays quiet for a stylesheet with nothing dead in it" do
113
+ write("app/assets/stylesheets/application.bootstrap.scss", "@import 'bootstrap/scss/bootstrap';")
114
+
115
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
116
+
117
+ described_class.warn_about_asset_references(root)
118
+ end
119
+
120
+ it "never lets an unreadable stylesheet stop the application booting" do
121
+ path = write("app/assets/stylesheets/application.bootstrap.scss", "")
122
+ allow(File).to receive(:read).with(path.to_s).and_raise(Errno::EACCES)
123
+
124
+ expect(described_class.dead_asset_references(path.to_s)).to eq []
125
+ end
126
+ end
127
+
128
+ describe ".warn_about_layouts" do
129
+ it "reports everything the installed 5.x layout has to change, as one warning" do
130
+ write("app/views/layouts/blacklight/base.html.erb", <<~ERB)
131
+ <%= vite_client_tag %>
132
+ <%= render partial: 'shared/header_navbar' %>
133
+ ERB
134
+
135
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(
136
+ /base\.html\.erb needs these changes before GeoBlacklight 6: .*shared\/header_navbar.*; .*vite_client_tag/m
137
+ )
138
+
139
+ described_class.warn_about_layouts(root)
140
+ end
141
+
142
+ it "stays quiet for a layout that has already been migrated" do
143
+ write("app/views/layouts/blacklight/base.html.erb",
144
+ "<%= render blacklight_config.header_component.new %>")
145
+
146
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
147
+
148
+ described_class.warn_about_layouts(root)
149
+ end
150
+
151
+ it "stays quiet when the application has no layout of its own" do
152
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
153
+
154
+ described_class.warn_about_layouts(root)
155
+ end
156
+
157
+ it "never lets an unreadable layout stop the application booting" do
158
+ path = write("app/views/layouts/application.html.erb", "")
159
+ allow(File).to receive(:read).with(path.to_s).and_raise(Errno::EACCES)
160
+
161
+ expect(described_class.dead_layout_references(path.to_s)).to eq []
162
+ end
163
+ end
164
+
165
+ describe ".warn_about_removed_constants" do
166
+ it "reports every removed name in a file as one warning" do
167
+ write("app/components/document_component.html.erb", <<~ERB)
168
+ <%= render Geoblacklight::AttributeTableComponent.new(document:) %>
169
+ <%= render Geoblacklight::IndexMapInspectComponent.new(document:) %>
170
+ ERB
171
+
172
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(
173
+ /document_component\.html\.erb needs these changes before GeoBlacklight 6: .*AttributeTableComponent.*; .*IndexMapInspectComponent/m
174
+ )
175
+
176
+ described_class.warn_about_removed_constants(root)
177
+ end
178
+
179
+ it "catches the renamed relations namespace without catching its replacement" do
180
+ write("app/models/thing.rb", "Geoblacklight::Relation::RelationResponse.new(id, repo)")
181
+ write("app/models/other.rb", "Geoblacklight::Relations::RelationResponse.new(id, repo)")
182
+
183
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(/app\/models\/thing\.rb/)
184
+
185
+ described_class.warn_about_removed_constants(root)
186
+ end
187
+
188
+ it "looks at initializers and lib as well as app" do
189
+ write("config/initializers/geoblacklight.rb", "Geoblacklight::ShapefileDownload")
190
+
191
+ expect(Geoblacklight.deprecation).to receive(:warn).with(/config\/initializers\/geoblacklight\.rb/)
192
+
193
+ described_class.warn_about_removed_constants(root)
194
+ end
195
+
196
+ it "does not report the facet component the CatalogController check already covers" do
197
+ write("app/controllers/catalog_controller.rb", "item_component: Geoblacklight::IconFacetItemComponent")
198
+
199
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
200
+
201
+ described_class.warn_about_removed_constants(root)
202
+ end
203
+
204
+ it "stays quiet for an application that names none of them" do
205
+ write("app/models/solr_document.rb", "include Geoblacklight::SolrDocument")
206
+
207
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
208
+
209
+ described_class.warn_about_removed_constants(root)
210
+ end
211
+
212
+ it "never lets an unreadable file stop the application booting" do
213
+ path = write("app/models/thing.rb", "")
214
+ allow(File).to receive(:read).with(path.to_s).and_raise(Errno::EACCES)
215
+
216
+ expect(described_class.removed_constants_in(path.to_s)).to eq []
217
+ end
218
+ end
219
+
220
+ describe ".warn_about_frontend_package" do
221
+ it "warns while the frontend package is still pinned to a 5.x release" do
222
+ write("package.json", '{"dependencies": {"@geoblacklight/frontend": "5.3.0"}}')
223
+
224
+ expect(Geoblacklight.deprecation).to receive(:warn).with(
225
+ /package\.json pins @geoblacklight\/frontend to 5\.3\.0/
226
+ )
227
+
228
+ described_class.warn_about_frontend_package(root)
229
+ end
230
+
231
+ it "stays quiet once the package is on 6" do
232
+ write("package.json", '{"dependencies": {"@geoblacklight/frontend": "^6.0.0"}}')
233
+
234
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
235
+
236
+ described_class.warn_about_frontend_package(root)
237
+ end
238
+
239
+ it "stays quiet when the package is not a dependency" do
240
+ write("package.json", '{"dependencies": {}}')
241
+
242
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
243
+
244
+ described_class.warn_about_frontend_package(root)
245
+ end
246
+
247
+ it "stays quiet when there is no package.json" do
248
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
249
+
250
+ described_class.warn_about_frontend_package(root)
251
+ end
252
+
253
+ it "ignores a package.json it cannot parse" do
254
+ write("package.json", "{not json")
255
+
256
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
257
+ expect { described_class.warn_about_frontend_package(root) }.not_to raise_error
258
+ end
259
+ end
260
+
261
+ describe ".warn_about_locale_keys" do
262
+ it "reports a whole key family as one line rather than one line per key" do
263
+ write("config/locales/geoblacklight.en.yml", <<~YAML)
264
+ en:
265
+ blacklight:
266
+ icon:
267
+ stanford: Stanford
268
+ harvard: Harvard
269
+ YAML
270
+
271
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(
272
+ /stop translating the 2 blacklight\.icon\.\* keys/
273
+ )
274
+
275
+ described_class.warn_about_locale_keys(root)
276
+ end
277
+
278
+ it "names a single key on its own" do
279
+ write("config/locales/gbl.en.yml", "en:\n geoblacklight:\n relations:\n browse_all: Browse\n")
280
+
281
+ expect(Geoblacklight.deprecation).to receive(:warn).with(
282
+ /stop translating geoblacklight\.relations\.browse_all/
283
+ )
284
+
285
+ described_class.warn_about_locale_keys(root)
286
+ end
287
+
288
+ it "reports labels that become pluralized" do
289
+ write("config/locales/gbl.en.yml", <<~YAML)
290
+ en:
291
+ geoblacklight:
292
+ relations:
293
+ member_of_ancestors: Belongs to collection
294
+ YAML
295
+
296
+ expect(Geoblacklight.deprecation).to receive(:warn).with(/a one:\/other: pair/)
297
+
298
+ described_class.warn_about_locale_keys(root)
299
+ end
300
+
301
+ it "matches a translation into any locale, not just English" do
302
+ write("config/locales/gbl.de.yml", "de:\n geoblacklight:\n relations:\n browse_all: Alle\n")
303
+
304
+ expect(Geoblacklight.deprecation).to receive(:warn).with(/browse_all/)
305
+
306
+ described_class.warn_about_locale_keys(root)
307
+ end
308
+
309
+ it "does not warn about translations GeoBlacklight 6 keeps" do
310
+ write("config/locales/gbl.en.yml", "en:\n geoblacklight:\n home:\n title: My Portal\n")
311
+
312
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
313
+
314
+ described_class.warn_about_locale_keys(root)
315
+ end
316
+
317
+ it "does not warn when the application has no locale files of its own" do
318
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
319
+
320
+ described_class.warn_about_locale_keys(root)
321
+ end
322
+
323
+ it "ignores a locale file it cannot parse" do
324
+ write("config/locales/broken.en.yml", "en:\n geoblacklight:\n : not valid: [\n")
325
+
326
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
327
+ expect { described_class.warn_about_locale_keys(root) }.not_to raise_error
328
+ end
329
+
330
+ it "ignores a locale file that is not a mapping" do
331
+ write("config/locales/scalar.en.yml", "--- just a string\n")
332
+
333
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
334
+
335
+ described_class.warn_about_locale_keys(root)
336
+ end
337
+ end
338
+
339
+ describe ".warn_about_settings_file" do
340
+ it "reports everything the settings file needs, as one warning" do
341
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(
342
+ /\Aconfig\/settings\.yml needs these changes before GeoBlacklight 6: /
343
+ )
344
+
345
+ described_class.warn_about_settings_file
346
+ end
347
+
348
+ it "stays quiet once there is nothing left to change" do
349
+ allow(described_class).to receive(:settings_problems).and_return([])
350
+
351
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
352
+
353
+ described_class.warn_about_settings_file
354
+ end
355
+ end
356
+
357
+ describe ".settings_problems" do
358
+ subject(:problems) { described_class.settings_problems }
359
+
360
+ it "flags the RELATIONSHIPS_SHOWN attribute GeoBlacklight 6 stops drawing" do
361
+ expect(problems).to include(/delete the icon attribute from RELATIONSHIPS_SHOWN/)
362
+ end
363
+
364
+ it "says nothing about uppercase RELATIONSHIPS_SHOWN entry names, which 6 downcases" do
365
+ expect(problems).not_to include(/RELATIONSHIPS_SHOWN entries to lowercase/)
366
+ end
367
+
368
+ it "flags the settings whose feature GeoBlacklight 6 drops" do
369
+ expect(problems).to include(/remove Settings\.ICON_MAPPING/)
370
+ expect(problems).to include(/remove Settings\.SIDEBAR_STATIC_MAP/)
371
+ expect(problems).to include(/remove Settings\.HELP_TEXT/)
372
+ end
373
+
374
+ it "flags the whole LEAFLET section, naming the setting that replaces it" do
375
+ expect(problems).to include(/remove Settings\.LEAFLET,.*light_basemap_url and dark_basemap_url/)
376
+ end
377
+
378
+ it "flags the uppercase top level key convention, and the files that read it" do
379
+ expect(problems).to include(/rename the \d+ uppercase top level keys to lowercase/)
380
+ expect(problems).to include(/app\/models\/solr_document\.rb/)
381
+ end
382
+
383
+ it "flags settings GeoBlacklight 6 stops reading" do
384
+ expect(problems).to include(/remove Settings\.TIMEOUT_DOWNLOAD/)
385
+ end
386
+
387
+ it "flags a setting that is still the GeoBlacklight 5 default" do
388
+ stub_const("#{described_class}::CHANGED_SETTINGS", {
389
+ "TIMEOUT_WMS" => {from: Settings.TIMEOUT_WMS, to: 99, because: "of a reason"}
390
+ })
391
+
392
+ expect(problems).to include(/Settings\.TIMEOUT_WMS is still the GeoBlacklight 5 default/)
393
+ end
394
+
395
+ it "flags a setting GeoBlacklight 6 requires that is missing" do
396
+ stub_const("#{described_class}::REQUIRED_SETTINGS", {"NO_SUCH_SETTING" => "of a reason"})
397
+
398
+ expect(problems).to include(/set Settings\.NO_SUCH_SETTING/)
399
+ end
400
+
401
+ it "flags a setting value that stops matching" do
402
+ stub_const("#{described_class}::STALE_SETTING_VALUES", {
403
+ "METADATA_SHOWN" => {value: Settings.METADATA_SHOWN.first, because: "of a reason"}
404
+ })
405
+
406
+ expect(problems).to include(/Settings\.METADATA_SHOWN lists/)
407
+ end
408
+ end
409
+
410
+ describe ".relationships_shown_problems" do
411
+ it "is empty for a configuration GeoBlacklight 6 accepts" do
412
+ migrated = Config::Options.new.merge!(
413
+ member_of_ancestors: {field: "pcdm_memberOf_sm", inverse: "member_of_descendants",
414
+ label: "a.label", query_type: "ancestors"}
415
+ )
416
+ allow(Settings).to receive(:RELATIONSHIPS_SHOWN).and_return(migrated)
417
+
418
+ expect(described_class.relationships_shown_problems).to be_empty
419
+ end
420
+
421
+ it "is empty when nothing is configured" do
422
+ allow(Settings).to receive(:RELATIONSHIPS_SHOWN).and_return(Config::Options.new)
423
+
424
+ expect(described_class.relationships_shown_problems).to be_empty
425
+ end
426
+
427
+ it "is empty for an uppercase entry name, which GeoBlacklight 6 downcases itself" do
428
+ allow(Settings).to receive(:RELATIONSHIPS_SHOWN).and_return(
429
+ Config::Options.new.merge!(
430
+ MEMBER_OF_ANCESTORS: {field: "pcdm_memberOf_sm", inverse: "member_of_descendants",
431
+ label: "a.label", query_type: "ancestors"}
432
+ )
433
+ )
434
+
435
+ expect(described_class.relationships_shown_problems).to be_empty
436
+ end
437
+
438
+ it "reports icon as a label that stopped being drawn, not as a boot failure" do
439
+ allow(Settings).to receive(:RELATIONSHIPS_SHOWN).and_return(
440
+ Config::Options.new.merge!(
441
+ member_of_ancestors: {field: "pcdm_memberOf_sm", icon: "parent-item"}
442
+ )
443
+ )
444
+
445
+ problems = described_class.relationships_shown_problems
446
+
447
+ expect(problems).to include(/delete the icon attribute .* resource class badge/)
448
+ expect(problems).not_to include(/InvalidSettings/)
449
+ end
450
+
451
+ it "reports an attribute GeoBlacklight 6 has no setter for as a boot failure" do
452
+ allow(Settings).to receive(:RELATIONSHIPS_SHOWN).and_return(
453
+ Config::Options.new.merge!(
454
+ member_of_ancestors: {field: "pcdm_memberOf_sm", colour: "purple"}
455
+ )
456
+ )
457
+
458
+ problems = described_class.relationships_shown_problems
459
+
460
+ expect(problems).to include(/remove the colour attribute .*Exceptions::InvalidSettings/)
461
+ expect(problems).not_to include(/delete the colour attribute/)
462
+ end
463
+
464
+ it "is empty when the setting is not a mapping at all" do
465
+ allow(Settings).to receive(:RELATIONSHIPS_SHOWN).and_return(nil)
466
+
467
+ expect(described_class.relationships_shown_problems).to be_empty
468
+ end
469
+ end
470
+
471
+ describe ".uppercase_convention_problems" do
472
+ it "is empty once every top level key is lowercase" do
473
+ allow(Settings).to receive(:to_h).and_return({institution: "Stanford"})
474
+
475
+ expect(described_class.uppercase_convention_problems).to be_empty
476
+ end
477
+ end
478
+
479
+ describe ".warn_about_catalog_controller" do
480
+ it "reports everything the CatalogController needs, as one warning" do
481
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(
482
+ /\Aapp\/controllers\/catalog_controller\.rb needs these changes before GeoBlacklight 6: /
483
+ )
484
+
485
+ described_class.warn_about_catalog_controller
486
+ end
487
+
488
+ it "stays quiet once there is nothing left to change" do
489
+ allow(described_class).to receive(:catalog_controller_problems).and_return([])
490
+
491
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
492
+
493
+ described_class.warn_about_catalog_controller
494
+ end
495
+
496
+ it "never lets a broken controller stop the application booting" do
497
+ allow(described_class).to receive(:catalog_controller_problems).and_raise("boom")
498
+
499
+ expect { described_class.warn_about_catalog_controller }.not_to raise_error
500
+ end
501
+ end
502
+
503
+ describe ".catalog_controller_problems" do
504
+ subject(:problems) { described_class.catalog_controller_problems(CatalogController) }
505
+
506
+ it "flags the removed facet item component" do
507
+ expect(problems).to include(/item_component: Geoblacklight::IconFacetItemComponent/)
508
+ end
509
+
510
+ it "flags each removed helper the controller still names" do
511
+ expect(problems).to include(/helper_method: :snippit/)
512
+ expect(problems).to include(/helper_method: :render_value_as_truncate_abstract/)
513
+ end
514
+
515
+ # The basemap examples set the value explicitly rather than reading whatever
516
+ # CatalogController happens to carry: blacklight_config is memoized and shared,
517
+ # so an ambient read couples these to suite ordering.
518
+ it "leaves the stock basemap alone" do
519
+ config = CatalogController.blacklight_config.deep_copy
520
+ config.basemap_provider = "positron"
521
+ controller = class_double(CatalogController, blacklight_config: config)
522
+
523
+ expect(described_class.catalog_controller_problems(controller))
524
+ .not_to include(/basemap_provider/)
525
+ end
526
+
527
+ it "leaves an unset basemap alone" do
528
+ config = CatalogController.blacklight_config.deep_copy
529
+ config.basemap_provider = nil
530
+ controller = class_double(CatalogController, blacklight_config: config)
531
+
532
+ expect(described_class.catalog_controller_problems(controller))
533
+ .not_to include(/basemap_provider/)
534
+ end
535
+
536
+ it "flags a basemap the application chose for itself" do
537
+ config = CatalogController.blacklight_config.deep_copy
538
+ config.basemap_provider = "darkMatter"
539
+ controller = class_double(CatalogController, blacklight_config: config)
540
+
541
+ expect(described_class.catalog_controller_problems(controller))
542
+ .to include(/config\.basemap_provider = "darkMatter"/)
543
+ end
544
+
545
+ it "is empty for a controller that has already been migrated" do
546
+ config = CatalogController.blacklight_config.deep_copy
547
+ config.facet_fields.each_value { |field| field.item_component = nil }
548
+ config.index_fields.each_value { |field| field.helper_method = nil }
549
+ config.show_fields.each_value { |field| field.helper_method = nil }
550
+ config.basemap_provider = "positron"
551
+ controller = class_double(CatalogController, blacklight_config: config)
552
+
553
+ expect(described_class.catalog_controller_problems(controller)).to be_empty
554
+ end
555
+ end
556
+
557
+ describe ".setting_value" do
558
+ it "returns the value of a top level setting" do
559
+ expect(described_class.setting_value("TIMEOUT_WMS")).to eq Settings.TIMEOUT_WMS
560
+ end
561
+
562
+ it "walks a dotted path" do
563
+ expect(described_class.setting_value("FIELDS.ID")).to eq Settings.FIELDS.ID
564
+ end
565
+
566
+ it "is nil when the setting is absent" do
567
+ expect(described_class.setting_value("NO_SUCH_SETTING")).to be_nil
568
+ end
569
+
570
+ it "is nil when an ancestor of the path is absent" do
571
+ expect(described_class.setting_value("NO_SUCH_SETTING.NOR_THIS_ONE")).to be_nil
572
+ end
573
+ end
574
+
575
+ describe ".setting_present?" do
576
+ it "is true for a setting that is present" do
577
+ expect(described_class.setting_present?("TIMEOUT_WMS")).to be true
578
+ end
579
+
580
+ it "is false for a setting that is absent" do
581
+ expect(described_class.setting_present?("NO_SUCH_SETTING")).to be false
582
+ end
583
+ end
584
+
585
+ describe ".gem_requirement_problems" do
586
+ it "flags Blacklight 8, which GeoBlacklight 6 will not run against" do
587
+ problems = described_class.gem_requirement_problems("Blacklight" => "8.12.3")
588
+
589
+ expect(problems).to include(/Blacklight 8\.12\.3 is too old .* requires Blacklight 9\.1 or later/)
590
+ end
591
+
592
+ it "flags a Rails older than 8" do
593
+ problems = described_class.gem_requirement_problems("Rails" => "7.2.3")
594
+
595
+ expect(problems).to include(/Rails 7\.2\.3 is too old/)
596
+ end
597
+
598
+ it "is quiet once both libraries are new enough" do
599
+ problems = described_class.gem_requirement_problems(
600
+ "Blacklight" => "9.1.0", "Rails" => "8.1.1"
601
+ )
602
+
603
+ expect(problems).to be_empty
604
+ end
605
+
606
+ it "treats the minimum itself as new enough" do
607
+ problems = described_class.gem_requirement_problems("Blacklight" => "9.1")
608
+
609
+ expect(problems).to be_empty
610
+ end
611
+
612
+ it "flags Blacklight 9.0, which is short of the per-field layout components 6 uses" do
613
+ problems = described_class.gem_requirement_problems("Blacklight" => "9.0.0")
614
+
615
+ expect(problems).to include(/Blacklight 9\.0\.0 is too old/)
616
+ end
617
+
618
+ it "says nothing about a library it cannot see" do
619
+ expect(described_class.gem_requirement_problems({})).to be_empty
620
+ end
621
+
622
+ it "says nothing about a version it cannot parse" do
623
+ problems = described_class.gem_requirement_problems("Blacklight" => "not-a-version")
624
+
625
+ expect(problems).to be_empty
626
+ end
627
+ end
628
+
629
+ describe ".current_gem_versions" do
630
+ it "reads the versions actually loaded" do
631
+ expect(described_class.current_gem_versions)
632
+ .to include("Blacklight" => Blacklight::VERSION, "Rails" => Rails::VERSION::STRING)
633
+ end
634
+ end
635
+
636
+ describe ".warn_about_gem_requirements" do
637
+ it "warns once per library that is too old" do
638
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(/Blacklight 8\.12\.3 is too old/)
639
+
640
+ described_class.warn_about_gem_requirements("Blacklight" => "8.12.3")
641
+ end
642
+
643
+ it "stays quiet when every requirement is met" do
644
+ expect(Geoblacklight.deprecation).not_to receive(:warn)
645
+
646
+ described_class.warn_about_gem_requirements("Blacklight" => "9.1.0", "Rails" => "8.1.1")
647
+ end
648
+
649
+ it "reads the loaded versions when given nothing" do
650
+ allow(described_class).to receive(:current_gem_versions).and_return("Rails" => "7.2.3")
651
+ expect(Geoblacklight.deprecation).to receive(:warn).once.with(/Rails 7\.2\.3 is too old/)
652
+
653
+ described_class.warn_about_gem_requirements
654
+ end
655
+ end
656
+
657
+ describe ".warn!" do
658
+ it "runs every check" do
659
+ %i[warn_about_templates warn_about_locale_keys warn_about_routes
660
+ warn_about_asset_references warn_about_frontend_package
661
+ warn_about_removed_constants warn_about_layouts].each do |check|
662
+ expect(described_class).to receive(check).with(root)
663
+ end
664
+ expect(described_class).to receive(:warn_about_settings_file)
665
+ expect(described_class).to receive(:warn_about_catalog_controller)
666
+ expect(described_class).to receive(:warn_about_gem_requirements)
667
+
668
+ described_class.warn!(root)
669
+ end
670
+
671
+ it "skips the file checks when there is no application root" do
672
+ expect(described_class).not_to receive(:warn_about_templates)
673
+ allow(described_class).to receive(:warn_about_settings_file)
674
+ allow(described_class).to receive(:warn_about_catalog_controller)
675
+ allow(described_class).to receive(:warn_about_gem_requirements)
676
+
677
+ described_class.warn!(nil)
678
+ end
679
+ end
680
+ end