blacklight 6.20.0 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (428) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.jshintrc +3 -1
  4. data/.npmignore +23 -0
  5. data/.rubocop.yml +40 -16
  6. data/.rubocop_todo.yml +478 -382
  7. data/.travis.yml +28 -31
  8. data/CONTRIBUTING.md +50 -0
  9. data/Gemfile +5 -2
  10. data/README.md +22 -5
  11. data/Rakefile +3 -2
  12. data/VERSION +1 -1
  13. data/Vagrantfile +2 -0
  14. data/app/assets/images/blacklight/list.svg +1 -0
  15. data/app/assets/images/blacklight/search.svg +1 -0
  16. data/app/assets/javascripts/blacklight/blacklight.js +495 -57
  17. data/app/assets/stylesheets/blacklight/_balanced_list.scss +7 -12
  18. data/app/assets/stylesheets/blacklight/_blacklight_base.scss +18 -15
  19. data/app/assets/stylesheets/blacklight/_bookmark.scss +1 -13
  20. data/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +31 -0
  21. data/app/assets/stylesheets/blacklight/_constraints.scss +17 -25
  22. data/app/assets/stylesheets/blacklight/_controls.scss +8 -16
  23. data/app/assets/stylesheets/blacklight/_facets.scss +66 -92
  24. data/app/assets/stylesheets/blacklight/_header.scss +60 -47
  25. data/app/assets/stylesheets/blacklight/_icons.scss +35 -0
  26. data/app/assets/stylesheets/blacklight/_layout.scss +0 -10
  27. data/app/assets/stylesheets/blacklight/_mixins.scss +15 -0
  28. data/app/assets/stylesheets/blacklight/_modal.scss +9 -17
  29. data/app/assets/stylesheets/blacklight/_pagination.scss +4 -13
  30. data/app/assets/stylesheets/blacklight/_search_form.scss +7 -0
  31. data/app/assets/stylesheets/blacklight/_search_history.scss +5 -13
  32. data/app/assets/stylesheets/blacklight/_search_results.scss +9 -8
  33. data/app/assets/stylesheets/blacklight/_twitter_typeahead.scss +1 -2
  34. data/app/assets/stylesheets/blacklight/blacklight.scss +1 -1
  35. data/app/builders/blacklight/action_builder.rb +57 -0
  36. data/app/controllers/bookmarks_controller.rb +2 -2
  37. data/app/controllers/catalog_controller.rb +2 -2
  38. data/app/controllers/concerns/blacklight/base.rb +0 -33
  39. data/app/controllers/concerns/blacklight/bookmarks.rb +20 -30
  40. data/app/controllers/concerns/blacklight/catalog.rb +256 -210
  41. data/app/controllers/concerns/blacklight/controller.rb +102 -124
  42. data/app/controllers/concerns/blacklight/default_component_configuration.rb +12 -43
  43. data/app/controllers/concerns/blacklight/facet.rb +22 -8
  44. data/app/controllers/concerns/blacklight/search_context.rb +11 -11
  45. data/app/controllers/concerns/blacklight/search_fields.rb +4 -14
  46. data/app/controllers/concerns/blacklight/search_history.rb +1 -6
  47. data/app/controllers/concerns/blacklight/searchable.rb +17 -0
  48. data/app/controllers/concerns/blacklight/token_based_user.rb +5 -7
  49. data/app/helpers/blacklight/blacklight_helper_behavior.rb +37 -119
  50. data/app/helpers/blacklight/catalog_helper_behavior.rb +103 -93
  51. data/app/helpers/blacklight/component_helper_behavior.rb +21 -21
  52. data/app/helpers/blacklight/configuration_helper_behavior.rb +30 -58
  53. data/app/helpers/blacklight/facets_helper_behavior.rb +79 -54
  54. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +9 -11
  55. data/app/helpers/blacklight/icon_helper_behavior.rb +18 -0
  56. data/app/helpers/blacklight/layout_helper_behavior.rb +3 -3
  57. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +8 -6
  58. data/app/helpers/blacklight/render_partials_helper_behavior.rb +207 -0
  59. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +19 -11
  60. data/app/helpers/blacklight/suggest_helper_behavior.rb +1 -0
  61. data/app/helpers/blacklight/url_helper_behavior.rb +51 -42
  62. data/app/{assets/javascripts → javascript}/blacklight/autocomplete.js +3 -2
  63. data/app/javascript/blacklight/bookmark_toggle.js +25 -0
  64. data/app/javascript/blacklight/button_focus.js +9 -0
  65. data/app/javascript/blacklight/checkbox_submit.js +134 -0
  66. data/app/javascript/blacklight/core.js +41 -0
  67. data/app/javascript/blacklight/facet_load.js +22 -0
  68. data/app/{assets/javascripts/blacklight/ajax_modal.js → javascript/blacklight/modal.js} +62 -64
  69. data/app/javascript/blacklight/search_context.js +67 -0
  70. data/app/models/blacklight/facet_paginator.rb +3 -3
  71. data/app/models/blacklight/icon.rb +79 -0
  72. data/app/models/blacklight/suggest_search.rb +1 -1
  73. data/app/models/bookmark.rb +5 -10
  74. data/app/models/concerns/blacklight/configurable.rb +13 -13
  75. data/app/models/concerns/blacklight/document.rb +23 -39
  76. data/app/models/concerns/blacklight/document/active_model_shim.rb +8 -11
  77. data/app/models/concerns/blacklight/document/cache_key.rb +1 -1
  78. data/app/models/concerns/blacklight/document/dublin_core.rb +2 -2
  79. data/app/models/concerns/blacklight/document/email.rb +5 -5
  80. data/app/models/concerns/blacklight/document/extensions.rb +5 -5
  81. data/app/models/concerns/blacklight/document/semantic_fields.rb +9 -9
  82. data/app/models/concerns/blacklight/document/sms.rb +3 -3
  83. data/app/models/concerns/blacklight/user.rb +7 -6
  84. data/app/models/record_mailer.rb +8 -6
  85. data/app/models/search.rb +5 -7
  86. data/app/presenters/blacklight/document_presenter.rb +25 -140
  87. data/app/presenters/blacklight/field_presenter.rb +19 -14
  88. data/app/presenters/blacklight/index_presenter.rb +43 -71
  89. data/app/presenters/blacklight/json_presenter.rb +10 -14
  90. data/app/presenters/blacklight/link_alternate_presenter.rb +3 -1
  91. data/app/presenters/blacklight/rendering/abstract_step.rb +7 -5
  92. data/app/presenters/blacklight/rendering/helper_method.rb +10 -8
  93. data/app/presenters/blacklight/rendering/join.rb +5 -3
  94. data/app/presenters/blacklight/rendering/link_to_facet.rb +23 -19
  95. data/app/presenters/blacklight/rendering/microdata.rb +6 -3
  96. data/app/presenters/blacklight/rendering/pipeline.rb +27 -10
  97. data/app/presenters/blacklight/rendering/terminator.rb +2 -0
  98. data/app/presenters/blacklight/search_bar_presenter.rb +41 -0
  99. data/app/presenters/blacklight/show_presenter.rb +26 -72
  100. data/app/presenters/blacklight/thumbnail_presenter.rb +74 -0
  101. data/app/services/blacklight/document_factory.rb +13 -0
  102. data/app/services/blacklight/field_retriever.rb +26 -24
  103. data/app/services/blacklight/search_service.rb +153 -0
  104. data/app/values/blacklight/types.rb +31 -0
  105. data/app/views/blacklight/nav/_bookmark.html.erb +2 -2
  106. data/app/views/blacklight/nav/_search_history.html.erb +1 -1
  107. data/app/views/bookmarks/_tools.html.erb +2 -2
  108. data/app/views/bookmarks/index.html.erb +12 -13
  109. data/app/views/catalog/_bookmark_control.html.erb +27 -13
  110. data/app/views/catalog/_constraints.html.erb +6 -7
  111. data/app/views/catalog/_constraints_element.html.erb +6 -6
  112. data/app/views/catalog/_did_you_mean.html.erb +1 -1
  113. data/app/views/catalog/{_document_default.atom.builder → _document.atom.builder} +20 -19
  114. data/app/views/catalog/_document.html.erb +5 -3
  115. data/app/views/catalog/{_document_default.rss.builder → _document.rss.builder} +2 -0
  116. data/app/views/catalog/_document_action.html.erb +2 -1
  117. data/app/views/catalog/_email_form.html.erb +8 -4
  118. data/app/views/catalog/_facet_group.html.erb +19 -0
  119. data/app/views/catalog/_facet_index_navigation.html.erb +5 -4
  120. data/app/views/catalog/_facet_layout.html.erb +13 -8
  121. data/app/views/catalog/_facet_limit.html.erb +3 -2
  122. data/app/views/catalog/_facet_pagination.html.erb +8 -8
  123. data/app/views/catalog/_facet_pivot.html.erb +2 -2
  124. data/app/views/catalog/_facets.html.erb +3 -21
  125. data/app/views/catalog/_field.json.jbuilder +10 -0
  126. data/app/views/catalog/{_group_default.html.erb → _group.html.erb} +1 -1
  127. data/app/views/catalog/_home_text.html.erb +32 -36
  128. data/app/views/catalog/_index.html.erb +10 -0
  129. data/app/views/catalog/{_index_header_default.html.erb → _index_header.html.erb} +3 -3
  130. data/app/views/catalog/_per_page_widget.html.erb +7 -8
  131. data/app/views/catalog/_previous_next_doc.html.erb +6 -14
  132. data/app/views/catalog/_results_pagination.html.erb +2 -2
  133. data/app/views/catalog/_search_form.html.erb +12 -8
  134. data/app/views/catalog/_search_header.html.erb +0 -3
  135. data/app/views/catalog/_search_results.html.erb +10 -2
  136. data/app/views/catalog/_show.html.erb +8 -0
  137. data/app/views/catalog/{_show_header_default.html.erb → _show_header.html.erb} +0 -0
  138. data/app/views/catalog/_show_main_content.html.erb +4 -4
  139. data/app/views/catalog/_show_more_like_this.html.erb +1 -1
  140. data/app/views/catalog/_show_sidebar.html.erb +10 -8
  141. data/app/views/catalog/_show_tools.html.erb +10 -21
  142. data/app/views/catalog/_sms_form.html.erb +8 -4
  143. data/app/views/catalog/_sort_and_per_page.html.erb +3 -3
  144. data/app/views/catalog/_sort_widget.html.erb +8 -8
  145. data/app/views/catalog/_thumbnail.html.erb +5 -0
  146. data/app/views/catalog/_view_type_group.html.erb +2 -2
  147. data/app/views/catalog/_zero_results.html.erb +1 -1
  148. data/app/views/catalog/email.html.erb +5 -3
  149. data/app/views/catalog/email_success.html.erb +12 -8
  150. data/app/views/catalog/facet.html.erb +10 -8
  151. data/app/views/catalog/facet.json.jbuilder +2 -0
  152. data/app/views/catalog/index.atom.builder +28 -30
  153. data/app/views/catalog/index.html.erb +9 -11
  154. data/app/views/catalog/index.json.jbuilder +84 -3
  155. data/app/views/catalog/index.rss.builder +8 -6
  156. data/app/views/catalog/opensearch.xml.builder +12 -10
  157. data/app/views/catalog/show.html.erb +11 -6
  158. data/app/views/catalog/show.json.jbuilder +21 -0
  159. data/app/views/catalog/sms.html.erb +3 -1
  160. data/app/views/catalog/sms_success.html.erb +12 -8
  161. data/app/views/kaminari/blacklight/_first_page.html.erb +2 -2
  162. data/app/views/kaminari/blacklight/_gap.html.erb +2 -2
  163. data/app/views/kaminari/blacklight/_last_page.html.erb +2 -2
  164. data/app/views/kaminari/blacklight/_next_page.html.erb +5 -5
  165. data/app/views/kaminari/blacklight/_page.html.erb +5 -3
  166. data/app/views/kaminari/blacklight/_prev_page.html.erb +4 -4
  167. data/app/views/kaminari/blacklight_compact/_paginator.html.erb +4 -4
  168. data/app/views/layouts/blacklight.html.erb +14 -41
  169. data/app/views/layouts/blacklight/base.html.erb +40 -0
  170. data/app/views/layouts/catalog_result.html.erb +11 -0
  171. data/app/views/record_mailer/email_record.text.erb +6 -5
  172. data/app/views/search_history/index.html.erb +16 -21
  173. data/app/views/{_flash_msg.html.erb → shared/_flash_msg.html.erb} +5 -3
  174. data/app/views/shared/_header_navbar.html.erb +8 -13
  175. data/app/views/shared/_modal.html.erb +6 -0
  176. data/app/views/shared/_user_util_links.html.erb +22 -0
  177. data/blacklight.gemspec +8 -12
  178. data/config/i18n-tasks.yml +17 -0
  179. data/config/locales/blacklight.de.yml +87 -83
  180. data/config/locales/blacklight.en.yml +32 -29
  181. data/config/locales/blacklight.es.yml +31 -28
  182. data/config/locales/blacklight.fr.yml +33 -35
  183. data/config/locales/blacklight.hu.yml +226 -0
  184. data/config/locales/blacklight.it.yml +32 -28
  185. data/config/locales/blacklight.nl.yml +226 -0
  186. data/config/locales/blacklight.pt-BR.yml +41 -31
  187. data/config/locales/blacklight.sq.yml +21 -30
  188. data/config/locales/blacklight.zh.yml +20 -28
  189. data/config/routes.rb +2 -10
  190. data/db/migrate/20140202020202_create_bookmarks.rb +0 -1
  191. data/db/migrate/20140320000000_add_polymorphic_type_to_bookmarks.rb +1 -1
  192. data/lib/blacklight.rb +6 -4
  193. data/lib/blacklight/abstract_repository.rb +9 -9
  194. data/lib/blacklight/configuration.rb +106 -88
  195. data/lib/blacklight/configuration/context.rb +12 -1
  196. data/lib/blacklight/configuration/facet_field.rb +16 -9
  197. data/lib/blacklight/configuration/field.rb +32 -3
  198. data/lib/blacklight/configuration/fields.rb +15 -17
  199. data/lib/blacklight/configuration/null_field.rb +2 -0
  200. data/lib/blacklight/configuration/search_field.rb +2 -2
  201. data/lib/blacklight/configuration/sort_field.rb +2 -2
  202. data/lib/blacklight/configuration/view_config.rb +4 -0
  203. data/lib/blacklight/engine.rb +10 -10
  204. data/lib/blacklight/exceptions.rb +4 -7
  205. data/lib/blacklight/{utils.rb → nested_open_struct_with_hash_access.rb} +9 -81
  206. data/lib/blacklight/open_struct_with_hash_access.rb +49 -0
  207. data/lib/blacklight/parameters.rb +1 -1
  208. data/lib/blacklight/routes/exportable.rb +1 -3
  209. data/lib/blacklight/routes/searchable.rb +3 -3
  210. data/lib/blacklight/runtime_registry.rb +2 -0
  211. data/lib/blacklight/search_builder.rb +28 -35
  212. data/lib/blacklight/search_state.rb +10 -8
  213. data/lib/blacklight/solr.rb +2 -0
  214. data/{app/models/concerns → lib}/blacklight/solr/document.rb +8 -8
  215. data/{app/models → lib}/blacklight/solr/facet_paginator.rb +3 -3
  216. data/lib/blacklight/solr/repository.rb +4 -3
  217. data/lib/blacklight/solr/request.rb +1 -1
  218. data/lib/blacklight/solr/response.rb +29 -30
  219. data/lib/blacklight/solr/response/facets.rb +38 -31
  220. data/lib/blacklight/solr/response/group.rb +3 -3
  221. data/lib/blacklight/solr/response/group_response.rb +11 -1
  222. data/lib/blacklight/solr/response/more_like_this.rb +2 -2
  223. data/lib/blacklight/solr/response/pagination_methods.rb +12 -0
  224. data/lib/blacklight/solr/response/response.rb +2 -2
  225. data/lib/blacklight/solr/response/spelling.rb +4 -3
  226. data/lib/blacklight/solr/search_builder_behavior.rb +27 -31
  227. data/lib/blacklight/version.rb +1 -1
  228. data/lib/generators/blacklight/assets_generator.rb +28 -12
  229. data/lib/generators/blacklight/controller_generator.rb +4 -5
  230. data/lib/generators/blacklight/document_generator.rb +1 -1
  231. data/lib/generators/blacklight/install_generator.rb +15 -34
  232. data/lib/generators/blacklight/search_builder_generator.rb +1 -1
  233. data/lib/generators/blacklight/{solr5_generator.rb → solr_generator.rb} +12 -6
  234. data/{.solr_wrapper.yml → lib/generators/blacklight/templates/.solr_wrapper.yml} +0 -0
  235. data/lib/generators/blacklight/templates/alternate_controller.rb +4 -4
  236. data/lib/generators/blacklight/templates/blacklight.scss +0 -2
  237. data/lib/generators/blacklight/templates/catalog_controller.rb +57 -50
  238. data/lib/generators/blacklight/templates/config/blacklight.yml +1 -13
  239. data/{solr → lib/generators/blacklight/templates/solr}/conf/_rest_managed.json +0 -0
  240. data/{solr → lib/generators/blacklight/templates/solr}/conf/admin-extra.html +0 -0
  241. data/{solr → lib/generators/blacklight/templates/solr}/conf/elevate.xml +0 -0
  242. data/{solr → lib/generators/blacklight/templates/solr}/conf/mapping-ISOLatin1Accent.txt +0 -0
  243. data/{solr → lib/generators/blacklight/templates/solr}/conf/protwords.txt +0 -0
  244. data/lib/generators/blacklight/templates/solr/conf/schema.xml +388 -0
  245. data/{solr → lib/generators/blacklight/templates/solr}/conf/scripts.conf +0 -0
  246. data/lib/generators/blacklight/templates/solr/conf/solrconfig.xml +195 -0
  247. data/{solr → lib/generators/blacklight/templates/solr}/conf/spellings.txt +0 -0
  248. data/{solr → lib/generators/blacklight/templates/solr}/conf/stopwords.txt +0 -0
  249. data/{solr → lib/generators/blacklight/templates/solr}/conf/stopwords_en.txt +0 -0
  250. data/{solr → lib/generators/blacklight/templates/solr}/conf/synonyms.txt +0 -0
  251. data/{solr → lib/generators/blacklight/templates/solr}/conf/xslt/example.xsl +0 -0
  252. data/{solr → lib/generators/blacklight/templates/solr}/conf/xslt/example_atom.xsl +0 -0
  253. data/{solr → lib/generators/blacklight/templates/solr}/conf/xslt/example_rss.xsl +0 -0
  254. data/{solr → lib/generators/blacklight/templates/solr}/conf/xslt/luke.xsl +0 -0
  255. data/lib/generators/blacklight/test_support_generator.rb +10 -10
  256. data/lib/generators/blacklight/user_generator.rb +5 -6
  257. data/lib/railties/blacklight.rake +7 -6
  258. data/package-lock.json +2793 -0
  259. data/package.json +30 -0
  260. data/spec/controllers/alternate_controller_spec.rb +5 -4
  261. data/spec/controllers/application_controller_spec.rb +1 -5
  262. data/spec/controllers/blacklight/base_spec.rb +6 -3
  263. data/spec/controllers/blacklight/catalog/component_configuration_spec.rb +11 -7
  264. data/spec/controllers/blacklight/facet_spec.rb +1 -2
  265. data/spec/controllers/blacklight/search_fields_spec.rb +25 -34
  266. data/spec/controllers/bookmarks_controller_spec.rb +17 -13
  267. data/spec/controllers/catalog_controller_spec.rb +329 -161
  268. data/spec/controllers/search_history_controller_spec.rb +6 -6
  269. data/spec/features/alternate_controller_spec.rb +4 -4
  270. data/spec/features/autocomplete_spec.rb +4 -2
  271. data/spec/features/bookmarks_spec.rb +10 -10
  272. data/spec/features/did_you_mean_spec.rb +7 -12
  273. data/spec/features/facets_spec.rb +38 -17
  274. data/spec/features/record_view_spec.rb +12 -18
  275. data/spec/features/search_context_spec.rb +6 -7
  276. data/spec/features/search_crawler_spec.rb +3 -5
  277. data/spec/features/search_filters_spec.rb +100 -80
  278. data/spec/features/search_formats_spec.rb +4 -5
  279. data/spec/features/search_history_spec.rb +6 -29
  280. data/spec/features/search_pagination_spec.rb +4 -2
  281. data/spec/features/search_results_spec.rb +14 -12
  282. data/spec/features/search_sort_spec.rb +2 -2
  283. data/spec/features/search_spec.rb +8 -9
  284. data/spec/features/sitelinks_search_box.rb +4 -4
  285. data/{solr → spec/fixtures}/sample_solr_documents.yml +688 -688
  286. data/spec/helpers/{configuration_helper_spec.rb → blacklight/configuration_helper_behavior_spec.rb} +97 -98
  287. data/spec/helpers/{facets_helper_spec.rb → blacklight/facets_helper_behavior_spec.rb} +82 -73
  288. data/spec/helpers/{hash_as_hidden_fields_spec.rb → blacklight/hash_as_hidden_fields_behavior_spec.rb} +2 -2
  289. data/spec/helpers/blacklight/icon_helper_behavior_spec.rb +10 -0
  290. data/spec/helpers/{layout_helper_spec.rb → blacklight/layout_helper_behavior_spec.rb} +5 -5
  291. data/spec/helpers/{render_constraints_helper_spec.rb → blacklight/render_constraints_helper_behavior_spec.rb} +10 -6
  292. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +92 -0
  293. data/spec/helpers/{search_history_constraints_helper_spec.rb → blacklight/search_history_constraints_helper_behavior_spec.rb} +29 -30
  294. data/spec/helpers/{suggest_helper_spec.rb → blacklight/suggest_helper_behavior_spec.rb} +9 -2
  295. data/spec/helpers/{url_helper_spec.rb → blacklight/url_helper_behavior_spec.rb} +61 -54
  296. data/spec/helpers/blacklight_helper_spec.rb +104 -151
  297. data/spec/helpers/catalog_helper_spec.rb +89 -105
  298. data/spec/i18n_spec.rb +18 -0
  299. data/spec/integration/generators/blacklight/{solr5_generator_spec.rb → solr_generator_spec.rb} +21 -13
  300. data/spec/lib/blacklight/configuration/facet_field_spec.rb +13 -0
  301. data/spec/lib/blacklight/configuration/field_spec.rb +15 -0
  302. data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +17 -0
  303. data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +148 -0
  304. data/spec/lib/blacklight/parameters_spec.rb +4 -2
  305. data/spec/lib/blacklight/search_state_spec.rb +53 -36
  306. data/spec/lib/blacklight_spec.rb +14 -15
  307. data/spec/lib/tasks/blacklight_task_spec.rb +4 -6
  308. data/spec/models/blacklight/configurable_spec.rb +24 -27
  309. data/spec/models/blacklight/configuration/context_spec.rb +9 -10
  310. data/spec/models/blacklight/configuration_spec.rb +188 -165
  311. data/spec/models/blacklight/document/active_model_shim_spec.rb +15 -6
  312. data/spec/models/blacklight/document/cache_key_spec.rb +10 -3
  313. data/spec/models/blacklight/document/dublin_core_spec.rb +17 -20
  314. data/spec/models/blacklight/document/email_spec.rb +10 -10
  315. data/spec/models/blacklight/document/sms_spec.rb +10 -10
  316. data/spec/models/blacklight/document_spec.rb +10 -22
  317. data/spec/models/blacklight/facet_paginator_spec.rb +40 -30
  318. data/spec/models/blacklight/icon_spec.rb +82 -0
  319. data/spec/models/blacklight/search_builder_spec.rb +41 -26
  320. data/spec/models/blacklight/solr/document_spec.rb +224 -216
  321. data/spec/models/blacklight/solr/facet_paginator_spec.rb +6 -4
  322. data/spec/models/blacklight/solr/repository_spec.rb +50 -42
  323. data/spec/models/blacklight/solr/request_spec.rb +17 -18
  324. data/spec/models/blacklight/solr/response/facets_spec.rb +97 -60
  325. data/spec/models/blacklight/solr/response/group_response_spec.rb +29 -22
  326. data/spec/models/blacklight/solr/response/group_spec.rb +18 -25
  327. data/spec/models/blacklight/solr/response_spec.rb +72 -68
  328. data/spec/models/blacklight/solr/search_builder_spec.rb +150 -164
  329. data/spec/models/blacklight/suggest/response_spec.rb +2 -1
  330. data/spec/models/blacklight/suggest_search_spec.rb +4 -4
  331. data/spec/models/blacklight/user_spec.rb +9 -11
  332. data/spec/models/bookmark_spec.rb +7 -6
  333. data/spec/models/record_mailer_spec.rb +23 -21
  334. data/spec/models/search_spec.rb +19 -18
  335. data/spec/models/solr_document_spec.rb +33 -5
  336. data/spec/presenters/blacklight/document_presenter_spec.rb +86 -0
  337. data/spec/presenters/{index_presenter_spec.rb → blacklight/index_presenter_spec.rb} +25 -62
  338. data/spec/presenters/blacklight/json_presenter_spec.rb +59 -0
  339. data/spec/presenters/blacklight/link_alternate_presenter_spec.rb +3 -0
  340. data/spec/presenters/blacklight/search_bar_presenter_spec.rb +94 -0
  341. data/spec/presenters/{show_presenter_spec.rb → blacklight/show_presenter_spec.rb} +47 -62
  342. data/spec/presenters/pipeline_spec.rb +43 -16
  343. data/spec/presenters/thumbnail_presenter_spec.rb +174 -0
  344. data/spec/routing/catalog_routing_spec.rb +13 -31
  345. data/spec/services/blacklight/search_service_spec.rb +495 -0
  346. data/spec/spec_helper.rb +12 -24
  347. data/spec/support/features.rb +1 -1
  348. data/spec/support/features/session_helpers.rb +4 -4
  349. data/spec/test_app_templates/Gemfile.extra +2 -5
  350. data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -13
  351. data/spec/views/catalog/_constraints.html.erb_spec.rb +3 -6
  352. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +17 -13
  353. data/spec/views/catalog/_document.html.erb_spec.rb +11 -11
  354. data/spec/views/catalog/_document_list.html.erb_spec.rb +2 -1
  355. data/spec/views/catalog/_facet_group.html.erb_spec.rb +82 -0
  356. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +5 -5
  357. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +6 -6
  358. data/spec/views/catalog/_facets.html.erb_spec.rb +6 -46
  359. data/spec/views/catalog/{_index_default.erb_spec.rb → _index.html.erb_spec.rb} +14 -15
  360. data/spec/views/catalog/{_index_header_default.html.erb_spec.rb → _index_header.html.erb_spec.rb} +6 -9
  361. data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +7 -30
  362. data/spec/views/catalog/_search_header.erb_spec.rb +1 -3
  363. data/spec/views/catalog/{_show_default.erb_spec.rb → _show.html.erb_spec.rb} +13 -14
  364. data/spec/views/catalog/_show_sidebar.erb_spec.rb +7 -10
  365. data/spec/views/catalog/_show_tools.html.erb_spec.rb +6 -6
  366. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +1 -2
  367. data/spec/views/catalog/_sort_widget.html.erb_spec.rb +3 -1
  368. data/spec/views/catalog/{_thumbnail_default.erb_spec.rb → _thumbnail.html.erb_spec.rb} +7 -9
  369. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +12 -10
  370. data/spec/views/catalog/email_success.html.erb_spec.rb +8 -0
  371. data/spec/views/catalog/facet.html.erb_spec.rb +4 -3
  372. data/spec/views/catalog/facet.json.jbuilder_spec.rb +3 -2
  373. data/spec/views/catalog/index.atom.builder_spec.rb +11 -6
  374. data/spec/views/catalog/index.html.erb_spec.rb +6 -8
  375. data/spec/views/catalog/index.json.jbuilder_spec.rb +119 -26
  376. data/spec/views/catalog/opensearch.xml.builder_spec.rb +1 -1
  377. data/spec/views/catalog/show.html.erb_spec.rb +8 -8
  378. data/spec/views/catalog/show.json.jbuilder_spec.rb +40 -0
  379. data/spec/views/catalog/sms_success.html.erb_spec.rb +8 -0
  380. data/spec/views/{_user_util_links.html.erb_spec.rb → shared/_user_util_links.html.erb_spec.rb} +4 -7
  381. data/tasks/blacklight.rake +9 -12
  382. data/template.demo.rb +4 -12
  383. metadata +178 -218
  384. data/app/assets/javascripts/blacklight/autofocus.js +0 -16
  385. data/app/assets/javascripts/blacklight/bookmark_toggle.js +0 -23
  386. data/app/assets/javascripts/blacklight/checkbox_submit.js +0 -139
  387. data/app/assets/javascripts/blacklight/collapsable.js +0 -9
  388. data/app/assets/javascripts/blacklight/core.js +0 -30
  389. data/app/assets/javascripts/blacklight/facet_load.js +0 -23
  390. data/app/assets/javascripts/blacklight/search_context.js +0 -42
  391. data/app/controllers/concerns/blacklight/request_builders.rb +0 -77
  392. data/app/controllers/concerns/blacklight/saved_searches.rb +0 -70
  393. data/app/controllers/concerns/blacklight/search_helper.rb +0 -161
  394. data/app/controllers/concerns/blacklight/suggest.rb +0 -25
  395. data/app/controllers/saved_searches_controller.rb +0 -4
  396. data/app/controllers/suggest_controller.rb +0 -4
  397. data/app/helpers/blacklight/deprecated_url_helper_behavior.rb +0 -57
  398. data/app/helpers/blacklight/render_partials_helper.rb +0 -205
  399. data/app/helpers/blacklight_configuration_helper.rb +0 -4
  400. data/app/helpers/blacklight_url_helper.rb +0 -4
  401. data/app/helpers/component_helper.rb +0 -4
  402. data/app/helpers/facets_helper.rb +0 -4
  403. data/app/helpers/hash_as_hidden_fields_helper.rb +0 -4
  404. data/app/helpers/layout_helper.rb +0 -4
  405. data/app/helpers/render_constraints_helper.rb +0 -4
  406. data/app/helpers/search_history_constraints_helper.rb +0 -4
  407. data/app/helpers/suggest_helper.rb +0 -4
  408. data/app/models/concerns/blacklight/solr/document/more_like_this.rb +0 -6
  409. data/app/views/_user_util_links.html.erb +0 -26
  410. data/app/views/blacklight/nav/_saved_searches.html.erb +0 -1
  411. data/app/views/catalog/_index_default.html.erb +0 -12
  412. data/app/views/catalog/_show_default.html.erb +0 -10
  413. data/app/views/catalog/_thumbnail_default.html.erb +0 -5
  414. data/app/views/saved_searches/index.html.erb +0 -32
  415. data/app/views/shared/_ajax_modal.html.erb +0 -6
  416. data/lib/generators/blacklight/solr4_generator.rb +0 -31
  417. data/lib/generators/blacklight/templates/config/jetty.yml +0 -13
  418. data/solr/conf/schema.xml +0 -629
  419. data/solr/conf/solrconfig.xml +0 -411
  420. data/spec/controllers/blacklight/search_helper_spec.rb +0 -489
  421. data/spec/controllers/saved_searches_controller_spec.rb +0 -32
  422. data/spec/controllers/suggest_controller_spec.rb +0 -17
  423. data/spec/features/saved_searches_spec.rb +0 -47
  424. data/spec/helpers/deprecated_url_helper_behavior_spec.rb +0 -101
  425. data/spec/lib/blacklight/utils_spec.rb +0 -167
  426. data/spec/models/blacklight/solr/document/more_like_this_spec.rb +0 -18
  427. data/spec/presenters/document_presenter_spec.rb +0 -438
  428. data/spec/support/backport_test.rb +0 -14
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Blacklight::ThumbnailPresenter do
4
+ include Capybara::RSpecMatchers
5
+ let(:view_context) { double "View context" }
6
+ let(:config) { Blacklight::Configuration.new.view_config(:index) }
7
+ let(:presenter) { described_class.new(document, view_context, config) }
8
+ let(:document) { SolrDocument.new }
9
+
10
+ describe "#exists?" do
11
+ subject { presenter.exists? }
12
+
13
+ context "when thumbnail_method is configured" do
14
+ let(:config) do
15
+ Blacklight::OpenStructWithHashAccess.new(thumbnail_method: :xyz)
16
+ end
17
+
18
+ it { is_expected.to be true }
19
+ end
20
+
21
+ context "when thumbnail_field is configured as a single field" do
22
+ let(:config) do
23
+ Blacklight::OpenStructWithHashAccess.new(thumbnail_field: :xyz)
24
+ end
25
+
26
+ context "and the field exists in the document" do
27
+ let(:document) { SolrDocument.new('xyz' => 'image.png') }
28
+
29
+ it { is_expected.to be true }
30
+ end
31
+
32
+ context "and the field is missing from the document" do
33
+ it { is_expected.to be false }
34
+ end
35
+ end
36
+
37
+ context "when thumbnail_field is configured as an array of fields" do
38
+ let(:config) do
39
+ Blacklight::OpenStructWithHashAccess.new(thumbnail_field: [:rst, :uvw, :xyz])
40
+ end
41
+
42
+ context "and the field exists in the document" do
43
+ let(:document) { SolrDocument.new('xyz' => 'image.png') }
44
+
45
+ it { is_expected.to be true }
46
+ end
47
+ end
48
+
49
+ context "when default_thumbnail is configured" do
50
+ let(:config) do
51
+ Blacklight::OpenStructWithHashAccess.new(default_thumbnail: 'image.png')
52
+ end
53
+
54
+ context "and the field exists in the document" do
55
+ it { is_expected.to be true }
56
+ end
57
+ end
58
+
59
+ context "without any configured options" do
60
+ it { is_expected.to be_falsey }
61
+ end
62
+ end
63
+
64
+ describe "#thumbnail_tag" do
65
+ subject { presenter.thumbnail_tag }
66
+
67
+ context "when thumbnail_method is configured" do
68
+ let(:config) do
69
+ Blacklight::OpenStructWithHashAccess.new(thumbnail_method: :xyz)
70
+ end
71
+
72
+ context "and the method returns a value" do
73
+ before do
74
+ allow(view_context).to receive_messages(xyz: "some-thumbnail")
75
+ end
76
+
77
+ it "calls the provided thumbnail method" do
78
+ expect(view_context).to receive_messages(xyz: "some-thumbnail")
79
+ allow(view_context).to receive(:link_to_document).with(document, "some-thumbnail", {})
80
+ .and_return("link")
81
+ expect(subject).to eq "link"
82
+ end
83
+
84
+ context "and url options have :suppress_link" do
85
+ subject { presenter.thumbnail_tag({}, suppress_link: true) }
86
+
87
+ it "does not link to the document" do
88
+ expect(subject).to eq "some-thumbnail"
89
+ end
90
+ end
91
+ end
92
+
93
+ context "and no value is returned from the thumbnail method" do
94
+ before do
95
+ allow(view_context).to receive_messages(xyz: nil)
96
+ end
97
+
98
+ it { is_expected.to be nil }
99
+ end
100
+ end
101
+
102
+ context "when thumbnail_field is configured" do
103
+ let(:config) do
104
+ Blacklight::OpenStructWithHashAccess.new(thumbnail_field: :xyz)
105
+ end
106
+
107
+ it "creates an image tag from the given field" do
108
+ allow(document).to receive(:first).with(:xyz).and_return("http://example.com/some.jpg")
109
+ allow(view_context).to receive(:image_tag).with("http://example.com/some.jpg", {}).and_return('<img src="image.jpg">')
110
+ expect(view_context).to receive(:link_to_document).with(document, '<img src="image.jpg">', {})
111
+ subject
112
+ end
113
+
114
+ it "returns nil if no thumbnail is in the document" do
115
+ allow(document).to receive(:first).with(:xyz).and_return(nil)
116
+ expect(subject).to be_nil
117
+ end
118
+ end
119
+
120
+ context "when thumbnail_field is configured as an array of fields" do
121
+ let(:config) do
122
+ Blacklight::OpenStructWithHashAccess.new(thumbnail_field: [:rst, :uvw, :xyz])
123
+ end
124
+
125
+ context "and the field exists in the document" do
126
+ let(:document) { SolrDocument.new(xyz: 'http://example.com/some.jpg') }
127
+
128
+ it "creates an image tag from the given field" do
129
+ allow(view_context).to receive(:image_tag).with("http://example.com/some.jpg", {}).and_return('<img src="image.jpg">')
130
+ expect(view_context).to receive(:link_to_document).with(document, '<img src="image.jpg">', {}).and_return('<a><img></a>')
131
+ expect(presenter.thumbnail_tag).to eq '<a><img></a>'
132
+ end
133
+ end
134
+ end
135
+
136
+ context "when default_thumbnail is configured" do
137
+ context "and is a string" do
138
+ let(:config) do
139
+ Blacklight::OpenStructWithHashAccess.new(default_thumbnail: 'image.png')
140
+ end
141
+
142
+ it "creates an image tag for the given asset" do
143
+ allow(view_context).to receive(:image_tag).with('image.png', {}).and_return('<img src="image.jpg">')
144
+ expect(presenter.thumbnail_tag({}, suppress_link: true)).to eq '<img src="image.jpg">'
145
+ end
146
+ end
147
+
148
+ context "and is a symbol" do
149
+ let(:config) do
150
+ Blacklight::OpenStructWithHashAccess.new(default_thumbnail: :get_a_default_thumbnail)
151
+ end
152
+
153
+ it "calls that helper method" do
154
+ allow(view_context).to receive(:get_a_default_thumbnail).with(document, {}).and_return('<img src="image.jpg">')
155
+ expect(presenter.thumbnail_tag({}, suppress_link: true)).to eq '<img src="image.jpg">'
156
+ end
157
+ end
158
+
159
+ context "and is a proc" do
160
+ let(:config) do
161
+ Blacklight::OpenStructWithHashAccess.new(default_thumbnail: ->(_, _) { '<img src="image.jpg">' })
162
+ end
163
+
164
+ it "calls that lambda" do
165
+ expect(presenter.thumbnail_tag({}, suppress_link: true)).to eq '<img src="image.jpg">'
166
+ end
167
+ end
168
+ end
169
+
170
+ context "when no thumbnail is configured" do
171
+ it { is_expected.to be_nil }
172
+ end
173
+ end
174
+ end
@@ -1,70 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
- describe "Routing" do
4
+ RSpec.describe "Routing" do
5
5
  describe "Paths Generated by Custom Routes:" do
