blacklight 7.0.0.rc1 → 7.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +30 -18
  3. data/.rubocop_todo.yml +308 -67
  4. data/.solr_wrapper.yml +8 -1
  5. data/.travis.yml +15 -13
  6. data/Gemfile +2 -0
  7. data/README.md +2 -2
  8. data/Rakefile +2 -0
  9. data/VERSION +1 -1
  10. data/Vagrantfile +2 -0
  11. data/app/assets/javascripts/blacklight/blacklight.js +17 -17
  12. data/app/assets/stylesheets/blacklight/_blacklight_base.scss +17 -16
  13. data/app/assets/stylesheets/blacklight/_facets.scss +2 -13
  14. data/app/assets/stylesheets/blacklight/_icons.scss +8 -2
  15. data/app/assets/stylesheets/blacklight/_search_form.scss +7 -0
  16. data/app/assets/stylesheets/blacklight/blacklight.scss +1 -1
  17. data/app/builders/blacklight/action_builder.rb +1 -0
  18. data/app/controllers/concerns/blacklight/bookmarks.rb +19 -13
  19. data/app/controllers/concerns/blacklight/catalog.rb +19 -7
  20. data/app/controllers/concerns/blacklight/controller.rb +12 -18
  21. data/app/controllers/concerns/blacklight/facet.rb +3 -0
  22. data/app/controllers/concerns/blacklight/search_context.rb +7 -3
  23. data/app/controllers/concerns/blacklight/search_history.rb +1 -6
  24. data/app/controllers/concerns/blacklight/token_based_user.rb +3 -1
  25. data/app/helpers/blacklight/blacklight_helper_behavior.rb +5 -1
  26. data/app/helpers/blacklight/configuration_helper_behavior.rb +5 -3
  27. data/app/helpers/blacklight/facets_helper_behavior.rb +15 -12
  28. data/app/helpers/blacklight/icon_helper_behavior.rb +2 -0
  29. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +2 -0
  30. data/app/helpers/blacklight/render_partials_helper_behavior.rb +2 -2
  31. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +1 -0
  32. data/app/helpers/blacklight/url_helper_behavior.rb +29 -14
  33. data/app/javascript/blacklight/checkbox_submit.js +9 -8
  34. data/app/javascript/blacklight/core.js +8 -6
  35. data/app/javascript/blacklight/modal.js +1 -3
  36. data/app/javascript/blacklight/search_context.js +0 -1
  37. data/app/models/blacklight/icon.rb +3 -0
  38. data/app/models/blacklight/suggest_search.rb +3 -14
  39. data/app/models/bookmark.rb +1 -1
  40. data/app/models/concerns/blacklight/document.rb +3 -1
  41. data/app/models/concerns/blacklight/solr/document.rb +1 -0
  42. data/app/models/concerns/blacklight/suggest/response.rb +5 -3
  43. data/app/models/concerns/blacklight/user.rb +1 -0
  44. data/app/models/search.rb +1 -0
  45. data/app/presenters/blacklight/document_presenter.rb +38 -0
  46. data/app/presenters/blacklight/field_presenter.rb +2 -0
  47. data/app/presenters/blacklight/index_presenter.rb +13 -5
  48. data/app/presenters/blacklight/json_presenter.rb +5 -12
  49. data/app/presenters/blacklight/link_alternate_presenter.rb +2 -0
  50. data/app/presenters/blacklight/rendering/abstract_step.rb +2 -0
  51. data/app/presenters/blacklight/rendering/helper_method.rb +2 -0
  52. data/app/presenters/blacklight/rendering/join.rb +2 -0
  53. data/app/presenters/blacklight/rendering/link_to_facet.rb +4 -0
  54. data/app/presenters/blacklight/rendering/microdata.rb +3 -0
  55. data/app/presenters/blacklight/rendering/pipeline.rb +2 -0
  56. data/app/presenters/blacklight/rendering/terminator.rb +2 -0
  57. data/app/presenters/blacklight/search_bar_presenter.rb +2 -0
  58. data/app/presenters/blacklight/show_presenter.rb +8 -5
  59. data/app/presenters/blacklight/thumbnail_presenter.rb +2 -0
  60. data/app/services/blacklight/document_factory.rb +2 -0
  61. data/app/services/blacklight/field_retriever.rb +2 -0
  62. data/app/services/blacklight/search_service.rb +7 -9
  63. data/app/values/blacklight/types.rb +3 -0
  64. data/app/views/bookmarks/index.html.erb +12 -13
  65. data/app/views/catalog/_citation.html.erb +4 -4
  66. data/app/views/catalog/_constraints.html.erb +2 -0
  67. data/app/views/catalog/_did_you_mean.html.erb +1 -1
  68. data/app/views/catalog/_document.atom.builder +17 -16
  69. data/app/views/catalog/_document.rss.builder +2 -0
  70. data/app/views/catalog/_facet_index_navigation.html.erb +5 -4
  71. data/app/views/catalog/_facet_layout.html.erb +3 -5
  72. data/app/views/catalog/_facets.html.erb +5 -4
  73. data/app/views/catalog/_field.json.jbuilder +10 -0
  74. data/app/views/catalog/_group.html.erb +1 -1
  75. data/app/views/catalog/_home_text.html.erb +5 -5
  76. data/app/views/catalog/_index.html.erb +5 -7
  77. data/app/views/catalog/_index_header.html.erb +1 -1
  78. data/app/views/catalog/_per_page_widget.html.erb +1 -1
  79. data/app/views/catalog/_results_pagination.html.erb +2 -2
  80. data/app/views/catalog/_search_form.html.erb +1 -1
  81. data/app/views/catalog/_search_results.html.erb +2 -2
  82. data/app/views/catalog/_show.html.erb +3 -5
  83. data/app/views/catalog/_show_more_like_this.html.erb +1 -1
  84. data/app/views/catalog/_show_sidebar.html.erb +1 -1
  85. data/app/views/catalog/_show_tools.html.erb +1 -1
  86. data/app/views/catalog/_sort_widget.html.erb +1 -1
  87. data/app/views/catalog/_zero_results.html.erb +1 -1
  88. data/app/views/catalog/citation.js.erb +1 -1
  89. data/app/views/catalog/facet.html.erb +5 -4
  90. data/app/views/catalog/facet.json.jbuilder +2 -0
  91. data/app/views/catalog/index.atom.builder +4 -2
  92. data/app/views/catalog/index.json.jbuilder +29 -10
  93. data/app/views/catalog/index.rss.builder +2 -0
  94. data/app/views/catalog/opensearch.xml.builder +3 -1
  95. data/app/views/catalog/show.json.jbuilder +21 -0
  96. data/app/views/kaminari/blacklight/_first_page.html.erb +1 -1
  97. data/app/views/kaminari/blacklight/_last_page.html.erb +1 -1
  98. data/app/views/kaminari/blacklight/_next_page.html.erb +3 -3
  99. data/app/views/kaminari/blacklight/_page.html.erb +4 -2
  100. data/app/views/kaminari/blacklight/_prev_page.html.erb +2 -2
  101. data/app/views/layouts/blacklight.html.erb +4 -4
  102. data/app/views/layouts/blacklight/base.html.erb +1 -9
  103. data/app/views/search_history/index.html.erb +3 -3
  104. data/app/views/shared/_header_navbar.html.erb +1 -1
  105. data/app/views/shared/_modal.html.erb +2 -2
  106. data/blacklight.gemspec +7 -6
  107. data/config/i18n-tasks.yml +17 -0
  108. data/config/locales/blacklight.de.yml +72 -57
  109. data/config/locales/blacklight.en.yml +11 -1
  110. data/config/locales/blacklight.es.yml +15 -1
  111. data/config/locales/blacklight.fr.yml +17 -8
  112. data/config/locales/blacklight.hu.yml +3 -1
  113. data/config/locales/blacklight.it.yml +16 -1
  114. data/config/locales/blacklight.nl.yml +3 -1
  115. data/config/locales/blacklight.pt-BR.yml +19 -2
  116. data/config/locales/blacklight.sq.yml +3 -1
  117. data/config/locales/blacklight.zh.yml +3 -1
  118. data/config/routes.rb +0 -1
  119. data/lib/blacklight.rb +3 -0
  120. data/lib/blacklight/abstract_repository.rb +12 -0
  121. data/lib/blacklight/configuration.rb +21 -3
  122. data/lib/blacklight/configuration/context.rb +11 -0
  123. data/lib/blacklight/configuration/fields.rb +31 -26
  124. data/lib/blacklight/configuration/null_field.rb +2 -0
  125. data/lib/blacklight/engine.rb +4 -1
  126. data/lib/blacklight/routes/exportable.rb +1 -3
  127. data/lib/blacklight/routes/searchable.rb +2 -3
  128. data/lib/blacklight/runtime_registry.rb +2 -0
  129. data/lib/blacklight/search_builder.rb +2 -0
  130. data/lib/blacklight/search_state.rb +2 -0
  131. data/lib/blacklight/solr/repository.rb +34 -0
  132. data/lib/blacklight/solr/response/spelling.rb +1 -0
  133. data/lib/generators/blacklight/assets_generator.rb +10 -9
  134. data/lib/generators/blacklight/controller_generator.rb +1 -1
  135. data/lib/generators/blacklight/install_generator.rb +7 -14
  136. data/lib/generators/blacklight/solr_generator.rb +8 -0
  137. data/lib/generators/blacklight/templates/alternate_controller.rb +4 -4
  138. data/lib/generators/blacklight/templates/catalog_controller.rb +7 -1
  139. data/lib/generators/blacklight/templates/solr/conf/schema.xml +20 -22
  140. data/lib/generators/blacklight/user_generator.rb +2 -0
  141. data/lib/railties/blacklight.rake +9 -13
  142. data/package-lock.json +544 -406
  143. data/package.json +3 -2
  144. data/spec/controllers/alternate_controller_spec.rb +4 -3
  145. data/spec/controllers/application_controller_spec.rb +0 -4
  146. data/spec/controllers/blacklight/base_spec.rb +5 -2
  147. data/spec/controllers/blacklight/catalog/component_configuration_spec.rb +4 -4
  148. data/spec/controllers/blacklight/facet_spec.rb +0 -1
  149. data/spec/controllers/blacklight/search_fields_spec.rb +25 -22
  150. data/spec/controllers/bookmarks_controller_spec.rb +45 -10
  151. data/spec/controllers/catalog_controller_spec.rb +206 -138
  152. data/spec/controllers/search_history_controller_spec.rb +4 -4
  153. data/spec/features/alternate_controller_spec.rb +3 -3
  154. data/spec/features/autocomplete_spec.rb +2 -0
  155. data/spec/features/did_you_mean_spec.rb +4 -3
  156. data/spec/features/facets_spec.rb +7 -7
  157. data/spec/features/record_view_spec.rb +11 -12
  158. data/spec/features/search_context_spec.rb +4 -5
  159. data/spec/features/search_crawler_spec.rb +3 -5
  160. data/spec/features/search_filters_spec.rb +44 -44
  161. data/spec/features/search_history_spec.rb +5 -3
  162. data/spec/features/search_pagination_spec.rb +3 -1
  163. data/spec/features/search_results_spec.rb +11 -8
  164. data/spec/features/search_spec.rb +3 -3
  165. data/spec/features/sitelinks_search_box.rb +4 -4
  166. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +30 -30
  167. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +65 -59
  168. data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +1 -1
  169. data/spec/helpers/blacklight/icon_helper_behavior_spec.rb +2 -0
  170. data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +8 -3
  171. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +16 -4
  172. data/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb +21 -22
  173. data/spec/helpers/blacklight/suggest_helper_behavior_spec.rb +6 -1
  174. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +49 -43
  175. data/spec/helpers/blacklight_helper_spec.rb +28 -12
  176. data/spec/helpers/catalog_helper_spec.rb +50 -47
  177. data/spec/i18n_spec.rb +18 -0
  178. data/spec/integration/generators/blacklight/solr_generator_spec.rb +18 -10
  179. data/spec/lib/blacklight/configuration/facet_field_spec.rb +2 -0
  180. data/spec/lib/blacklight/configuration/field_spec.rb +3 -0
  181. data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +15 -20
  182. data/spec/lib/blacklight/parameters_spec.rb +3 -1
  183. data/spec/lib/blacklight/search_state_spec.rb +51 -34
  184. data/spec/lib/blacklight_spec.rb +13 -14
  185. data/spec/lib/tasks/blacklight_task_spec.rb +3 -5
  186. data/spec/models/blacklight/configurable_spec.rb +11 -13
  187. data/spec/models/blacklight/configuration/context_spec.rb +9 -10
  188. data/spec/models/blacklight/configuration_spec.rb +103 -91
  189. data/spec/models/blacklight/document/active_model_shim_spec.rb +5 -6
  190. data/spec/models/blacklight/document/cache_key_spec.rb +9 -2
  191. data/spec/models/blacklight/document/dublin_core_spec.rb +16 -19
  192. data/spec/models/blacklight/document/email_spec.rb +9 -9
  193. data/spec/models/blacklight/document/sms_spec.rb +9 -9
  194. data/spec/models/blacklight/document_spec.rb +9 -8
  195. data/spec/models/blacklight/facet_paginator_spec.rb +40 -30
  196. data/spec/models/blacklight/icon_spec.rb +12 -2
  197. data/spec/models/blacklight/search_builder_spec.rb +12 -3
  198. data/spec/models/blacklight/solr/document_spec.rb +216 -219
  199. data/spec/models/blacklight/solr/facet_paginator_spec.rb +6 -4
  200. data/spec/models/blacklight/solr/repository_spec.rb +37 -34
  201. data/spec/models/blacklight/solr/request_spec.rb +17 -18
  202. data/spec/models/blacklight/solr/response/facets_spec.rb +58 -58
  203. data/spec/models/blacklight/solr/response/group_response_spec.rb +16 -22
  204. data/spec/models/blacklight/solr/response/group_spec.rb +18 -25
  205. data/spec/models/blacklight/solr/response_spec.rb +48 -50
  206. data/spec/models/blacklight/solr/search_builder_spec.rb +120 -121
  207. data/spec/models/blacklight/suggest/response_spec.rb +6 -4
  208. data/spec/models/blacklight/suggest_search_spec.rb +9 -16
  209. data/spec/models/blacklight/user_spec.rb +9 -11
  210. data/spec/models/bookmark_spec.rb +6 -5
  211. data/spec/models/record_mailer_spec.rb +22 -20
  212. data/spec/models/search_spec.rb +18 -17
  213. data/spec/models/solr_document_spec.rb +6 -2
  214. data/spec/presenters/blacklight/document_presenter_spec.rb +86 -0
  215. data/spec/presenters/blacklight/index_presenter_spec.rb +186 -0
  216. data/spec/presenters/blacklight/json_presenter_spec.rb +59 -0
  217. data/spec/presenters/blacklight/link_alternate_presenter_spec.rb +3 -0
  218. data/spec/presenters/blacklight/search_bar_presenter_spec.rb +7 -0
  219. data/spec/presenters/{show_presenter_spec.rb → blacklight/show_presenter_spec.rb} +138 -91
  220. data/spec/presenters/pipeline_spec.rb +15 -8
  221. data/spec/presenters/thumbnail_presenter_spec.rb +5 -2
  222. data/spec/routing/catalog_routing_spec.rb +12 -14
  223. data/spec/services/blacklight/search_service_spec.rb +112 -70
  224. data/spec/spec_helper.rb +6 -2
  225. data/spec/support/features.rb +1 -1
  226. data/spec/support/features/session_helpers.rb +4 -4
  227. data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -13
  228. data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -3
  229. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +9 -5
  230. data/spec/views/catalog/_document.html.erb_spec.rb +4 -4
  231. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -0
  232. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -4
  233. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +3 -3
  234. data/spec/views/catalog/_facets.html.erb_spec.rb +8 -10
  235. data/spec/views/catalog/_index.html.erb_spec.rb +13 -14
  236. data/spec/views/catalog/_index_header.html.erb_spec.rb +5 -8
  237. data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +3 -3
  238. data/spec/views/catalog/_show.html.erb_spec.rb +12 -13
  239. data/spec/views/catalog/_show_sidebar.erb_spec.rb +4 -7
  240. data/spec/views/catalog/_show_tools.html.erb_spec.rb +2 -2
  241. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +0 -1
  242. data/spec/views/catalog/_sort_widget.html.erb_spec.rb +3 -1
  243. data/spec/views/catalog/_thumbnail.html.erb_spec.rb +6 -8
  244. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +7 -9
  245. data/spec/views/catalog/email_success.html.erb_spec.rb +0 -1
  246. data/spec/views/catalog/facet.html.erb_spec.rb +3 -2
  247. data/spec/views/catalog/facet.json.jbuilder_spec.rb +3 -2
  248. data/spec/views/catalog/index.atom.builder_spec.rb +9 -4
  249. data/spec/views/catalog/index.html.erb_spec.rb +2 -1
  250. data/spec/views/catalog/index.json.jbuilder_spec.rb +84 -36
  251. data/spec/views/catalog/show.html.erb_spec.rb +6 -6
  252. data/spec/views/catalog/show.json.jbuilder_spec.rb +40 -0
  253. data/spec/views/catalog/sms_success.html.erb_spec.rb +0 -1
  254. data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -4
  255. data/tasks/blacklight.rake +6 -4
  256. data/template.demo.rb +2 -0
  257. metadata +50 -24
  258. data/app/javascript/blacklight/autofocus.js +0 -20
  259. data/spec/presenters/index_presenter_spec.rb +0 -150
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  RSpec.describe BlacklightHelper do
3
- before(:each) do
3
+ before do
4
4
  allow(helper).to receive(:current_or_guest_user).and_return(User.new)
