blacklight 9.2.1 → 9.3.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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/.github/matrix.json +4 -4
  3. data/.github/workflows/build.yml +3 -0
  4. data/.github/workflows/lint.yml +17 -2
  5. data/.github/workflows/main.yml +3 -0
  6. data/.github/workflows/release_7_x_scheduled.yml +3 -0
  7. data/.github/workflows/release_8_x_scheduled.yml +3 -0
  8. data/.github/workflows/test.yml +3 -2
  9. data/.gitignore +0 -1
  10. data/.prettierignore +5 -0
  11. data/.prettierrc.json +4 -0
  12. data/.rubocop.yml +4 -0
  13. data/.rubocop_todo.yml +0 -143
  14. data/VERSION +1 -1
  15. data/app/assets/builds/blacklight.css +39 -9
  16. data/app/assets/javascripts/blacklight/blacklight.esm.js +207 -125
  17. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  18. data/app/assets/javascripts/blacklight/blacklight.js +207 -125
  19. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  20. data/app/assets/stylesheets/blacklight/_search_results.scss +24 -0
  21. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +18 -3
  22. data/app/components/blacklight/constraints_component.rb +2 -1
  23. data/app/components/blacklight/facet_field_component.rb +1 -1
  24. data/app/components/blacklight/open_graph_metadata_component.rb +33 -0
  25. data/app/components/blacklight/search/sidebar_component.html.erb +2 -2
  26. data/app/components/blacklight/search/sidebar_component.rb +3 -2
  27. data/app/controllers/concerns/blacklight/catalog.rb +3 -5
  28. data/app/controllers/concerns/blacklight/controller.rb +2 -6
  29. data/app/controllers/concerns/blacklight/search_context.rb +2 -7
  30. data/app/controllers/concerns/blacklight/token_based_user.rb +2 -6
  31. data/app/helpers/blacklight/catalog_helper_behavior.rb +9 -9
  32. data/app/helpers/blacklight/url_helper_behavior.rb +2 -7
  33. data/app/javascript/blacklight-frontend/bookmark_toggle.js +10 -8
  34. data/app/javascript/blacklight-frontend/checkbox_submit.js +42 -33
  35. data/app/javascript/blacklight-frontend/color_theme_switcher.js +47 -16
  36. data/app/javascript/blacklight-frontend/core.js +18 -19
  37. data/app/javascript/blacklight-frontend/debounce.js +7 -5
  38. data/app/javascript/blacklight-frontend/facet_suggest.js +27 -25
  39. data/app/javascript/blacklight-frontend/index.js +1 -1
  40. data/app/javascript/blacklight-frontend/modal.js +69 -52
  41. data/app/javascript/blacklight-frontend/search_context.js +36 -17
  42. data/app/models/blacklight/facet_paginator.rb +1 -3
  43. data/app/presenters/blacklight/document_presenter.rb +10 -1
  44. data/app/presenters/blacklight/facet_grouped_item_presenter.rb +1 -3
  45. data/app/presenters/blacklight/facet_item_pivot_presenter.rb +0 -8
  46. data/app/presenters/blacklight/json_presenter.rb +1 -3
  47. data/app/presenters/blacklight/open_graph_presenter.rb +34 -0
  48. data/app/presenters/blacklight/thumbnail_presenter.rb +24 -1
  49. data/app/services/blacklight/field_retriever.rb +1 -3
  50. data/app/services/blacklight/search_service.rb +1 -1
  51. data/app/views/catalog/_document.atom.builder +3 -5
  52. data/app/views/catalog/_show_main_content.html.erb +1 -0
  53. data/app/views/catalog/index.atom.builder +8 -4
  54. data/app/views/layouts/blacklight/base.html.erb +7 -1
  55. data/config/i18n-tasks.yml +1 -1
  56. data/config/locales/blacklight.ja.yml +256 -0
  57. data/lib/blacklight/configuration/context.rb +1 -1
  58. data/lib/blacklight/configuration/fields.rb +3 -9
  59. data/lib/blacklight/configuration/view_config.rb +16 -0
  60. data/lib/blacklight/configuration.rb +6 -2
  61. data/lib/blacklight/engine.rb +2 -4
  62. data/lib/blacklight/search_builder.rb +4 -4
  63. data/lib/blacklight/search_state/filter_field.rb +0 -1
  64. data/lib/blacklight/search_state.rb +2 -6
  65. data/lib/blacklight/solr/facet_paginator.rb +1 -1
  66. data/lib/blacklight/solr/repository.rb +1 -3
  67. data/lib/blacklight/solr/response/facets.rb +11 -9
  68. data/lib/blacklight/solr/response/spelling.rb +51 -47
  69. data/lib/blacklight/solr/search_builder_behavior.rb +14 -15
  70. data/lib/blacklight.rb +3 -9
  71. data/lib/generators/blacklight/assets/importmap_generator.rb +3 -3
  72. data/lib/generators/blacklight/assets_generator.rb +1 -1
  73. data/lib/railties/blacklight.rake +3 -5
  74. data/package-lock.json +1054 -0
  75. data/package.json +7 -4
  76. data/rollup.config.js +5 -7
  77. data/spec/components/blacklight/constraints_component_spec.rb +23 -1
  78. data/spec/components/blacklight/document/page_header_component_spec.rb +4 -4
  79. data/spec/components/blacklight/document_component_spec.rb +16 -3
  80. data/spec/components/blacklight/metadata_field_component_spec.rb +2 -2
  81. data/spec/components/blacklight/response/spellcheck_component_spec.rb +2 -2
  82. data/spec/components/blacklight/search_bar_component_spec.rb +1 -1
  83. data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +1 -1
  84. data/spec/components/blacklight/system/dropdown_component_spec.rb +1 -2
  85. data/spec/controllers/bookmarks_controller_spec.rb +3 -9
  86. data/spec/controllers/catalog_controller_spec.rb +56 -26
  87. data/spec/features/dark_mode_spec.rb +30 -0
  88. data/spec/features/did_you_mean_spec.rb +1 -1
  89. data/spec/features/facet_missing_spec.rb +3 -3
  90. data/spec/features/modal_spec.rb +2 -2
  91. data/spec/features/open_graph_spec.rb +43 -0
  92. data/spec/features/search_context_spec.rb +1 -1
  93. data/spec/fixtures/sample_solr_documents.yml +6 -0
  94. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +11 -8
  95. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +1 -1
  96. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +5 -5
  97. data/spec/helpers/blacklight_helper_spec.rb +6 -4
  98. data/spec/helpers/catalog_helper_spec.rb +34 -8
  99. data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +2 -2
  100. data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +2 -2
  101. data/spec/lib/blacklight/search_state/filter_field_spec.rb +1 -1
  102. data/spec/lib/blacklight/search_state/pivot_filter_field_spec.rb +1 -1
  103. data/spec/lib/blacklight/search_state_spec.rb +14 -19
  104. data/spec/lib/blacklight_spec.rb +5 -5
  105. data/spec/models/blacklight/configuration_spec.rb +1 -1
  106. data/spec/models/blacklight/document/cache_key_spec.rb +32 -12
  107. data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
  108. data/spec/models/blacklight/icon_spec.rb +3 -3
  109. data/spec/models/blacklight/search_builder_spec.rb +21 -16
  110. data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +1 -1
  111. data/spec/models/blacklight/solr/document_spec.rb +8 -8
  112. data/spec/models/blacklight/solr/response/facets_spec.rb +5 -5
  113. data/spec/models/blacklight/solr/response/group_response_spec.rb +1 -1
  114. data/spec/models/blacklight/solr/response/group_spec.rb +1 -1
  115. data/spec/models/blacklight/solr/response_spec.rb +18 -3
  116. data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +46 -7
  117. data/spec/models/blacklight/suggest_search_spec.rb +1 -1
  118. data/spec/models/record_mailer_spec.rb +2 -2
  119. data/spec/models/search_spec.rb +7 -7
  120. data/spec/presenters/blacklight/document_presenter_spec.rb +19 -6
  121. data/spec/presenters/blacklight/facet_field_presenter_spec.rb +4 -4
  122. data/spec/presenters/blacklight/field_presenter_spec.rb +12 -9
  123. data/spec/presenters/blacklight/open_graph_presenter_spec.rb +56 -0
  124. data/spec/presenters/blacklight/rendering/pipeline_spec.rb +3 -3
  125. data/spec/presenters/blacklight/thumbnail_presenter_spec.rb +129 -13
  126. data/spec/routing/catalog_routing_spec.rb +1 -1
  127. data/spec/services/blacklight/field_retriever_spec.rb +1 -1
  128. data/spec/services/blacklight/search_service_spec.rb +8 -8
  129. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -3
  130. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -2
  131. data/spec/views/catalog/index.atom.builder_spec.rb +16 -20
  132. data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -1
  133. metadata +12 -2