6
6
  # paths generated by custom routes
7
7
  it "has a path for showing the email form" do
8
- expect(:get => "/catalog/email").to route_to(:controller => 'catalog', :action => 'email')
8
+ expect(get: "/catalog/email").to route_to(controller: 'catalog', action: 'email')
9
9
  end
10
10
  it "has a path for sending the email" do
11
- expect(:post => "/catalog/email").to route_to(:controller => 'catalog', :action => 'email')
11
+ expect(post: "/catalog/email").to route_to(controller: 'catalog', action: 'email')
12
12
  end
13
13
  it "maps GET {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do
14
- expect(:get => "/catalog/sms").to route_to(:controller => 'catalog', :action => 'sms')
14
+ expect(get: "/catalog/sms").to route_to(controller: 'catalog', action: 'sms')
15
15
  end
16
16
  it "maps POST {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do
17
- expect(:post => "/catalog/sms").to route_to(:controller => 'catalog', :action => 'sms')
17
+ expect(post: "/catalog/sms").to route_to(controller: 'catalog', action: 'sms')
18
18
  end
19
19
  it "maps { :controller => 'catalog', :action => 'show', :id => 666 } to /catalog/666" do
20
- expect(:get => "/catalog/666").to route_to(:controller => 'catalog', :action => 'show', :id => "666")
20
+ expect(get: "/catalog/666").to route_to(controller: 'catalog', action: 'show', id: "666")
21
21
  end