5
5
  allow(helper).to receive(:search_action_path) do |*args|
6
6
  search_catalog_url *args
@@ -11,6 +11,7 @@ RSpec.describe BlacklightHelper do
11
11
  before do
12
12
  allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::NullStore.new)
13
13
  end
14
+
14
15
  it "defaults to 'Blacklight'" do
15
16
  expect(application_name).to eq "Blacklight"
16
17
  end
@@ -30,10 +31,11 @@ RSpec.describe BlacklightHelper do
30
31
 
31
32
  context "and a translation exists for that language" do
32
33
  around do |example|
33
- I18n.backend.store_translations(:de, 'blacklight' => { 'application_name' => 'Schwarzlicht' } )
34
+ I18n.backend.store_translations(:de, 'blacklight' => { 'application_name' => 'Schwarzlicht' })
34
35
  example.run
35
36
  I18n.backend.reload!
36
37
  end
38
+
37
39
  it "uses the provided value" do
38
40
  expect(application_name).to eq "Schwarzlicht"
39
41
  end
@@ -90,7 +92,7 @@ RSpec.describe BlacklightHelper do
90
92
  config.index.display_type_field = 'format'
91
93
  end
92
94
  end
93
- let(:document) { SolrDocument.new('title_tsim' => "A Fake Document", 'id'=>'8') }
95
+ let(:document) { SolrDocument.new('title_tsim' => "A Fake Document", 'id' => '8') }
94
96
 