@@ -123,6 +123,7 @@
123
123
  title_tsim: Naqdī barā-yi tamām-i fuṣūl
124
124
  subject_era_ssim:
125
125
  - 1997-
126
+ thumbnail_path_ss: https://picsum.photos/seed/00313831/100/100
126
127
  id: 00313831
127
128
  isbn_ssim:
128
129
  - '9645625963'
@@ -612,6 +613,7 @@
612
613
  - Gautama Buddha
613
614
  - Yaśodharā (Wife of Gautama Buddha)
614
615
  title_si: yaśodharā-mahākāvyam
616
+ thumbnail_path_ss: https://picsum.photos/seed/78908283/640/480
615
617
  id: '78908283'
616
618
  author_si: Parikshit Sharma Ogeti 1930 Yaśodharāmahākāvyam
617
619
  title_addl_tsim:
@@ -1091,6 +1093,7 @@
1091
1093
  subject_addl_ssim:
1092
1094
  - Customs and practices
1093
1095
  title_tsim: Sefer Mishnah berurah
1096
+ thumbnail_path_ss: https://picsum.photos/seed/92828023/60/180
1094
1097
  id: '92828023'
1095
1098
  subject_ssim:
1096
1099
  - Karo, Joseph ben Ephraim, 1488-1575
@@ -1683,6 +1686,7 @@
1683
1686
  - Bon-brgya (China)