22
22
  end
23
23
 
24
- describe 'tracking' do
25
- context 'when the routing constraint is set to allow periods' do
26
- before do
27
- if Rails.version < '5.2.0'
28
- skip 'requires https://github.com/rails/rails/pull/22435'
29
- end
30
- allow(Blacklight::Engine.config.routes).to receive(:identifier_constraint).and_return(%r{[^/]+})
31
- Rails.application.reload_routes!
32
- end
33
-
34
- it 'routes to #track' do
35
- expect(post('/catalog/gallica.bnf.fr/track')).to route_to('catalog#track', id: 'gallica.bnf.fr')
36
- end
37
- end
38
- end
39
-
40
-
41
- describe "solr_document_path for SolrDocument", :test => true do
24
+ describe "solr_document_path for SolrDocument", test: true do
42
25
  it "routes correctly" do
43
- expect(:get => solr_document_path(SolrDocument.new(:id => 'asdf'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'asdf')
26
+ expect(get: solr_document_path(SolrDocument.new(id: 'asdf'))).to route_to(controller: 'catalog', action: 'show', id: 'asdf')
44
27
  end
45
28
 
46
29
  context "should escape solr document ids" do
47
-
48
30
  it "pass-throughs url-valid ids" do
49
- expect(:get => solr_document_path(SolrDocument.new(:id => 'qwerty'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'qwerty')
31
+ expect(get: solr_document_path(SolrDocument.new(id: 'qwerty'))).to route_to(controller: 'catalog', action: 'show', id: 'qwerty')
50
32
  end
51
33
 
52
34
  it "routes url-like ids" do
53
35
  skip "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
54
- expect(:get => solr_document_path(SolrDocument.new(:id => 'http://example.com'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'http://example.com')
36
+ expect(get: solr_document_path(SolrDocument.new(id: 'http://example.com'))).to route_to(controller: 'catalog', action: 'show', id: 'http://example.com')
55
37
  end
56
38
 
57
39
  it "routes ids with whitespace" do
58
- expect(:get => solr_document_path(SolrDocument.new(:id => 'mm 123'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'mm 123')
40
+ expect(get: solr_document_path(SolrDocument.new(id: 'mm 123'))).to route_to(controller: 'catalog', action: 'show', id: 'mm 123')
59
41
  end
60
42
 
61
43
  it "routes ids with a literal '+'" do
62
- expect(:get => solr_document_path(SolrDocument.new(:id => 'this+that'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'this+that')
44
+ expect(get: solr_document_path(SolrDocument.new(id: 'this+that'))).to route_to(controller: 'catalog', action: 'show', id: 'this+that')
63
45
  end
64
46
 
65
47
  it "routes ids with a literal '/" do
66
48
  skip "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
67
- expect(:get => solr_document_path(SolrDocument.new(:id => 'and/or'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'and/or')
49
+ expect(get: solr_document_path(SolrDocument.new(id: 'and/or'))).to route_to(controller: 'catalog', action: 'show', id: 'and/or')
68
50
  end
69
51
  end
70
52
  end
@@ -0,0 +1,495 @@
1
+ # frozen_string_literal: true
2
+
3
+ # check the methods that do solr requests. Note that we are not testing if
4
+ # solr gives "correct" responses, as that's out of scope (it's a part of
5
+ # testing the solr code itself). We *are* testing if blacklight code sends
6
+ # queries to solr such that it gets appropriate results. When a user does a search,
7
+ # do we get data back from solr (i.e. did we properly configure blacklight code
8
+ # to talk with solr and get results)? when we do a document request, does
9
+ # blacklight code get a single document returned?)
10
+ #
11
+ RSpec.describe Blacklight::SearchService, api: true do
12
+ subject { service }
13
+
14
+ let(:context) { { whatever: :value } }
15
+ let(:service) { described_class.new(config: blacklight_config, user_params: user_params, **context) }
16
+ let(:repository) { Blacklight::Solr::Repository.new(blacklight_config) }
17
+ let(:user_params) { {} }
18
+
19
+ let(:blacklight_config) { Blacklight::Configuration.new }
20
+ let(:copy_of_catalog_config) { ::CatalogController.blacklight_config.deep_copy }
21
+ let(:blacklight_solr) { RSolr.connect(Blacklight.connection_config.except(:adapter)) }
22
+
23
+ let(:all_docs_query) { '' }
24
+ let(:no_docs_query) { 'zzzzzzzzzzzz' }
25
+ # f[format][]=Book&f[language_facet][]=English
26
+ let(:single_facet) { { format: 'Book' } }
27
+
28
+ before do
29
+ allow(service).to receive(:repository).and_return(repository)
30
+ service.repository.connection = blacklight_solr
31
+ end
32
+
33
+ describe '#search_builder_class' do
34
+ subject { service.send(:search_builder_class) }
35
+
36
+ it 'defaults to the value in the config' do
37
+ expect(subject).to eq SearchBuilder
38
+ end
39
+
40
+ context 'when the search_builder_class is passed in' do
41
+ let(:klass) { double("Search builder") }
42
+
43
+ let(:service) { described_class.new(config: blacklight_config, user_params: user_params, search_builder_class: klass) }
44
+
45
+ it 'uses the passed value' do
46
+ expect(subject).to eq klass
47
+ end
48
+ end
49
+ end
50
+
51
+ # SPECS FOR SEARCH RESULTS FOR QUERY
52
+ describe 'Search Results', integration: true do
53
+ let(:blacklight_config) { copy_of_catalog_config }
54
+
55
+ describe 'for a sample query returning results' do
56
+ let(:user_params) { { q: all_docs_query } }
57
+
58
+ before do
59
+ (@solr_response, @document_list) = service.search_results
60
+ end
61
+
62
+ it "uses the configured request handler" do
63
+ allow(blacklight_config).to receive(:default_solr_params).and_return(qt: 'custom_request_handler')
64
+ allow(blacklight_solr).to receive(:send_and_receive) do |path, params|
65
+ expect(path).to eq 'select'
66
+ expect(params[:params]['facet.field']).to eq ["format", "{!ex=pub_date_ssim_single}pub_date_ssim", "subject_ssim", "language_ssim", "lc_1letter_ssim", "subject_geo_ssim", "subject_era_ssim"]
67
+ expect(params[:params]["facet.query"]).to eq ["pub_date_ssim:[#{5.years.ago.year} TO *]", "pub_date_ssim:[#{10.years.ago.year} TO *]", "pub_date_ssim:[#{25.years.ago.year} TO *]"]
68
+ expect(params[:params]).to include('rows' => 10, 'qt' => "custom_request_handler", 'q' => "", "f.subject_ssim.facet.limit" => 21, 'sort' => "score desc, pub_date_si desc, title_si asc")
69
+ end.and_return('response' => { 'docs' => [] })
70
+ service.search_results
71
+ end
72
+
73
+ it 'has a @response.docs list of the same size as @document_list' do
74
+ expect(@solr_response.docs).to have(@document_list.length).docs
75
+ end
76
+
77
+ it 'has @response.docs list representing same documents as SolrDocuments in @document_list' do
78
+ @solr_response.docs.each_index do |index|
79
+ mash = @solr_response.docs[index]
80
+ solr_document = @document_list[index]
81
+
82
+ expect(Set.new(mash.keys)).to eq Set.new(solr_document.keys)
83
+
84
+ mash.keys.each do |key|
85
+ expect(mash[key]).to eq solr_document[key]
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "for a query returning a grouped response" do
92
+ let(:blacklight_config) { copy_of_catalog_config }
93
+ let(:user_params) { { q: all_docs_query } }
94
+
95
+ before do
96
+ blacklight_config.default_solr_params[:group] = true
97
+ blacklight_config.default_solr_params[:'group.field'] = 'pub_date_si'
98
+ (@solr_response, @document_list) = service.search_results
99
+ end
100
+
101
+ it "returns a grouped response" do
102
+ expect(@document_list).to be_empty
103
+ expect(@solr_response).to be_a_kind_of Blacklight::Solr::Response::GroupResponse
104
+ end
105
+ end
106
+
107
+ describe "for a query returning multiple groups", integration: true do
108
+ let(:blacklight_config) { copy_of_catalog_config }
109
+ let(:user_params) { { q: all_docs_query } }
110
+
111
+ before do
112
+ allow(subject).to receive_messages grouped_key_for_results: 'title_si'
113
+ blacklight_config.default_solr_params[:group] = true
114
+ blacklight_config.default_solr_params[:'group.field'] = %w[pub_date_si title_si]
115
+ (@solr_response, @document_list) = service.search_results
116
+ end
117
+
118
+ it "returns a grouped response" do
119
+ expect(@document_list).to be_empty
120
+ expect(@solr_response).to be_a_kind_of Blacklight::Solr::Response::GroupResponse
121
+ expect(@solr_response.group_field).to eq "title_si"
122
+ end
123
+ end
124
+
125
+ describe "for All Docs Query and One Facet" do
126
+ let(:user_params) { { q: all_docs_query, f: single_facet } }
127
+
128
+ it 'has results' do
129
+ (solr_response, document_list) = service.search_results
130
+ expect(solr_response.docs).to have(document_list.size).results
131
+ expect(solr_response.docs).to have_at_least(1).result
132
+ end
133
+ # TODO: check that number of these results < number of results for all docs query
134
+ # BUT can't: num docs isn't total, it's the num docs in the single SOLR response (e.g. 10)
135
+ end
136
+
137
+ describe "for Query Without Results and No Facet" do
138
+ let(:user_params) { { q: no_docs_query } }
139
+
140
+ it 'has no results and not raise error' do
141
+ (solr_response, document_list) = service.search_results
142
+ expect(document_list).to have(0).results
143
+ expect(solr_response.docs).to have(0).results
144
+ end
145
+ end
146
+
147
+ describe "for Query Without Results and One Facet" do
148
+ let(:user_params) { { q: no_docs_query, f: single_facet } }
149
+
150
+ it 'has no results and not raise error' do
151
+ (solr_response, document_list) = service.search_results
152
+ expect(document_list).to have(0).results
153
+ expect(solr_response.docs).to have(0).results
154
+ end
155
+ end
156
+
157
+ describe "for All Docs Query and Bad Facet" do
158
+ let(:bad_facet) { { format: '666' } }
159
+ let(:user_params) { { q: all_docs_query, f: bad_facet } }
160
+
161
+ it 'has no results and not raise error' do
162
+ (solr_response, document_list) = service.search_results
163
+ expect(document_list).to have(0).results
164
+ expect(solr_response.docs).to have(0).results
165
+ end
166
+ end
167
+ end # Search Results
168
+
169
+ # SPECS FOR SEARCH RESULTS FOR FACETS
170
+ describe 'Facets in Search Results for All Docs Query', integration: true do
171
+ let(:blacklight_config) { copy_of_catalog_config }
172
+ let(:user_params) { { q: all_docs_query } }
173
+
174
+ before do
175
+ (solr_response,) = service.search_results
176
+ @facets = solr_response.aggregations
177
+ end
178
+
179
+ it 'has more than one facet' do
180
+ expect(@facets).to have_at_least(1).facet
181
+ end
182
+ it 'has all facets specified in initializer' do
183
+ expect(@facets.keys).to include *blacklight_config.facet_fields.keys
184
+ expect(@facets.none? { |_k, v| v.nil? }).to eq true
185
+ end
186
+
187
+ it 'has at least one value for each facet' do
188
+ @facets.each do |_key, facet|
189
+ expect(facet.items).to have_at_least(1).hit
190
+ end
191
+ end
192
+ it 'has multiple values for at least one facet' do
193
+ has_mult_values = false
194
+ @facets.each do |_key, facet|
195
+ if facet.items.size > 1
196
+ has_mult_values = true
197
+ break
198
+ end
199
+ end
200
+ expect(has_mult_values).to eq true
201
+ end
202
+ it 'has all value counts > 0' do
203
+ @facets.each do |_key, facet|
204
+ facet.items.each do |facet_vals|
205
+ expect(facet_vals.hits).to be > 0
206
+ end
207
+ end
208
+ end
209
+ end # facet specs
210
+
211
+ # SPECS FOR SEARCH RESULTS FOR PAGING
212
+ describe 'Paging', integration: true do
213
+ let(:blacklight_config) { copy_of_catalog_config }
214
+ let(:user_params) { { q: all_docs_query } }
215
+
216
+ it 'starts with first results by default' do
217
+ (solr_response,) = service.search_results
218
+ expect(solr_response.params[:start].to_i).to eq 0
219
+ end
220
+ it 'has number of results (per page) set in initializer, by default' do
221
+ (solr_response, document_list) = service.search_results
222
+ expect(solr_response.docs).to have(blacklight_config[:default_solr_params][:rows]).items
223
+ expect(document_list).to have(blacklight_config[:default_solr_params][:rows]).items
224
+ end
225
+
226
+ context "with per page requested" do
227
+ let(:user_params) { { q: all_docs_query, per_page: num_results } }
228
+ let(:num_results) { 3 } # non-default value
229
+
230
+ it 'gets number of results per page requested' do
231
+ (solr_response1, document_list1) = service.search_results
232
+ expect(document_list1).to have(num_results).docs
233
+ expect(solr_response1.docs).to have(num_results).docs
234
+ end
235
+ end
236
+
237
+ context "with rows requested" do
238
+ let(:user_params) { { q: all_docs_query, rows: num_results } }
239
+ let(:num_results) { 4 } # non-default value
240
+
241
+ it 'gets number of rows requested' do
242
+ (solr_response1, document_list1) = service.search_results
243
+ expect(document_list1).to have(num_results).docs
244
+ expect(solr_response1.docs).to have(num_results).docs
245
+ end
246
+ end
247
+
248
+ context "with page requested" do
249
+ let(:user_params) { { q: all_docs_query, page: page } }
250
+ let(:page) { 3 }
251
+
252
+ it 'skips appropriate number of results when requested - default per page' do
253
+ (solr_response2,) = service.search_results
254
+ expect(solr_response2.params[:start].to_i).to eq blacklight_config[:default_solr_params][:rows] * (page - 1)
255
+ end
256
+ end
257
+
258
+ context "with page and num_results requested" do
259
+ let(:user_params) { { q: all_docs_query, page: page, per_page: num_results } }
260
+ let(:page) { 3 }
261
+ let(:num_results) { 3 } # non-default value
262
+
263
+ it 'skips appropriate number of results when requested - non-default per page' do
264
+ num_results = 3
265
+ (solr_response2a,) = service.search_results
266
+ expect(solr_response2a.params[:start].to_i).to eq num_results * (page - 1)
267
+ end
268
+ end
269
+
270
+ context "with page and num_results requested" do
271
+ let(:page) { 5000 }
272
+ let(:rows) { 5000 }
273
+ let(:user_params) { { q: all_docs_query, page: page, rows: rows } }
274
+
275
+ it 'has no results when prompted for page after last result' do
276
+ (solr_response3, document_list3) = service.search_results
277
+ expect(document_list3).to have(0).docs
278
+ expect(solr_response3.docs).to have(0).docs
279
+ end
280
+ end
281
+
282
+ context "with negative page" do
283
+ let(:page) { '-1' }
284
+ let(:user_params) { { q: all_docs_query, page: page } }
285
+
286
+ it 'shows first results when prompted for page before first result' do
287
+ # FIXME: should it show first results, or should it throw an error for view to deal w?
288
+ # Solr throws an error for a negative start value
289
+ (solr_response4,) = service.search_results
290
+ expect(solr_response4.params[:start].to_i).to eq 0
291
+ end
292
+ end
293
+
294
+ context "when asking for more rows than are in the reponse" do
295
+ let(:page) { 1 }
296
+ let(:rows) { 5000 }
297
+ let(:user_params) { { q: all_docs_query, page: page, rows: rows } }
298
+
299
+ it 'has results available when asked for more than are in response' do
300
+ (solr_response5, document_list5) = service.search_results
301
+ expect(solr_response5.docs).to have(document_list5.length).docs
302
+ expect(solr_response5.docs).to have_at_least(1).doc
303
+ end
304
+ end
305
+ end # page specs
306
+
307
+ # SPECS FOR SINGLE DOCUMENT REQUESTS
308
+ describe 'Get Document By Id', integration: true do
309
+ let(:doc_id) { '2007020969' }
310
+ let(:bad_id) { 'redrum' }
311
+
312
+ before do
313
+ @response2, @document = service.fetch(doc_id)
314
+ end
315
+
316
+ it "raises Blacklight::RecordNotFound for an unknown id" do
317
+ expect do
318
+ service.fetch(bad_id)
319
+ end.to raise_error(Blacklight::Exceptions::RecordNotFound)
320
+ end
321
+
322
+ it "has a non-nil result for a known id" do
323
+ expect(@document).not_to be_nil
324
+ end
325
+ it "has a single document in the response for a known id" do
326
+ expect(@response2.docs.size).to eq 1
327
+ end
328
+ it 'has the expected value in the id field' do
329
+ expect(@document.id).to eq doc_id
330
+ end
331
+ it 'has non-nil values for required fields set in initializer' do
332
+ expect(@document.fetch(blacklight_config.view_config(:show).display_type_field)).not_to be_nil
333
+ end
334
+ end
335
+
336
+ describe 'Get multiple documents By Id', integration: true do
337
+ let(:doc_id) { '2007020969' }
338
+ let(:bad_id) { 'redrum' }
339
+ let(:response) { service.fetch([doc_id]).first }
340
+
341
+ before do
342
+ blacklight_config.fetch_many_document_params[:fl] = 'id,format'
343
+ end
344
+
345
+ it 'has the expected value in the id field' do
346
+ expect(response.documents.first.id).to eq doc_id
347
+ end
348
+
349
+ it 'returns all the requested fields' do
350
+ expect(response.documents.first['format']).to eq ['Book']
351
+ end
352
+ end
353
+
354
+ # SPECS FOR SPELLING SUGGESTIONS VIA SEARCH
355
+ describe "Searches should return spelling suggestions", integration: true do
356
+ context "for just-poor-enough-query term" do
357
+ let(:user_params) { { q: 'boo' } }
358
+
359
+ it 'has (multiple) spelling suggestions' do
360
+ (solr_response,) = service.search_results
361
+ expect(solr_response.spelling.words).to include('bon')
362
+ expect(solr_response.spelling.words).to include('bod') # for multiple suggestions
363
+ end
364
+ end
365
+
366
+ context "for another just-poor-enough-query term" do
367
+ let(:user_params) { { q: 'politica' } }
368
+
369
+ it 'has multiple spelling suggestions' do
370
+ (solr_response,) = service.search_results
371
+ expect(solr_response.spelling.words).to include('policy') # less freq
372
+ expect(solr_response.spelling.words).to include('politics') # more freq
373
+ expect(solr_response.spelling.words).to include('political') # more freq
374
+ # # when we can have multiple suggestions
375
+ # expect(solr_response.spelling.words).to_not include('policy') # less freq
376
+ # solr_response.spelling.words).to include('politics') # more freq
377
+ # solr_response.spelling.words).to include('political') # more freq
378
+ end
379
+ end
380
+
381
+ context "for title search" do
382
+ let(:user_params) { { q: 'yehudiyam', qt: 'search', "spellcheck.dictionary": "title" } }
383
+
384
+ it 'has spelling suggestions' do
385
+ (solr_response,) = service.search_results
386
+ expect(solr_response.spelling.words).to include('yehudiyim')
387
+ end
388
+ end
389
+
390
+ context "for author search" do
391
+ let(:user_params) { { q: 'shirma', qt: 'search', "spellcheck.dictionary": "author" } }
392
+
393
+ it 'has spelling suggestions' do
394
+ (solr_response,) = service.search_results
395
+ expect(solr_response.spelling.words).to include('sharma')
396
+ end
397
+ end
398
+
399
+ context "for subject search" do
400
+ let(:user_params) { { q: 'wome', qt: 'search', "spellcheck.dictionary": "subject" } }
401
+
402
+ it 'has spelling suggestions' do
403
+ (solr_response,) = service.search_results
404
+ expect(solr_response.spelling.words).to include('women')
405
+ end
406
+ end
407
+ end
408
+
409
+ # TODO: more complex queries! phrases, offset into search results, non-latin, boosting(?)
410
+ # search within query building (?)
411
+ # search + facets (search done first; facet selected first, both selected)
412
+
413
+ # TODO: maybe eventually check other types of solr requests
414
+ # more like this
415
+ # nearby on shelf
416
+ it "raises a Blacklight exception if RSolr can't connect to the Solr instance" do
417
+ allow(blacklight_solr).to receive(:send_and_receive).and_raise(Errno::ECONNREFUSED)
418
+ expect { service.repository.search }.to raise_exception(/Unable to connect to Solr instance/)
419
+ end
420
+
421
+ describe "#previous_and_next_documents_for_search" do
422
+ let(:user_params) { { q: '', per_page: 100 } }
423
+
424
+ before do
425
+ @full_response, @all_docs = service.search_results
426
+ end
427
+
428
+ it "returns the previous and next documents for a search" do
429
+ _response, docs = service.previous_and_next_documents_for_search(4, q: '')
430
+
431
+ expect(docs.first.id).to eq @all_docs[3].id
432
+ expect(docs.last.id).to eq @all_docs[5].id
433
+ end
434
+
435
+ it "returns only the next document if the counter is 0" do
436
+ _response, docs = service.previous_and_next_documents_for_search(0, q: '')
437
+
438
+ expect(docs.first).to be_nil
439
+ expect(docs.last.id).to eq @all_docs[1].id
440
+ end
441
+
442
+ it "returns only the previous document if the counter is the total number of documents" do
443
+ _response, docs = service.previous_and_next_documents_for_search(@full_response.total - 1, q: '')
444
+ expect(docs.first.id).to eq @all_docs.slice(-2).id
445
+ expect(docs.last).to be_nil
446
+ end
447
+
448
+ it "returns an array of nil values if there is only one result" do
449
+ _response, docs = service.previous_and_next_documents_for_search(0, q: 'id:2007020969')
450
+ expect(docs.last).to be_nil
451
+ expect(docs.first).to be_nil
452
+ end
453
+
454
+ it 'returns only the unique key by default' do
455
+ _response, docs = service.previous_and_next_documents_for_search(0, q: '')
456
+ expect(docs.last.to_h).to eq 'id' => @all_docs[1].id
457
+ end
458
+
459
+ it 'allows the query parameters to be customized using configuration' do
460
+ blacklight_config.document_pagination_params[:fl] = 'id,format'
461
+
462
+ _response, docs = service.previous_and_next_documents_for_search(0, q: '')
463
+
464
+ expect(docs.last.to_h).to eq @all_docs[1].to_h.slice('id', 'format')
465
+ end
466
+ end
467
+
468
+ describe '#opensearch_response' do
469
+ let(:user_params) { { q: 'Book' } }
470
+ let(:mock_response) do
471
+ instance_double(Blacklight::Solr::Response, documents: [
472
+ { field: 'A' }, { field: 'B' }, { field: 'C' }
473
+ ])
474
+ end
475
+
476
+ before do
477
+ blacklight_config.view.opensearch.title_field = :field
478
+ allow(repository).to receive(:search).and_return(mock_response)
479
+ end
480
+
481
+ it 'contains the original user query as the first element in the response' do
482
+ expect(service.opensearch_response.first).to eq 'Book'
483
+ end
484
+
485
+ it 'contains the search suggestions as the second element in the response' do
486
+ expect(service.opensearch_response.last).to match_array %w[A B C]
487
+ end
488
+ end
489
+
490
+ describe '#context' do
491
+ it 'has a context attribute' do
492
+ expect(subject.context).to eq context
493
+ end
494
+ end
495
+ end