95
97
  before do
96
98
  config.add_show_tools_partial(:bookmark, partial: 'catalog/bookmark_control')
@@ -103,7 +105,7 @@ RSpec.describe BlacklightHelper do
103
105
  describe "render_nav_actions" do
104
106
  it "renders partials" do
105
107
  buff = String.new
106
- helper.render_nav_actions { |config, item| buff << "<foo>#{item}</foo>" }
108
+ helper.render_nav_actions { |_config, item| buff << "<foo>#{item}</foo>" }
107
109
  expect(buff).to have_selector "foo a#bookmarks_nav[href=\"/bookmarks\"]"
108
110
  expect(buff).to have_selector "foo a span[data-role='bookmark-counter']", text: '0'
109
111
  end
@@ -142,15 +144,18 @@ RSpec.describe BlacklightHelper do
142
144
  end
143
145
 
144
146
  it "is true" do
147
+ expect(Deprecation).to receive(:warn)
145
148
  expect(helper.should_render_index_field?(double, double)).to be true
146
149
  end
147
150
 
148
151
  it "is false if the document doesn't have a value for the field" do
152
+ expect(Deprecation).to receive(:warn)
149
153
  allow(helper).to receive_messages(document_has_value?: false)
150
154
  expect(helper.should_render_index_field?(double, double)).to be false