1684
1687
  title_si: bon-brgyaʼi lo rgyus lugs gñis gsal baʼi me loṅ źes bya ba bźugs
1685
1688
  so
1689
+ thumbnail_path_ss: https://picsum.photos/seed/2004310986/200/80
1686
1690
  id: '2004310986'
1687
1691
  author_si: Bstanʼdzinmkhasgrub 1967 Bonbrgyaʼi lo rgyus lugs gñis gsal baʼi me
1688
1692
  loṅ źes bya ba bźugs so
@@ -2310,6 +2314,7 @@
2310
2314
  title_si: bod kyi naṅ chos ṅo sprod sñiṅ bsdus :goṅ sa skyabs mgon chen po
2311
2315
  mchog nas deṅ dus bod rigs na gźon rnams la naṅ chos ṅo sprod bstsal ba bźugs
2312
2316
  so
2317
+ thumbnail_path_ss: https://picsum.photos/seed/2008308201/120/90
2313
2318
  id: '2008308201'
2314
2319
  author_si: Bstanʼdzinrgyamtsho Dalai Lama XIV 1935 Bod kyi naṅ chos ṅo sprod
2315
2320
  sñiṅ bsdus goṅ sa skyabs mgon chen po mchog nas deṅ dus Bod rigs na gźon
@@ -2463,6 +2468,7 @@
2463
2468
  - Tibetan language
2464
2469
  - Teaching
2465
2470
  title_si: śes yon
2471
+ thumbnail_path_ss: https://picsum.photos/seed/2008308478/80/120
2466
2472
  id: '2008308478'
2467
2473
  author_si: "\U0010FFFF Śes yon"
2468
2474
  title_addl_tsim:
@@ -57,22 +57,25 @@ RSpec.describe Blacklight::ConfigurationHelperBehavior do
57
57
 
58
58
  describe "#field_label" do
59
59
  it "looks up the label as an i18n string" do
60
- expect(helper).to receive(:t).with(:some_key, default: []).and_return "my label"
60
+ allow(helper).to receive(:t).and_return "my label"
61
61
  label = helper.field_label :some_key
62
62
 
63
63
  expect(label).to eq "my label"
64
+ expect(helper).to have_received(:t).with(:some_key, default: [])
64
65
  end
65
66
 
66
67
  it "passes the provided i18n keys to I18n.t" do
67
- expect(helper).to receive(:t).with(:key_a, default: [:key_b, "default text"])
68
+ allow(helper).to receive(:t)
68
69
 
69
70
  helper.field_label :key_a, :key_b, "default text"
71
+ expect(helper).to have_received(:t).with(:key_a, default: [:key_b, "default text"])
70
72
  end
71
73
 
72
74
  it "compacts nil keys (fixes rails/rails#19419)" do
73
- expect(helper).to receive(:t).with(:key_a, default: [:key_b])
75
+ allow(helper).to receive(:t)
74
76
 
75
77
  helper.field_label :key_a, nil, :key_b
78
+ expect(helper).to have_received(:t).with(:key_a, default: [:key_b])
76
79
  end
77
80
  end
78
81
 
@@ -94,7 +97,7 @@ RSpec.describe Blacklight::ConfigurationHelperBehavior do
94
97
  end
95
98
 
96
99
  describe "#should_render_field?" do
97
- let(:field_config) { double('field config', if: true, unless: false) }
100
+ let(:field_config) { Blacklight::Configuration::Field.new(if: true, unless: false) }
98
101
 
99
102
  it "is true" do
100
103
  expect(helper.should_render_field?(field_config)).to be true
@@ -111,15 +114,15 @@ RSpec.describe Blacklight::ConfigurationHelperBehavior do
111
114
  end
112
115
  end
113
116
 
114
- context 'labels' do
115
- let(:field_config) { { 'my-key' => double('field', display_label: 'My Field') } }
117
+ describe 'labels' do
118
+ let(:field_config) { { 'my-key' => instance_double(Blacklight::Configuration::Field, display_label: 'My Field') } }
116
119
 
117
120
  before do
118
121
  allow(helper).to receive_messages(blacklight_config: config)
119
122
  end
120
123
 
121
124
  describe '#label_for_search_field' do
122
- let(:config) { double('Blacklight configuration', search_fields: field_config) }
125
+ let(:config) { Blacklight::Configuration.new(search_fields: field_config) }
123
126
 