151
155
  end
152
156
 
153
157
  it "is false if the configuration has the field disabled" do
158
+ expect(Deprecation).to receive(:warn)
154
159
  allow(helper).to receive_messages(should_render_field?: false)
155
160
  expect(helper.should_render_index_field?(double, double)).to be false
156
161
  end
@@ -162,15 +167,18 @@ RSpec.describe BlacklightHelper do
162
167
  end
163
168
 
164
169
  it "is true" do
170
+ expect(Deprecation).to receive(:warn)
165
171
  expect(helper.should_render_show_field?(double, double)).to be true
166
172
  end
167
173
 
168
174
  it "is false if the document doesn't have a value for the field" do
175
+ expect(Deprecation).to receive(:warn)
169
176
  allow(helper).to receive_messages(document_has_value?: false)
170
177
  expect(helper.should_render_show_field?(double, double)).to be false
171
178
  end
172
179
 
173
180
  it "is false if the configuration has the field disabled" do
181
+ expect(Deprecation).to receive(:warn)
174
182
  allow(helper).to receive_messages(should_render_field?: false)
175
183
  expect(helper.should_render_show_field?(double, double)).to be false
176
184
  end
@@ -178,21 +186,24 @@ RSpec.describe BlacklightHelper do
178
186
 
179
187
  describe "#document_has_value?" do
180
188
  let(:doc) { double(SolrDocument) }
189
+
190
+ before { allow(Deprecation).to receive(:warn) }
191
+
181
192
  it "ifs the document has the field value" do
182
193
  allow(doc).to receive(:has?).with('asdf').and_return(true)
183
- field_config = double(:field => 'asdf')
194
+ field_config = double(field: 'asdf')
184
195
  expect(helper.document_has_value?(doc, field_config)).to eq true
185
196
  end
186
197
  it "ifs the document has a highlight field value" do
187
198
  allow(doc).to receive(:has?).with('asdf').and_return(false)
188
199
  allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(true)
189
- field_config = double(:field => 'asdf', :highlight => true)
200
+ field_config = double(field: 'asdf', highlight: true)
190
201
  expect(helper.document_has_value?(doc, field_config)).to eq true
191
202
  end
192
203
  it "ifs the field has a model accessor" do
193
204
  allow(doc).to receive(:has?).with('asdf').and_return(false)
194
205
  allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(false)
195
- field_config = double(:field => 'asdf', :highlight => true, :accessor => true)
206
+ field_config = double(field: 'asdf', highlight: true, accessor: true)
196
207
  expect(helper.document_has_value?(doc, field_config)).to eq true
197
208
  end
198
209
  end
@@ -217,26 +228,28 @@ RSpec.describe BlacklightHelper do
217
228
  before do
218
229
  allow(helper).to receive_messages spell_check_max: 5
219
230
  end
231
+
220
232
  it "does not show suggestions if there are enough results" do
221
233
  response = double(total: 10)
222
- expect(helper.should_show_spellcheck_suggestions? response).to be false
234
+ expect(helper.should_show_spellcheck_suggestions?(response)).to be false
223
235
  end
224
236
  it "only shows suggestions if there are very few results" do
225
237
  response = double(total: 4, spelling: double(words: [1]))
226
- expect(helper.should_show_spellcheck_suggestions? response).to be true
238
+ expect(helper.should_show_spellcheck_suggestions?(response)).to be true
227
239
  end
228
240
  it "shows suggestions only if there are spelling suggestions available" do
229
241
  response = double(total: 4, spelling: double(words: []))
230
- expect(helper.should_show_spellcheck_suggestions? response).to be false
242
+ expect(helper.should_show_spellcheck_suggestions?(response)).to be false
231
243
  end
232
244
  it "does not show suggestions if spelling is not available" do
233
245
  response = double(total: 4, spelling: nil)
234
- expect(helper.should_show_spellcheck_suggestions? response).to be false
246
+ expect(helper.should_show_spellcheck_suggestions?(response)).to be false
235
247
  end
236
248
  end
237
249
 
238
250
  describe "#opensearch_description_tag" do
239
251
  subject { helper.opensearch_description_tag 'title', 'href' }
252
+
240
253
  it "has a search rel" do
241
254
  expect(subject).to have_selector "link[rel='search']", visible: false
242
255
  end
@@ -261,6 +274,7 @@ RSpec.describe BlacklightHelper do
261
274
 
262
275
  describe "#render_document_index_with_view" do
263
276
  let(:obj1) { SolrDocument.new }
277
+
264
278
  before do
265
279
  allow(helper).to receive(:blacklight_config).and_return(CatalogController.blacklight_config)
266
280
  assign(:response, instance_double(Blacklight::Solr::Response, grouped?: false, start: 0))
@@ -321,6 +335,7 @@ RSpec.describe BlacklightHelper do
321
335
  context "related classes" do
322
336
  let(:presenter_class) { double }
323
337
  let(:blacklight_config) { Blacklight::Configuration.new }
338
+
324
339
  before do
325
340
  allow(helper).to receive(:blacklight_config).and_return(blacklight_config)
326
341
  end
@@ -350,6 +365,7 @@ RSpec.describe BlacklightHelper do
350
365
 
351
366
  describe "#render_document_heading" do
352
367
  let(:document) { double }
368
+
353
369
  before do
354
370
  allow(helper).to receive(:presenter).and_return(double(heading: "Heading"))
355
371
  end