124
127
  it 'handles a found key' do
125
128
  expect(helper.label_for_search_field('my-key')).to eq 'My Field'
@@ -135,7 +138,7 @@ RSpec.describe Blacklight::ConfigurationHelperBehavior do
135
138
  end
136
139
 
137
140
  describe '#sort_field_label' do
138
- let(:config) { double('Blacklight configuration', sort_fields: field_config) }
141
+ let(:config) { Blacklight::Configuration.new(sort_fields: field_config) }
139
142
 
140
143
  it 'handles a found key' do
141
144
  expect(helper.sort_field_label('my-key')).to eq 'My Field'
@@ -24,7 +24,7 @@ RSpec.describe Blacklight::RenderPartialsHelperBehavior do
24
24
  it { is_expected.to eq 'one_two_three' }
25
25
  end
26
26
 
27
- context "an array" do
27
+ context "with an array" do
28
28
  let(:value) { %w[one two three] }
29
29
 
30
30
  it { is_expected.to eq 'one_two_three' }
@@ -82,18 +82,17 @@ RSpec.describe Blacklight::UrlHelperBehavior do
82
82
  context "when an alternate scope is passed in" do
83
83
  subject(:tag) { helper.link_back_to_catalog(route_set: my_engine) }
84
84
 
85
- let(:my_engine) { double("Engine") }
85
+ let(:my_engine) { instance_double(ActionDispatch::Routing::RoutesProxy) }
86
86
 
87
87
  before do
88
88
  allow(helper).to receive(:current_search_session).and_return double(query_params: query_params)
89
89
  end
90
90
 
91
91
  it "calls url_for on the engine scope" do
92
- expect(my_engine).to receive(:url_for)
93
- .with({ q: "query", f: "facets", controller: "catalog" })
94
- .and_return('link-url')
92
+ allow(my_engine).to receive(:url_for).and_return('link-url')
95
93
  expect(tag).to include('Back to Search')
96
94
  expect(tag).to include('link-url')
95
+ expect(my_engine).to have_received(:url_for).with({ q: "query", f: "facets", controller: "catalog" })
97
96
  end
98
97
  end
99
98
  end
@@ -157,10 +156,11 @@ RSpec.describe Blacklight::UrlHelperBehavior do
157
156
  end
158
157
 
159
158
  it 'adds a controller-specific tracking attribute' do
160
- expect(helper.main_app).to receive(:track_test_path).and_return('/asdf')
159
+ allow(helper.main_app).to receive(:track_test_path).and_return('/asdf')
161
160
  link = helper.link_to_document document, data: { x: 1 }
162
161
 
163
162
  expect(link).to have_css '[data-context-href="/asdf"]'
163
+ expect(helper.main_app).to have_received(:track_test_path)
164
164
  end
165
165
  end
166
166
 
@@ -24,13 +24,13 @@ RSpec.describe BlacklightHelper do
24
24
  I18n.locale = :en
25
25
  end
26
26
 
27
- context "and no translation exists for that language" do
27
+ context "when no translation exists for that language" do
28
28
  it "defaults to 'Blacklight'" do
29
29
  expect(application_name).to eq "Blacklight"
30
30
  end
31
31
  end
32
32
 
33
- context "and a translation exists for that language" do
33
+ context "when a translation exists for that language" do
34
34
  around do |example|
35
35
  I18n.backend.store_translations(:de, 'blacklight' => { 'application_name' => 'Schwarzlicht' })
36
36
  example.run
@@ -77,13 +77,15 @@ RSpec.describe BlacklightHelper do
77
77
  end
78
78
 
79
79
  it "generates <link rel=alternate> tags" do
80
- expect(presenter).to receive(:link_rel_alternates).and_return(result)
80
+ allow(presenter).to receive(:link_rel_alternates).and_return(result)
81
81
  expect(helper.render_link_rel_alternates(document)).to eq result
82
+ expect(presenter).to have_received(:link_rel_alternates)
82
83
  end
83
84
 
84
85
  it "sends parameters" do
85
- expect(presenter).to receive(:link_rel_alternates).with({ unique: true }).and_return(result)
86
+ allow(presenter).to receive(:link_rel_alternates).and_return(result)
86
87
  expect(helper.render_link_rel_alternates(document, unique: true)).to eq result
88
+ expect(presenter).to have_received(:link_rel_alternates).with({ unique: true })
87
89
  end
88
90
  end
89
91
 
@@ -124,20 +124,33 @@ RSpec.describe CatalogHelper do
124
124
  context "when an alternate scope is passed in" do
125
125
  subject(:tag) { helper.rss_feed_link_tag(route_set: my_engine) }
126
126
 
127
- let(:my_engine) { double("Engine") }
127
+ let(:my_engine) { instance_double(ActionDispatch::Routing::RoutesProxy) }
128
128
  let(:query_params) { { controller: 'catalog', action: 'index' } }