@@ -359,7 +375,7 @@ RSpec.describe BlacklightHelper do
359
375
  end
360
376
 
361
377
  it "accepts the tag name as an option" do
362
- expect(helper.render_document_heading tag: "h1").to have_selector "h1", text: "Heading"
378
+ expect(helper.render_document_heading(tag: "h1")).to have_selector "h1", text: "Heading"
363
379
  end
364
380
 
365
381
  it "accepts an explicit document argument" do
@@ -2,7 +2,7 @@
2
2
 
3
3
  RSpec.describe CatalogHelper do
4
4
  include ERB::Util
5
- include CatalogHelper
5
+ include described_class
6
6
 
7
7
  def mock_response args
8
8
  current_page = args[:current_page] || 1
@@ -22,18 +22,17 @@ RSpec.describe CatalogHelper do
22
22
  false
23
23
  end
24
24
 
25
-
26
25
  describe "page_entries_info" do
27
26
  it "with no results" do
28
- @response = mock_response :total => 0
27
+ @response = mock_response total: 0
29
28
 
30
- html = page_entries_info(@response, { :entry_name => 'entry_name' })
29
+ html = page_entries_info(@response, entry_name: 'entry_name')
31
30
  expect(html).to eq "No entry_names found"
32
31
  expect(html).to be_html_safe
33
32
  end
34
33
 
35
34
  it "with no results (and no entry_name provided)" do
36
- @response = mock_response :total => 0
35
+ @response = mock_response total: 0
37
36
 
38
37
  html = page_entries_info(@response)
39
38
  expect(html).to eq "No entries found"
@@ -49,15 +48,15 @@ RSpec.describe CatalogHelper do
49
48
 
50
49
  describe "with a single result" do
51
50
  it "uses the provided entry name" do
52
- response = mock_response :total => 1
51
+ response = mock_response total: 1
53
52
 
54
- html = page_entries_info(response, { :entry_name => 'entry_name' })
53
+ html = page_entries_info(response, entry_name: 'entry_name')
55
54
  expect(html).to eq "<strong>1</strong> entry_name found"
56
55
  expect(html).to be_html_safe
57
56
  end
58
57
 
59
58
  it "infers a name" do
60
- response = mock_response :total => 1
59
+ response = mock_response total: 1
61
60
 
62
61
  html = page_entries_info(response)
63
62
  expect(html).to eq "<strong>1</strong> entry found"
@@ -65,8 +64,8 @@ RSpec.describe CatalogHelper do
65
64
  end
66
65
 
67
66
  it "uses the model_name from the response" do
68
- response = mock_response :total => 1
69
- allow(response).to receive(:model_name).and_return(double(:human => 'thingy'))
67
+ response = mock_response total: 1
68
+ allow(response).to receive(:model_name).and_return(double(human: 'thingy'))
70
69
 
71
70
  html = page_entries_info(response)
72
71
  expect(html).to eq "<strong>1</strong> thingy found"
@@ -75,55 +74,57 @@ RSpec.describe CatalogHelper do
75
74
  end
76
75
 
77
76
  it "with a single page of results" do
78
- response = mock_response :total => 7
77
+ response = mock_response total: 7
79
78
 
80
- html = page_entries_info(response, { :entry_name => 'entry_name' })
79
+ html = page_entries_info(response, entry_name: 'entry_name')
81
80
  expect(html).to eq "<strong>1</strong> - <strong>7</strong> of <strong>7</strong>"
82
81
  expect(html).to be_html_safe
83
82
  end
84
83
 
85
84
  it "on the first page of multiple pages of results" do
86
- @response = mock_response :total => 15, :per_page => 10
85
+ @response = mock_response total: 15, per_page: 10
87
86
 
88
- html = page_entries_info(@response, { :entry_name => 'entry_name' })
87
+ html = page_entries_info(@response, entry_name: 'entry_name')
89
88
  expect(html).to eq "<strong>1</strong> - <strong>10</strong> of <strong>15</strong>"
90
89
  expect(html).to be_html_safe
91
90
  end
92
91
 
93
92
  it "on the second page of multiple pages of results" do
94
- @response = mock_response :total => 47, :per_page => 10, :current_page => 2
93
+ @response = mock_response total: 47, per_page: 10, current_page: 2
95
94
 
96
- html = page_entries_info(@response, { :entry_name => 'entry_name' })
95
+ html = page_entries_info(@response, entry_name: 'entry_name')
97
96
  expect(html).to eq "<strong>11</strong> - <strong>20</strong> of <strong>47</strong>"
98
97
  expect(html).to be_html_safe
99
98
  end
100
99
 
101
100
  it "on the last page of results" do
102
- @response = mock_response :total => 47, :per_page => 10, :current_page => 5
101
+ @response = mock_response total: 47, per_page: 10, current_page: 5
103
102
 
104
- html = page_entries_info(@response, { :entry_name => 'entry_name' })
103
+ html = page_entries_info(@response, entry_name: 'entry_name')
105
104
  expect(html).to eq "<strong>41</strong> - <strong>47</strong> of <strong>47</strong>"
106
105
  expect(html).to be_html_safe
107
106
  end
108
107
  it "works with rows the same as per_page" do
109
- @response = mock_response :total => 47, :rows => 20, :current_page => 2
108
+ @response = mock_response total: 47, rows: 20, current_page: 2
110
109
 