129
129
  let(:config) { Blacklight::Configuration.new }
130
130
  let(:search_state) { Blacklight::SearchState.new(query_params, config, controller) }
131
131
 
132
132
  before do
133
- allow(helper).to receive(:search_state).and_return search_state
133
+ allow(helper).to receive_messages(search_state: search_state, blacklight_config: config)
134
134
  end
135
135
 
136
136
  it "calls url_for on the engine scope" do
137
- expect(my_engine).to receive(:url_for).and_return('/rss-path')
137
+ allow(my_engine).to receive(:url_for).and_return('/rss-path')
138
138
  expect(tag).to include('title="RSS for results"')
139
139
  expect(tag).to include('rel="alternate"')
140
140
  expect(tag).to include('type="application/rss+xml"')
141
+ expect(my_engine).to have_received(:url_for)
142
+ end
143
+ end
144
+
145
+ context "when the rss view has been removed from the configuration" do
146
+ let(:config) { Blacklight::Configuration.new.tap { |c| c.view.delete_field(:rss) } }
147
+
148
+ before do
149
+ allow(helper).to receive(:blacklight_config).and_return config
150
+ end
151
+
152
+ it "returns nil" do
153
+ expect(helper.rss_feed_link_tag).to be_nil
141
154
  end
142
155
  end
143
156
  end
@@ -146,20 +159,33 @@ RSpec.describe CatalogHelper do
146
159
  context "when an alternate scope is passed in" do
147
160
  subject(:tag) { helper.atom_feed_link_tag(route_set: my_engine) }
148
161
 
149
- let(:my_engine) { double("Engine") }
162
+ let(:my_engine) { instance_double(ActionDispatch::Routing::RoutesProxy) }
150
163
  let(:query_params) { { controller: 'catalog', action: 'index' } }
151
164
  let(:config) { Blacklight::Configuration.new }
152
165
  let(:search_state) { Blacklight::SearchState.new(query_params, config, controller) }
153
166
 
154
167
  before do
155
- allow(helper).to receive(:search_state).and_return search_state
168
+ allow(helper).to receive_messages(search_state: search_state, blacklight_config: config)
156
169
  end
157
170
 
158
171
  it "calls url_for on the engine scope" do
159
- expect(my_engine).to receive(:url_for).and_return('/atom-path')
172
+ allow(my_engine).to receive(:url_for).and_return('/atom-path')
160
173
  expect(tag).to include('title="Atom for results"')
161
174
  expect(tag).to include('rel="alternate"')
162
175
  expect(tag).to include('type="application/atom+xml"')
176
+ expect(my_engine).to have_received(:url_for)
177
+ end
178
+ end
179
+
180
+ context "when the atom view has been removed from the configuration" do
181
+ let(:config) { Blacklight::Configuration.new.tap { |c| c.view.delete_field(:atom) } }
182
+
183
+ before do
184
+ allow(helper).to receive(:blacklight_config).and_return config
185
+ end
186
+
187
+ it "returns nil" do
188
+ expect(helper.atom_feed_link_tag).to be_nil
163
189
  end
164
190
  end
165
191
  end
@@ -325,7 +351,7 @@ RSpec.describe CatalogHelper do
325
351
  session[:preferred_view] = :b
326
352
  end
327
353
 
328
- context "and no view is specified" do
354
+ context "when no view is specified" do
329
355
  it "uses the saved preference" do
330
356
  allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
331
357
  expect(helper.document_index_view_type).to eq :b
@@ -337,7 +363,7 @@ RSpec.describe CatalogHelper do
337
363
  end
338
364
  end
339
365
 
340
- context "and a view is specified" do
366
+ context "when a view is specified" do
341
367
  it "uses the query parameter" do
342
368
  allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
343
369
  expect(helper.document_index_view_type(view: :c)).to eq :c
@@ -7,7 +7,7 @@ RSpec.describe Blacklight::Configuration::SessionTrackingConfig do
7
7
  expect(config.storage).to eq 'server'
8
8
  end
9
9
 
10
- context "@storage is set to 'server'" do
10
+ context "when @storage is set to 'server'" do
11
11
  before do
12
12
  config.storage = 'server'
13
13
  end
@@ -22,7 +22,7 @@ RSpec.describe Blacklight::Configuration::SessionTrackingConfig do
22
22
  end
23
23
  end
24
24
 
25
- context "@storage is set to false" do
25
+ context "when @storage is set to false" do
26
26
  before do
27
27
  config.storage = false
28
28
  end
@@ -4,7 +4,7 @@ RSpec.describe Blacklight::NestedOpenStructWithHashAccess do
4
4
  subject { described_class.new(Blacklight::OpenStructWithHashAccess) }
5
5
 
6
6
  describe '#key' do
7
- context 'for an object provided by the initializer' do
7
+ context 'with an object provided by the initializer' do
8
8
  subject { described_class.new(Blacklight::OpenStructWithHashAccess, a: { b: 1 }) }
9
9
 
10
10
  it 'copies the key to the initialized value' do
@@ -12,7 +12,7 @@ RSpec.describe Blacklight::NestedOpenStructWithHashAccess do
12
12
  end
13
13
  end
14
14
 
15
- context 'for an object provided through assignment' do
15
+ context 'with an object provided through assignment' do
16
16
  it 'copies the key to the initialized value' do
17
17
  subject.a!
18
18
 
@@ -158,7 +158,7 @@ RSpec.describe Blacklight::SearchState::FilterField do
158
158
  end
159
159
  end
160
160
 
161
- context "With facet.missing field" do
161
+ context "with facet.missing field" do
162
162
  let(:params) do
163
163
  { f: { '-some_field': ["[* TO *]"] } }
164
164
  end
@@ -89,7 +89,7 @@ RSpec.describe Blacklight::SearchState::PivotFilterField do
89
89
  pending 'decide how inclusive facets should work with pivots'
90
90
  end
91
91
 
92
- context "With facet.missing field" do
92
+ context "with facet.missing field" do
93
93
  pending 'decide how facet.missing should work with pivots'
94
94
  end
95
95
  end
@@ -52,7 +52,7 @@ RSpec.describe Blacklight::SearchState do
52
52
  end
53
53
  end
54
54
 
55
- context 'deleting item from to_h' do
55
+ context 'when deleting item from to_h' do
56
56
  let(:additional_search_fields) { [:q_1] }
57
57
  let(:params) { { q: 'foo', q_1: 'bar' } }
58
58
 
@@ -65,7 +65,7 @@ RSpec.describe Blacklight::SearchState do
65
65
  end
66
66
  end
67
67
 
68
- context 'deleting deep item from to_h' do
68
+ context 'when deleting deep item from to_h' do
69
69
  let(:additional_search_fields) { [{ foo: {} }] }
70
70
  let(:params) { { foo: { bar: [] } } }
71
71
 
@@ -135,7 +135,7 @@ RSpec.describe Blacklight::SearchState do
135
135
  end
136
136
 
137
137
  context "when params has page" do
138
- context "and per_page changed" do
138
+ context "when per_page changed" do
139
139
  let(:params) { parameter_class.new per_page: 20, page: 5 }
140
140
 
141
141
  it "adjusts the current page" do
@@ -144,7 +144,7 @@ RSpec.describe Blacklight::SearchState do
144
144
  end
145
145
  end
146
146
 
147
- context "and per_page didn't change" do
147
+ context "when per_page didn't change" do
148
148
  let(:params) { parameter_class.new per_page: 20, page: 5 }
149
149
 
150
150
  it "doesn't change the current page" do
@@ -153,7 +153,7 @@ RSpec.describe Blacklight::SearchState do
153
153
  end
154
154
  end
155
155
 
156
- context "and the sort changes" do
156
+ context "when the sort changes" do
157
157
  let(:params) { parameter_class.new sort: 'field_a', page: 5 }
158
158
 
159
159
  it "adjusts the current page" do
@@ -162,7 +162,7 @@ RSpec.describe Blacklight::SearchState do
162
162
  end
163
163
  end
164
164
 
165
- context "and the sort didn't change" do
165
+ context "when the sort didn't change" do
166
166
  let(:params) { parameter_class.new sort: 'field_a', page: 5 }
167
167
 
168
168
  it "doesn't change the current page" do
@@ -271,7 +271,7 @@ RSpec.describe Blacklight::SearchState do
271
271
  end
272
272
  end
273
273
 
274
- context 'it defaults to the configured value' do
274
+ context 'without params' do
275
275
  let(:params) { {} }
276
276
 
277
277
  it 'maps from rows' do
@@ -357,14 +357,9 @@ RSpec.describe Blacklight::SearchState do
357
357
 
358
358
  describe "#url_for_document" do
359
359
  let(:controller_class) { CatalogController.new }
360
+ let(:controller) { controller_class }
360
361
  let(:doc) { SolrDocument.new }
361
362
 
362
- before do
363
- allow(search_state).to receive_messages(controller: controller_class)
364
- allow(search_state).to receive_messages(controller_name: controller_class.controller_name)
365
- allow(search_state).to receive_messages(params: parameter_class.new)
366
- end
367
-
368
363
  it "is a polymorphic routing-ready object" do
369
364
  expect(search_state.url_for_document(doc)).to eq doc
370
365
  end
@@ -374,7 +369,7 @@ RSpec.describe Blacklight::SearchState do
374
369
  expect(search_state.url_for_document(doc)).to eq(controller: 'catalog', action: :show, id: doc)
375
370
  end
376
371
 