111
- html = page_entries_info(@response, { :entry_name => 'entry_name' })
110
+ html = page_entries_info(@response, entry_name: 'entry_name')
112
111
  expect(html).to eq "<strong>21</strong> - <strong>40</strong> of <strong>47</strong>"
113
112
  expect(html).to be_html_safe
114
113
  end
115
114
 
116
115
  it "uses delimiters with large numbers" do
117
- @response = mock_response :total => 5000, :rows => 10, :current_page => 101
118
- html = page_entries_info(@response, { :entry_name => 'entry_name' })
116
+ @response = mock_response total: 5000, rows: 10, current_page: 101
117
+ html = page_entries_info(@response, entry_name: 'entry_name')
119
118
 
120
119
  expect(html).to eq "<strong>1,001</strong> - <strong>1,010</strong> of <strong>5,000</strong>"
121
120
  end
122
121
 
123
122
  context "with an ActiveRecord collection" do
123
+ subject { helper.page_entries_info(Bookmark.page(1).per(25)) }
124
+
124
125
  let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345' }
126
+
125
127
  before { 50.times { Bookmark.create!(user: user) } }
126
- subject { helper.page_entries_info(Bookmark.page(1).per(25)) }
127
128
 
128
129
  it { is_expected.to eq "<strong>1</strong> - <strong>25</strong> of <strong>50</strong>" }
129
130
  end
@@ -177,6 +178,7 @@ RSpec.describe CatalogHelper do
177
178
  before do
178
179
  expect(Deprecation).to receive(:warn)
179
180
  end
181
+
180
182
  it "is focused if we're on a catalog-like index page without query or facet parameters" do
181
183
  allow(helper).to receive_messages(controller: CatalogController.new, action_name: "index", has_search_parameters?: false)
182
184
  expect(helper.should_autofocus_on_search_box?).to be true
@@ -207,27 +209,28 @@ RSpec.describe CatalogHelper do
207
209
  let(:data) { {} }
208
210
 
209
211
  it "has a thumbnail if a thumbnail_method is configured" do
210
- allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz, document_presenter_class: Blacklight::IndexPresenter) ))
211
- expect(helper.has_thumbnail? document).to be true
212
+ allow(helper).to receive_messages(blacklight_config: Blacklight::Configuration.new(index: Blacklight::OpenStructWithHashAccess.new(thumbnail_method: :xyz, document_presenter_class: Blacklight::IndexPresenter)))
213
+ expect(helper.has_thumbnail?(document)).to be true
212
214
  end
213
215
 
214
216
  context "if a thumbnail_field is configured and it exists in the document" do
215
217
  let(:data) { { xyz: 'abc' } }
218
+
216
219
  it "has a thumbnail" do
217
- allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz, document_presenter_class: Blacklight::IndexPresenter) ))
218
- expect(helper.has_thumbnail? document).to be true
220
+ allow(helper).to receive_messages(blacklight_config: Blacklight::Configuration.new(index: Blacklight::OpenStructWithHashAccess.new(thumbnail_field: :xyz, document_presenter_class: Blacklight::IndexPresenter)))
221
+ expect(helper.has_thumbnail?(document)).to be true
219
222
  end
220
223
  end
221
224
 
222
225
  it "does not have a thumbnail if the thumbnail_field is missing from the document" do
223
- allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz, document_presenter_class: Blacklight::IndexPresenter) ))
226
+ allow(helper).to receive_messages(blacklight_config: Blacklight::Configuration.new(index: Blacklight::OpenStructWithHashAccess.new(thumbnail_field: :xyz, document_presenter_class: Blacklight::IndexPresenter)))
224
227
  allow(document).to receive_messages(has?: false)
225
- expect(helper.has_thumbnail? document).to be false
228
+ expect(helper.has_thumbnail?(document)).to be false
226
229
  end
227
230
 
228
231
  it "does not have a thumbnail if none of the fields are configured" do
229
- allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(document_presenter_class: Blacklight::IndexPresenter) ))
230
- expect(helper.has_thumbnail? document).to be_falsey
232
+ allow(helper).to receive_messages(blacklight_config: Blacklight::Configuration.new(index: Blacklight::OpenStructWithHashAccess.new(document_presenter_class: Blacklight::IndexPresenter)))
233
+ expect(helper).not_to have_thumbnail(document)
231
234
  end
232
235
  end
233
236
 
@@ -235,7 +238,7 @@ RSpec.describe CatalogHelper do
235
238
  let(:index_presenter) do
236
239
  instance_double(Blacklight::IndexPresenter, thumbnail: thumbnail_presenter)
237
240
  end
238
- let(:thumbnail_presenter){ instance_double(Blacklight::ThumbnailPresenter) }
241
+ let(:thumbnail_presenter) { instance_double(Blacklight::ThumbnailPresenter) }
239
242
 
240
243
  before do
241
244
  expect(Deprecation).to receive(:warn)
@@ -251,7 +254,7 @@ RSpec.describe CatalogHelper do
251
254
 
252
255
  it "calls thumbnail presenter with provided values" do
253
256
  expect(thumbnail_presenter).to receive(:thumbnail_tag).with({}, suppress_link: true)
254
- result = helper.render_thumbnail_tag document, {}, suppress_link: true
257
+ helper.render_thumbnail_tag document, {}, suppress_link: true
255
258
  end
256
259
  end
257
260
 
@@ -261,18 +264,18 @@ RSpec.describe CatalogHelper do
261
264
  end
262
265
 
263
266
  it "pulls the configured thumbnail field out of the document" do
264
- allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
267
+ allow(helper).to receive_messages(blacklight_config: Blacklight::Configuration.new(index: Blacklight::OpenStructWithHashAccess.new(thumbnail_field: :xyz)))
265
268
  document = instance_double(SolrDocument)
266
269
  allow(document).to receive(:has?).with(:xyz).and_return(true)
267
270
  allow(document).to receive(:first).with(:xyz).and_return("asdf")
268
- expect(helper.thumbnail_url document).to eq("asdf")
271
+ expect(helper.thumbnail_url(document)).to eq("asdf")
269
272
  end
270
273
 
271
274
  it "returns nil if the thumbnail field doesn't exist" do
272
- allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
275
+ allow(helper).to receive_messages(blacklight_config: Blacklight::Configuration.new(index: Blacklight::OpenStructWithHashAccess.new(thumbnail_field: :xyz)))
273
276
  document = instance_double(SolrDocument)
274
277
  allow(document).to receive(:has?).with(:xyz).and_return(false)
275
- expect(helper.thumbnail_url document).to be_nil
278
+ expect(helper.thumbnail_url(document)).to be_nil
276
279
  end
277
280
  end
278
281
 
@@ -306,38 +309,37 @@ RSpec.describe CatalogHelper do
306
309
 
307
310
  it "pulls data out of a document's field" do
308
311
  blacklight_config.index.display_type_field = :type
309
- doc = { :type => 'book' }
312
+ doc = { type: 'book' }
310
313
  expect(helper.render_document_class(doc)).to eq "blacklight-book"
311
314
  end
312
315
 
313
316
  it "supports multivalued fields" do
314
317
  blacklight_config.index.display_type_field = :type
315
- doc = { :type => ['book', 'mss'] }
318
+ doc = { type: %w[book mss] }
316
319
  expect(helper.render_document_class(doc)).to eq "blacklight-book blacklight-mss"
317
320
  end
318
321
 
319
322
  it "supports empty fields" do
320
323
  blacklight_config.index.display_type_field = :type
321
- doc = { :type => [] }
324
+ doc = { type: [] }
322
325
  expect(helper.render_document_class(doc)).to be_blank
323
326
  end
324
327
 
325
328
  it "supports missing fields" do
326
329
  blacklight_config.index.display_type_field = :type
327
- doc = { }
330
+ doc = {}
328
331
  expect(helper.render_document_class(doc)).to be_blank
329
332
  end
330
333
 
331
334
  it "supports view-specific field configuration" do
332
335
  allow(helper).to receive(:document_index_view_type).and_return(:some_view_type)
333
336
  blacklight_config.view.some_view_type.display_type_field = :other_type
334
- doc = { other_type: "document"}
337
+ doc = { other_type: "document" }
335
338
  expect(helper.render_document_class(doc)).to eq "blacklight-document"
336
339
  end
337
340
  end
338
341
 
339
342
  describe "#bookmarked?" do
340
-
341
343
  let(:bookmark) { Bookmark.new document: bookmarked_document }
342
344
  let(:bookmarked_document) { SolrDocument.new(id: 'a') }
343
345
 
@@ -368,24 +370,25 @@ RSpec.describe CatalogHelper do
368
370
  end
369
371
 
370
372
  it "renders a facet with two values" do
371
- expect(helper.render_search_to_page_title_filter('foo', ['bar', 'baz'])).to eq "Foo: bar and baz"
373
+ expect(helper.render_search_to_page_title_filter('foo', %w[bar baz])).to eq "Foo: bar and baz"
372
374
  end
373
375
 
374
376
  it "renders a facet with more than two values" do
375
- expect(helper.render_search_to_page_title_filter('foo', ['bar', 'baz', 'foobar'])).to eq "Foo: 3 selected"
377
+ expect(helper.render_search_to_page_title_filter('foo', %w[bar baz foobar])).to eq "Foo: 3 selected"
376
378
  end
377
379
  end
378
380
 
379
381
  describe "#render_search_to_page_title" do
382
+ subject { helper.render_search_to_page_title(params) }
383
+
380
384
  before do
381
385
  allow(helper).to receive(:blacklight_config).and_return(blacklight_config)
382
- allow(helper).to receive(:default_search_field).and_return(Blacklight::Configuration::SearchField.new(:key => 'default_search_field', :display_label => 'Default'))
386
+ allow(helper).to receive(:default_search_field).and_return(Blacklight::Configuration::SearchField.new(key: 'default_search_field', display_label: 'Default'))
383
387
  allow(helper).to receive(:label_for_search_field).with(nil).and_return('')
384
388
  end
385
389
 
386
390
  let(:blacklight_config) { Blacklight::Configuration.new }
387
391
  let(:params) { ActionController::Parameters.new(q: 'foobar', f: { format: ["Book"] }) }
388
- subject { helper.render_search_to_page_title(params) }
389
392
 
390
393
  it { is_expected.to eq "foobar / Format: Book" }
391
394
  end