377
- context "within bookmarks" do
372
+ context "when within bookmarks" do
378
373
  let(:controller_class) { BookmarksController.new }
379
374
 
380
375
  it "uses polymorphic routing" do
@@ -382,12 +377,12 @@ RSpec.describe Blacklight::SearchState do
382
377
  end
383
378
  end
384
379
 
385
- context "within an alternative catalog controller" do
380
+ context "when within an alternative catalog controller" do
386
381
  let(:controller_class) { AlternateController.new }
382
+ let(:params) { parameter_class.new(controller: 'alternate') }
387
383
 
388
384
  before do
389
385
  search_state.blacklight_config.show.route = { controller: :current }
390
- allow(search_state).to receive(:params).and_return(parameter_class.new(controller: 'alternate'))
391
386
  end
392
387
 
393
388
  it "supports the :current controller configuration" do
@@ -404,14 +399,14 @@ RSpec.describe Blacklight::SearchState do
404
399
  end
405
400
 
406
401
  describe '#filters' do
407
- context 'pivot facet config but no facet params' do
402
+ context 'with pivot facet config but no facet params' do
408
403
  it 'maps no filters' do
409
404
  blacklight_config.add_facet_field 'some_key', pivot: %w[pivot_field_1 pivot_field_2]
410
405
  expect(search_state.filters).to eq([])
411
406
  end
412
407
  end
413
408
 
414
- context 'pivot facet config and some pivot facet params' do
409
+ context 'with pivot facet config and some pivot facet params' do
415
410
  let(:params) { { 'f' => { 'pivot_field_1' => 'foo' } } }
416
411
 
417
412
  it 'maps the pivot matching param pivot_field' do
@@ -421,7 +416,7 @@ RSpec.describe Blacklight::SearchState do
421
416
  end
422
417
  end
423
418
 
424
- context 'regular facet config with params' do
419
+ context 'with regular facet config with params' do
425
420
  let(:params) { { 'f' => { 'some_key' => 'foo' } } }
426
421
 
427
422
  it 'maps the field matching param facet_field' do
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Blacklight do
4
- context 'root' do
4
+ describe 'root' do
5
5
  let(:blroot) { File.expand_path(File.join(__FILE__, '..', '..', '..')) }
6
6
 
7
7
  it 'returns the full path to the BL plugin' do
@@ -10,7 +10,7 @@ RSpec.describe Blacklight do
10
10
  end
11
11
 
12
12
  describe '.default_index' do
13
- context 'for a solr index' do
13
+ context 'with a solr index' do
14
14
  before do
15
15
  allow(described_class).to receive(:connection_config).and_return(adapter: 'solr')
16
16
  end
@@ -32,7 +32,7 @@ RSpec.describe Blacklight do
32
32
  end
33
33
  end
34
34
 
35
- context 'for a solr index' do
35
+ context 'with a solr index' do
36
36
  before do
37
37
  allow(described_class).to receive(:connection_config).and_return(adapter: 'solr')
38
38
  end
@@ -42,7 +42,7 @@ RSpec.describe Blacklight do
42
42
  end
43
43
  end
44
44
 
45
- context 'for an elastic_search index' do
45
+ context 'with an elastic_search index' do
46
46
  before do
47
47
  stub_const("Blacklight::ElasticSearch::Repository", double)
48
48
  allow(described_class).to receive(:connection_config).and_return(adapter: 'elastic_search')
@@ -53,7 +53,7 @@ RSpec.describe Blacklight do
53
53
  end
54
54
  end
55
55
 
56
- context 'for an explicitly provided class' do
56
+ context 'with an explicitly provided class' do
57
57
  before do
58
58
  stub_const("CustomSearch::Repository", double)
59
59
  allow(described_class).to receive(:connection_config).and_return(adapter: 'CustomSearch::Repository')
@@ -821,7 +821,7 @@ RSpec.describe Blacklight::Configuration, :api do
821
821
  expect(config.advanced_search.form_solr_parameters['f.subject_ssim.facet.limit']).to eq(-1)
822
822
  end
823
823
 
824
- context "preserving existing advanced search config if present" do
824
+ context "with an existing advanced search config" do
825
825
  before do
826
826
  config.advanced_search.form_solr_parameters = {
827
827
  'facet.sort' => 'index',
@@ -1,20 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Blacklight::Document::CacheKey, :api do
4
+ subject(:document) { document_class.new(attributes) }
5
+
4
6
  let(:attributes) { {} }
5
- let(:subject) { SolrDocument.new(attributes) }
7
+ let(:document_class) { SolrDocument }
8
+
9
+ # A SolrDocument subclass that keeps SolrDocument's model name, which is part of the cache key
10
+ def solr_document_subclass(&)
11
+ Class.new(SolrDocument) do
12
+ def self.model_name
13
+ SolrDocument.model_name
14
+ end
15
+
16
+ class_eval(&)
17
+ end
18
+ end
6
19
 
7
20
  it 'SolrDocument includes the module' do
8
- expect(subject.class).to include(described_class)
21
+ expect(document.class).to include(described_class)
9
22
  end
10
23
 
11
24
  describe 'new record' do
12
- before do
13
- allow(subject).to receive_messages(new_record?: true)
25
+ let(:document_class) do
26
+ solr_document_subclass do
27
+ def new_record?
28
+ true
29
+ end
30
+ end
14
31
  end
15
32
 
16
33
  it 'provides an acceptable cache key' do
17
- expect(subject.cache_key).to eq 'solr_documents/new'
34
+ expect(document.cache_key).to eq 'solr_documents/new'
18
35
  end
19
36
  end
20
37
 
@@ -22,14 +39,14 @@ RSpec.describe Blacklight::Document::CacheKey, :api do
22
39
  let(:attributes) { { id: '12345', _version_: '1497353774427013120' } }
23
40
 
24
41
  it 'provides a cache key with the id and version' do
25
- expect(subject.cache_key).to eq 'solr_documents/12345-1497353774427013120'
42
+ expect(document.cache_key).to eq 'solr_documents/12345-1497353774427013120'
26
43
  end
27
44
 
28
45
  describe 'as array' do
29
46
  let(:attributes) { { id: '12345', _version_: %w[1234 4321] } }
30
47
 
31
48
  it 'provides a cache key with the id and joined version array' do
32
- expect(subject.cache_key).to eq 'solr_documents/12345-12344321'
49
+ expect(document.cache_key).to eq 'solr_documents/12345-12344321'
33
50
  end
34
51
  end
35
52
  end
@@ -38,19 +55,22 @@ RSpec.describe Blacklight::Document::CacheKey, :api do
38
55
  let(:attributes) { { id: '12345' } }
39
56
 
40
57
  it 'provides a cache key with just the id' do
41
- expect(subject.cache_key).to eq 'solr_documents/12345'
58
+ expect(document.cache_key).to eq 'solr_documents/12345'
42
59
  end
43
60
  end
44
61
 
45
62
  describe '#cache_version_key' do
46
63
  let(:attributes) { { id: '12345', another_version_field: '1497353774427013120' } }
47
-
48
- before do
49
- allow(subject).to receive_messages(cache_version_key: :another_version_field)
64
+ let(:document_class) do
65
+ solr_document_subclass do
66
+ def cache_version_key
67
+ :another_version_field
68
+ end
69
+ end
50
70
  end
51
71
 
52
72
  it 'provides a cache key with the defined field' do
53
- expect(subject.cache_key).to eq 'solr_documents/12345-1497353774427013120'
73
+ expect(document.cache_key).to eq 'solr_documents/12345-1497353774427013120'
54
74
  end
55
75
  end
56
76
  end
@@ -12,7 +12,7 @@ RSpec.describe Blacklight::FacetPaginator, :api do
12
12
  let(:six_facet_values) { [book, musical_score, serial, musical_recording, microform, thesis] }
13
13
  let(:limit) { 6 }
14
14
 
15
- context 'on the first page of two pages' do
15
+ context 'when on the first page of two pages' do
16
16
  subject(:paginator) { described_class.new(seven_facet_values, limit: limit) }
17
17
 
18
18
  it { is_expected.to be_first_page }
@@ -41,7 +41,7 @@ RSpec.describe Blacklight::FacetPaginator, :api do
41
41
  end
42
42
  end
43
43
 
44
- context 'on the last page of two pages' do
44
+ context 'when on the last page of two pages' do
45
45
  subject(:paginator) { described_class.new([blank], offset: 6, limit: limit) }
46
46
 
47
47
  it { is_expected.not_to be_first_page }
@@ -70,7 +70,7 @@ RSpec.describe Blacklight::FacetPaginator, :api do
70
70
  end
71
71
  end
72
72
 
73
- context 'on the second page of three pages' do
73
+ context 'when on the second page of three pages' do
74
74
  subject(:paginator) { described_class.new(seven_facet_values, offset: 6, limit: limit) }
75
75
 
76
76
  it { is_expected.not_to be_first_page }
@@ -99,7 +99,7 @@ RSpec.describe Blacklight::FacetPaginator, :api do
99
99
  end
100
100
  end
101
101
 
102
- context 'on the first page of one page' do
102
+ context 'when on the first page of one page' do
103
103
  subject { described_class.new(six_facet_values, offset: 0, limit: limit) }
104
104
 
105
105
  it { is_expected.to be_first_page }
@@ -136,7 +136,7 @@ RSpec.describe Blacklight::FacetPaginator, :api do
136
136
  end
137
137
  end
138
138
 
139
- context "for a nil :limit" do
139
+ context "with a nil :limit" do
140
140
  let(:paginator) { described_class.new(seven_facet_values, offset: 0, limit: nil) }
141
141
 
142
142
  describe "#items" do