blacklight 5.13.1 → 5.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -0
  3. data/.rubocop_todo.yml +5 -0
  4. data/VERSION +1 -1
  5. data/app/assets/stylesheets/blacklight/_header.scss +1 -2
  6. data/app/helpers/blacklight/facets_helper_behavior.rb +16 -2
  7. data/app/helpers/blacklight/url_helper_behavior.rb +5 -2
  8. data/app/views/catalog/_facet_pagination.html.erb +2 -2
  9. data/config/locales/blacklight.fr.yml +0 -10
  10. data/config/locales/blacklight.it.yml +226 -0
  11. data/config/locales/blacklight.pt-BR.yml +0 -22
  12. data/lib/blacklight/configuration.rb +10 -5
  13. data/lib/blacklight/document.rb +2 -0
  14. data/lib/blacklight/document/cache_key.rb +23 -0
  15. data/lib/blacklight/facet.rb +13 -16
  16. data/lib/blacklight/rails/routes.rb +1 -1
  17. data/lib/blacklight/request_builders.rb +6 -30
  18. data/lib/blacklight/search_builder.rb +13 -0
  19. data/lib/blacklight/search_helper.rb +2 -2
  20. data/lib/blacklight/solr.rb +0 -2
  21. data/lib/blacklight/solr/search_builder.rb +2 -1
  22. data/lib/blacklight/solr/search_builder_behavior.rb +42 -1
  23. data/lib/blacklight/solr_response/facets.rb +2 -1
  24. data/spec/helpers/facets_helper_spec.rb +32 -9
  25. data/spec/lib/blacklight/configuration_spec.rb +30 -7
  26. data/spec/lib/blacklight/document/cache_key_spec.rb +48 -0
  27. data/spec/lib/blacklight/facet_spec.rb +1 -1
  28. data/spec/lib/blacklight/search_builder_spec.rb +11 -1
  29. data/spec/lib/blacklight/search_helper_spec.rb +0 -72
  30. data/spec/lib/blacklight/solr/search_builder_spec.rb +65 -1
  31. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +0 -11
  32. metadata +7 -10
  33. data/app/assets/images/blacklight/bg.png +0 -0
  34. data/app/assets/images/blacklight/border.png +0 -0
  35. data/app/assets/images/blacklight/bul_sq_gry.gif +0 -0
  36. data/app/assets/images/blacklight/checkmark.gif +0 -0
  37. data/app/assets/images/blacklight/magnifying_glass.gif +0 -0
  38. data/app/assets/images/blacklight/remove.gif +0 -0
  39. data/app/assets/images/blacklight/separator.gif +0 -0
  40. data/app/assets/images/blacklight/start_over.gif +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa14f9dfd9ac0a4e26d1905608d59f8e992bcae3
4
- data.tar.gz: e8cdf5a5a230634dfb787292d83dcf00da17e60d
3
+ metadata.gz: 155a3451e8e922400f8c30a67dd298471dd7c176
4
+ data.tar.gz: 70525a0b4e6393a968af18a813f05221b691d921
5
5
  SHA512:
6
- metadata.gz: b4eba5b2e373d15fb4350ed3647489320a86f8839887ff1f72bf353c7f0988a72d3f3d1bb0906b26b1910778d28b496f0351a04f58e1294918f6a206f46119e6
7
- data.tar.gz: dc9e78e09a197f569cd54bee0e52f39dba67ff99639d35ce1c3418972d1a741c5067fae0e078b5127af3b1c48d11a44b37a417d4845ee31248bf61338264ec9c
6
+ metadata.gz: 90ce5a38742b9a880f307faaef78687bfa169cbd016af562d9824c84652d883bc19aaf59b6ed2333ea4ccdfbcf98937e394592992863bd34a20036346c942e2c
7
+ data.tar.gz: dbe00471126594db517968998e5c705bb434ae5b1f638e460c74e9ce4f36724e275411ac8ee27d43edaa808ec8e37efecd6d369c7d2e9a069f31126c94bc8205
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
data/.rubocop_todo.yml CHANGED
@@ -24,6 +24,11 @@ Lint/UnusedMethodArgument:
24
24
  Lint/UselessAssignment:
25
25
  Enabled: false
26
26
 
27
+ # Offense count: 10
28
+ # Configuration parameters: CountComments.
29
+ Metrics/ModuleLength:
30
+ Max: 212
31
+
27
32
  # Offense count: 2
28
33
  # Cop supports --auto-correct.
29
34
  # Configuration parameters: EnforcedStyle, SupportedStyles.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.13.1
1
+ 5.14.0
@@ -29,8 +29,7 @@
29
29
  border: 0;
30
30
  }
31
31
  .submit-search-text {
32
- // hide 'search' label at very small screens, magnifying glass
33
- // icon should still be there.
32
+ // hide 'search' label at very small screens
34
33
  @media screen and (max-width: $screen-xs-min ) {
35
34
  // copied from .sr-only, sadly can't seem to use @extend in a media
36
35
  // query like this, have to copy.
@@ -9,7 +9,7 @@ module Blacklight::FacetsHelperBehavior
9
9
  # @param [Hash] options
10
10
  # @return [Boolean]
11
11
  def has_facet_values? fields = facet_field_names, options = {}
12
- facets_from_request(fields).any? { |display_facet| !display_facet.items.empty? }
12
+ facets_from_request(fields).any? { |display_facet| !display_facet.items.empty? && should_render_facet?(display_facet) }
13
13
  end
14
14
 
15
15
  ##
@@ -123,12 +123,26 @@ module Blacklight::FacetsHelperBehavior
123
123
  # @option options [Boolean] :suppress_link display the facet, but don't link to it
124
124
  # @return [String]
125
125
  def render_facet_value(facet_field, item, options ={})
126
- path = search_action_path(add_facet_params_and_redirect(facet_field, item))
126
+ path = path_for_facet(facet_field, item)
127
127
  content_tag(:span, :class => "facet-label") do
128
128
  link_to_unless(options[:suppress_link], facet_display_value(facet_field, item), path, :class=>"facet_select")
129
129
  end + render_facet_count(item.hits)
130
130
  end
131
131
 
132
+ ##
133
+ # Where should this facet link to?
134
+ # @param [Blacklight::SolrResponse::Facets::FacetField]
135
+ # @param [String] facet item
136
+ # @return [String]
137
+ def path_for_facet(facet_field, item)
138
+ facet_config = facet_configuration_for_field(facet_field)
139
+ if facet_config.url_method
140
+ path = send(facet_config.url_method, facet_field, item)
141
+ else
142
+ path = search_action_path(add_facet_params_and_redirect(facet_field, item))
143
+ end
144
+ end
145
+
132
146
  ##
133
147
  # Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
134
148
  # @params (see #render_facet_value)
@@ -1,4 +1,6 @@
1
1
  require 'deprecation'
2
+ ##
3
+ # URL helper methods
2
4
  module Blacklight::UrlHelperBehavior
3
5
  extend Deprecation
4
6
  self.deprecation_horizon = 'blacklight 6.0'
@@ -255,9 +257,10 @@ module Blacklight::UrlHelperBehavior
255
257
 
256
258
  # Delete any request params from facet-specific action, needed
257
259
  # to redir to index action properly.
258
- new_params.except! *Blacklight::Solr::FacetPaginator.request_keys.values
260
+ request_keys = blacklight_config.facet_paginator_class.request_keys
261
+ new_params.except! *request_keys.values
259
262
 
260
- new_params
263
+ new_params
261
264
  end
262
265
 
263
266
  # copies the current params (or whatever is passed in as the 3rd arg)
@@ -1,8 +1,8 @@
1
1
  <div class="prev_next_links btn-group pull-left">
2
- <%= link_to_previous_page @pagination, raw(t('views.pagination.previous')), :params => params, :param_name => Blacklight::Solr::FacetPaginator.request_keys[:page], :class => 'btn btn-link', :data => {:ajax_modal => "preserve"} do %>
2
+ <%= link_to_previous_page @pagination, raw(t('views.pagination.previous')), :params => params, :param_name => blacklight_config.facet_paginator_class.request_keys[:page], :class => 'btn btn-link', :data => {:ajax_modal => "preserve"} do %>
3
3
  <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.previous')) %></span>
4
4
  <% end %>
5
- <%= link_to_next_page @pagination, raw(t('views.pagination.next')), :params => params, :param_name => Blacklight::Solr::FacetPaginator.request_keys[:page], :class => 'btn btn-link', :data => {:ajax_modal => "preserve"} do %>
5
+ <%= link_to_next_page @pagination, raw(t('views.pagination.next')), :params => params, :param_name => blacklight_config.facet_paginator_class.request_keys[:page], :class => 'btn btn-link', :data => {:ajax_modal => "preserve"} do %>
6
6
 
7
7
  <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.next')) %></span>
8
8
  <% end %>
@@ -48,16 +48,6 @@ fr:
48
48
  list_title: 'Vos favoris'
49
49
  delete: 'Supprimer'
50
50
 
51
- folder:
52
- title: 'Panier'
53
- add:
54
- success: '%{title} a bien été sélectionné.'
55
- remove:
56
- success: '%{title} a bien été supprimé.'
57
- clear:
58
- success: 'Panier vide.'
59
- no_folder: 'Votre panier est vide'
60
-
61
51
  saved_searches:
62
52
  add:
63
53
  success: 'Votre recherche a bien été sauvegardée.'
@@ -0,0 +1,226 @@
1
+ it:
2
+ views:
3
+ pagination:
4
+ first: '&laquo; Pagina iniziale'
5
+ last: 'Pagina finale &raquo;'
6
+ previous: '&laquo; Pagina precedente'
7
+ next: 'Pagina successiva &raquo;'
8
+ truncate: '…'
9
+
10
+ pagination_compact:
11
+ previous: '&laquo; Pagina precedente'
12
+ next: 'Pagina successiva &raquo;'
13
+
14
+ blacklight:
15
+ application_name: 'Blacklight'
16
+
17
+ header_links:
18
+ login: 'Login'
19
+ logout: 'Log out'
20
+ bookmarks: 'Preferiti'
21
+ saved_searches: 'Ricerche salvate'
22
+ search_history: 'Ricerche effettuate'
23
+
24
+ welcome: 'Benvenuti!'
25
+ and: 'e'
26
+ or: 'o'
27
+
28
+ bookmarks:
29
+ title: 'Preferiti'
30
+ no_bookmarks: 'Non è stato salvato nessun preferito.'
31
+ add:
32
+ button: 'Preferiti'
33
+ success:
34
+ one: 'Pagina aggiunta a preferiti.'
35
+ other: 'Pagine aggiunte a preferiti.'
36
+ failure: 'Si è verificato un errore nel salvare i preferiti.'
37
+ remove:
38
+ button: 'Togli la pagina dai preferiti'
39
+ success: 'La pagina è stata tolta dai preferiti.'
40
+ failure: 'Si è verificato un errore nel togliere la pagina dai preferiti.'
41
+ action_confirm: 'Vuoi togliere questa pagina dai preferiti?'
42
+ clear:
43
+ action_title: 'Cancella tutti i preferiti'
44
+ action_confirm: 'Vuoi cancellare tutti i preferiti?'
45
+ success: 'Tutti i preferiti sono stati cancellati.'
46
+ failure: 'Si è verificato un errore nel cancellare i preferiti.'
47
+ need_login: 'Effettuare il login per gestire e visualizzare i preferiti.'
48
+ list_title: 'Preferiti'
49
+ delete: 'Togli'
50
+
51
+ saved_searches:
52
+ add:
53
+ success: 'Ricerca salvata.'
54
+ failure: 'Si è verificato un errore nel salvare la ricerca.'
55
+ remove:
56
+ success: 'La ricerca è stata tolta dalla lista.'
57
+ failure: 'Si è verificato un errore nel togliere la ricerca dalla lista.'
58
+ clear:
59
+ action_title: 'Cancella tutte le ricerche salvate'
60
+ action_confirm: 'Vuoi cancellare tutte le ricerche salvate?'
61
+ success: 'Tutte le ricerche salvate sono state cancellate.'
62
+ failure: 'Si è verificato un errore nel cancellare le ricerche salvate.'
63
+ title: 'Ricerche salvate'
64
+ need_login: 'Effettuare il login per gestire e visualizzare le ricerche salvate.'
65
+ no_searches: 'Non è stata salvata nessuna ricerca.'
66
+ list_title: 'Ricerche salvate'
67
+ delete: 'cancella'
68
+
69
+ search_history:
70
+ clear:
71
+ action_title: 'Cancella le ricerche effettuate'
72
+ action_confirm: 'Vuoi cancellare le ricerche effettuate?'
73
+ success: 'Le ricerche effettuate sono state cancellate.'
74
+ failure: 'Si è verificato un errore nel cancellare le ricerche effettuate.'
75
+ title: 'Ricerche effettuate'
76
+ no_history: 'Non è stata effettuata nessuna ricerca'
77
+ recent: 'Ricerche effettuate'
78
+ forget: 'dimentica'
79
+ save: 'salva'
80
+
81
+ tools:
82
+ title: 'Strumenti'
83
+ citation: 'Cita'
84
+ endnote: 'Esporta in EndNote'
85
+ refworks: 'Esporta in Refworks'
86
+ email: 'Invia per e-mail'
87
+ sms: 'Invia per SMS'
88
+ clear: 'Cancella'
89
+
90
+ citation:
91
+ mla: 'MLA'
92
+ apa: 'APA'
93
+ chicago: 'Chicago'
94
+
95
+ email:
96
+ form:
97
+ title: 'Invia per e-mail'
98
+ to: 'E-mail:'
99
+ message: 'Messaggio:'
100
+ submit: 'Invia'
101
+ text:
102
+ title: 'Titolo: %{value}'
103
+ author: 'Autore: %{value}'
104
+ format: 'Formato: %{value}'
105
+ language: 'Lingua: %{value}'
106
+ subject:
107
+ one: 'Numero di scheda: %{title}'
108
+ other: 'Numeri di scheda'
109
+ url: 'URL: %{url}'
110
+ message: 'Messaggio: %{message}'
111
+
112
+ success: "Messaggio inviato"
113
+
114
+ errors:
115
+ to:
116
+ invalid: "L'indirizzo e-mail inserito non è valido"
117
+ blank: 'Inserisci un destinatario per inviare il messaggio'
118
+ sms:
119
+ form:
120
+ title: 'Invia per SMS'
121
+ to: 'Numero di telefono:'
122
+ carrier: 'Operatore'
123
+ carrier_prompt: "Indicare l'operatore"
124
+ submit: 'Inviare'
125
+ text:
126
+ title: '%{value}'
127
+ author: ' da %{value}'
128
+ url: 'Link: %{url}'
129
+ success: "SMS inviato"
130
+ errors:
131
+ to:
132
+ invalid: 'Inserisci un numero telefonico valido di 10 cifre'
133
+ blank: "Inserisci il numero di telefono del destinarario per inviare il messaggio"
134
+ carrier:
135
+ blank: 'Si richiede la scelta di un operatore'
136
+ invalid: "L'operatore non è valido"
137
+
138
+ back_to_search: 'Torna alla ricerca'
139
+ back_to_bookmarks: 'Torna ai preferiti'
140
+
141
+ search:
142
+ title: 'Risultati della ricerca per %{application_name}'
143
+ search_results_header: 'Ricerca'
144
+ search_results: 'Risultati della ricerca'
145
+ errors:
146
+ request_error: "La richiesta non è comprensibile."
147
+ invalid_solr_id: "Il numero di scheda richiesto non esiste."
148
+ per_page:
149
+ label: '%{count}<span class="sr-only"> per pagina</span>'
150
+ button_label: '%{count} per pagina'
151
+ title: 'Risultati per pagina'
152
+ submit: 'Aggiorna'
153
+ sort:
154
+ label: 'Ordina per %{field}'
155
+ submit: 'Ordina i risultati'
156
+ form:
157
+ search_field:
158
+ label: 'Cerca in'
159
+ title: 'Opzioni di ricerca mirate'
160
+ post_label: 'per'
161
+ # i18n key 'q' is deprecated and will be removed in Blacklight 6.0, use 'search.label' and 'search.placeholder'
162
+ q: 'Ricerca in corso...'
163
+ search:
164
+ label: 'cerca per'
165
+ placeholder: 'Ricerca in corso...'
166
+ submit: 'Avvia la ricerca'
167
+ pagination:
168
+ title: 'Navigazione nei risultati'
169
+ pagination_info:
170
+ no_items_found: 'Nessun %{entry_name} trovano'
171
+ single_item_found: '<strong>1</strong> %{entry_name} trovato'
172
+ pages:
173
+ one: '<strong>%{start_num}</strong> - <strong>%{end_num}</strong> di <strong>%{total_num}</strong>'
174
+ other: '<strong>%{start_num}</strong> - <strong>%{end_num}</strong> di <strong>%{total_num}</strong>'
175
+ entry_pagination_info:
176
+ one: '<strong>1 di 1</strong>'
177
+ other: '<strong>%{current}</strong> di <strong>%{total}</strong>'
178
+ documents:
179
+ counter: '%{counter}. '
180
+ facets:
181
+ title: 'Affina la ricerca'
182
+ sort:
183
+ count: 'Ordina per numero'
184
+ index: 'Ordina A-Z'
185
+ count: '%{number}'
186
+ # i18n key 'more' is deprecated and will be removed in Blacklight 6.0
187
+ more: 'altri »'
188
+ more_html: 'altri <span class="sr-only">%{field_name}</span> »'
189
+ selected:
190
+ remove: '[cancella]'
191
+ group:
192
+ more: 'altri »'
193
+ filters:
194
+ title: 'Hai cercato per:'
195
+ label: '%{label}:'
196
+ remove:
197
+ value: 'Cancella il filtro %{value}'
198
+ label_value: 'Cancella il filtro %{label}: %{value}'
199
+ start_over: 'Nuova ricerca'
200
+ index:
201
+ label: '%{label}:'
202
+ show:
203
+ title: '%{document_title} - %{application_name}'
204
+ label: '%{label}:'
205
+ rss_feed: 'RSS per i risultati'
206
+ atom_feed: 'Atom per i risultati'
207
+ fields:
208
+ default: 'Parola chiave'
209
+ bookmarks:
210
+ present: "Nei preferiti"
211
+ absent: "Non fra i preferiti"
212
+ inprogress: "Salvataggio in corso..."
213
+ zero_results:
214
+ title: "La ricerca non ha prodotto alcun risultato"
215
+ modify_search: "Modifica la ricerca"
216
+ use_fewer_keywords: "Usa meno parole chiave per iniziare, poi raffina la ricerca con i links sulla sinistra."
217
+ search_fields: "hai cercato in %{search_fields}"
218
+ search_everything: "prova a cercare in tutti i campi"
219
+ view_title: "Visualizza i risultati come: "
220
+ view:
221
+ list: "Lista"
222
+
223
+ entry_name:
224
+ default: 'termine di ricerca'
225
+
226
+ did_you_mean: 'Intendevi digitare: %{options}?'
@@ -1,12 +1,4 @@
1
1
  pt-BR:
2
- active_record:
3
- models:
4
- feedback: 'Feedback'
5
- attributes:
6
- feedback:
7
- name: 'Seu Nome'
8
- email: 'Seu Email'
9
- message: 'Sua Mensagem'
10
2
  views:
11
3
  pagination:
12
4
  first: '&laquo; primeiro'
@@ -34,9 +26,6 @@ pt-BR:
34
26
  or: 'ou'
35
27
 
36
28
  bookmarks:
37
- collection:
38
- add:
39
- button: 'Adicionar aos Favoritos'
40
29
  title: 'Favoritos'
41
30
  no_bookmarks: 'Você não salvou nenhum Favorito'
42
31
  add:
@@ -58,17 +47,6 @@ pt-BR:
58
47
  need_login: 'Faça o login para ver ou modificar seus favoritos.'
59
48
  list_title: 'Seus Favoritos'
60
49
  delete: 'Excluir'
61
-
62
- feedback:
63
- valid_name: 'Preencha o Nome'
64
- valid_email: 'Verifique seu endereço de email'
65
- need_message: 'Escreva uma mensagem'
66
- submit: 'Enviar!'
67
- errors:
68
- title: 'Por favor corrija os seguintes erros no formulário:'
69
- complete:
70
- title: 'Obrigado por seu contato'
71
-
72
50
  saved_searches:
73
51
  add:
74
52
  success: 'Sua busca foi salva.'
@@ -76,6 +76,8 @@ module Blacklight
76
76
  document_model: nil,
77
77
  # document presenter class used by helpers and views
78
78
  document_presenter_class: nil,
79
+ # Class for paginating long lists of facet fields
80
+ facet_paginator_class: nil,
79
81
  # repository connection configuration
80
82
  connection_config: nil,
81
83
  ##
@@ -228,6 +230,10 @@ module Blacklight
228
230
  Blacklight::Solr::SearchBuilder
229
231
  end
230
232
 
233
+ def facet_paginator_class
234
+ super || Blacklight::Solr::FacetPaginator
235
+ end
236
+
231
237
  def default_per_page
232
238
  super || per_page.first
233
239
  end
@@ -334,11 +340,10 @@ module Blacklight
334
340
  # too. These model names should not be `#dup`'ed or we might break ActiveModel::Naming.
335
341
  def deep_copy
336
342
  deep_dup.tap do |copy|
337
- copy.repository_class = self.repository_class
338
- copy.response_model = self.response_model
339
- copy.document_model = self.document_model
340
- copy.document_presenter_class = self.document_presenter_class
341
- copy.search_builder_class = self.search_builder_class
343
+ %w(repository_class response_model document_model document_presenter_class search_builder_class facet_paginator_class).each do |klass|
344
+ # Don't copy if nil, so as not to prematurely autoload default classes
345
+ copy.send("#{klass}=", send(klass)) unless fetch(klass.to_sym, nil).nil?
346
+ end
342
347
  end
343
348
  end
344
349
  alias_method :inheritable_copy, :deep_copy
@@ -15,6 +15,7 @@
15
15
  module Blacklight::Document
16
16
  autoload :ActiveModelShim, 'blacklight/document/active_model_shim'
17
17
  autoload :SchemaOrg, 'blacklight/document/schema_org'
18
+ autoload :CacheKey, 'blacklight/document/cache_key'
18
19
  autoload :DublinCore, 'blacklight/document/dublin_core'
19
20
  autoload :Email, 'blacklight/document/email'
20
21
  autoload :SemanticFields, 'blacklight/document/semantic_fields'
@@ -25,6 +26,7 @@ module Blacklight::Document
25
26
  extend ActiveSupport::Concern
26
27
  include Blacklight::Document::SchemaOrg
27
28
  include Blacklight::Document::SemanticFields
29
+ include Blacklight::Document::CacheKey
28
30
  include Blacklight::Document::Export
29
31
 
30
32
  extend Deprecation
@@ -0,0 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # This module provides the cache key which can be used by rails
3
+ # caching to determine when to expire a particular object's cache
4
+ # See http://apidock.com/rails/ActiveRecord/Integration/cache_key
5
+ # This key should be used in conjunction with additional data to
6
+ # determine when a document can be cached (e.g. for different view
7
+ # types in search results like gallery and list)
8
+ module Blacklight::Document::CacheKey
9
+ def cache_key
10
+ case
11
+ when new_record?
12
+ "#{self.class.model_name.cache_key}/new"
13
+ when cache_version_value = self[cache_version_key]
14
+ "#{self.class.model_name.cache_key}/#{id}-#{Array(cache_version_value).join}"
15
+ else
16
+ "#{self.class.model_name.cache_key}/#{id}"
17
+ end
18
+ end
19
+
20
+ def cache_version_key
21
+ :_version_
22
+ end
23
+ end
@@ -1,14 +1,15 @@
1
- # These are methods that are used at both the view helper and controller layers
2
- # They are only dependent on `blacklight_config` and `@response`
3
- #
4
1
  module Blacklight
2
+ # These are methods that are used at both the view helper and controller layers
3
+ # They are only dependent on `blacklight_config` and `@response`
4
+ #
5
5
  module Facet
6
-
7
- def facet_paginator field_config, display_facet
8
- Blacklight::Solr::FacetPaginator.new(display_facet.items,
6
+ def facet_paginator(field_config, display_facet)
7
+ blacklight_config.facet_paginator_class.new(
8
+ display_facet.items,
9
9
  sort: display_facet.sort,
10
- offset: display_facet.offset,
11
- limit: facet_limit_for(field_config.key))
10
+ offset: display_facet.offset,
11
+ limit: facet_limit_for(field_config.key)
12
+ )
12
13
  end
13
14
 
14
15
  def facets_from_request(fields = facet_field_names)
@@ -20,17 +21,13 @@ module Blacklight
20
21
  end
21
22
 
22
23
  def facet_configuration_for_field(field)
23
- f = blacklight_config.facet_fields[field]
24
- f ||= begin
25
- _, value = blacklight_config.facet_fields.find { |k,v| v.field.to_s == field.to_s }
26
- value
27
- end
28
- f ||= Blacklight::Configuration::FacetField.new(:field => field).normalize!
24
+ blacklight_config.facet_fields[field] ||
25
+ blacklight_config.facet_fields.values.find { |v| v.field.to_s == field.to_s } ||
26
+ Blacklight::Configuration::FacetField.new(field: field).normalize!
29
27
  end
30
28
 
31
-
32
29
  # Get a FacetField object from the @response
33
- def facet_by_field_name field_or_field_name
30
+ def facet_by_field_name(field_or_field_name)
34
31
  case field_or_field_name
35
32
  when String, Symbol, Blacklight::Configuration::FacetField
36
33
  facet_field = facet_configuration_for_field(field_or_field_name)
@@ -18,7 +18,7 @@ module ActionDispatch::Routing
18
18
  private
19
19
  def raise_no_blacklight_secret_key #:nodoc:
20
20
  raise <<-ERROR
21
- Blacklight.secret_key was not set. Please add the following to an initializer:
21
+ Blacklight.secret_key was not set. If you are using Rails 4.1+, set your app's secret key base (config/secrets.yml) OR add the following to an initializer:
22
22
 
23
23
  Blacklight.secret_key = '#{SecureRandom.hex(64)}'
24
24
 
@@ -23,7 +23,12 @@ module Blacklight
23
23
  # CatalogController.include ModuleDefiningNewMethod
24
24
  # CatalogController.search_params_logic += [:new_method]
25
25
  # CatalogController.search_params_logic.delete(:we_dont_want)
26
- self.search_params_logic = [:default_solr_parameters, :add_query_to_solr, :add_facet_fq_to_solr, :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr, :add_sorting_to_solr, :add_group_config_to_solr ]
26
+ self.search_params_logic = [
27
+ :default_solr_parameters, :add_query_to_solr, :add_facet_fq_to_solr,
28
+ :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr,
29
+ :add_sorting_to_solr, :add_group_config_to_solr,
30
+ :add_facet_paging_to_solr
31
+ ]
27
32
 
28
33
  if self.respond_to?(:helper_method)
29
34
  helper_method(:facet_limit_for)
@@ -111,35 +116,6 @@ module Blacklight
111
116
  end
112
117
  deprecation_deprecate :solr_documents_by_field_values_params
113
118
 
114
- ##
115
- # Retrieve a facet's paginated values.
116
- def solr_facet_params(facet_field, user_params=params || {}, extra_controller_params={})
117
- input = user_params.deep_merge(extra_controller_params)
118
- facet_config = blacklight_config.facet_fields[facet_field]
119
-
120
- solr_params = {}
121
-
122
- # Now override with our specific things for fetching facet values
123
- solr_params[:"facet.field"] = search_builder.with_ex_local_param((facet_config.ex if facet_config.respond_to?(:ex)), facet_field)
124
-
125
- limit = if respond_to?(:facet_list_limit)
126
- facet_list_limit.to_s.to_i
127
- elsif solr_params["facet.limit"]
128
- solr_params["facet.limit"].to_i
129
- else
130
- 20
131
- end
132
-
133
- # Need to set as f.facet_field.facet.* to make sure we
134
- # override any field-specific default in the solr request handler.
135
- solr_params[:"f.#{facet_field}.facet.limit"] = limit + 1
136
- solr_params[:"f.#{facet_field}.facet.offset"] = ( input.fetch(Blacklight::Solr::FacetPaginator.request_keys[:page] , 1).to_i - 1 ) * ( limit )
137
- solr_params[:"f.#{facet_field}.facet.sort"] = input[ Blacklight::Solr::FacetPaginator.request_keys[:sort] ] if input[ Blacklight::Solr::FacetPaginator.request_keys[:sort] ]
138
- solr_params[:rows] = 0
139
-
140
- solr_params
141
- end
142
-
143
119
  ##
144
120
  # Opensearch autocomplete parameters for plucking a field's value from the results
145
121
  def solr_opensearch_params(field=nil)
@@ -51,6 +51,7 @@ module Blacklight
51
51
  builder.start(@start) if @start
52
52
  builder.rows(@rows) if @rows
53
53
  builder.page(@page) if @page
54
+ builder.facet(@facet) if @facet
54
55
 
55
56
  builder
56
57
  end
@@ -204,6 +205,18 @@ module Blacklight
204
205
  field unless field.blank?
205
206
  end
206
207
 
208
+ # sets the facet that this query pertains to, if it is for the purpose of
209
+ # facet pagination
210
+ def facet(facet = nil)
211
+ if facet
212
+ params_will_change!
213
+ @facet = facet
214
+ self
215
+ else
216
+ @facet
217
+ end
218
+ end
219
+
207
220
  def search_field
208
221
  blacklight_config.search_fields[blacklight_params[:search_field]]
209
222
  end
@@ -159,8 +159,8 @@ module Blacklight::SearchHelper
159
159
  # Get the solr response when retrieving only a single facet field
160
160
  # @return [Blacklight::SolrResponse] the solr response
161
161
  def get_facet_field_response(facet_field, user_params = params || {}, extra_controller_params = {})
162
- query = search_builder.with(user_params).merge(extra_controller_params).merge(solr_facet_params(facet_field, user_params, extra_controller_params))
163
- repository.search(query)
162
+ query = search_builder.with(user_params).facet(facet_field)
163
+ repository.search(query.merge(extra_controller_params))
164
164
  end
165
165
 
166
166
  # a solr query method
@@ -1,7 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Blacklight::Solr
3
-
4
- autoload :Facets, 'blacklight/solr/facets'
5
3
  autoload :FacetPaginator, 'blacklight/solr/facet_paginator'
6
4
  autoload :Document, 'blacklight/solr/document'
7
5
  autoload :Request, 'blacklight/solr/request'
@@ -1,5 +1,6 @@
1
1
  module Blacklight::Solr
2
- # @deprecated
2
+ # @deprecated In 6.0 you should have this class generated into your application and Blacklight will
3
+ # no longer need to provide it.
3
4
  class SearchBuilder < Blacklight::SearchBuilder
4
5
  include Blacklight::Solr::SearchBuilderBehavior
5
6
  end
@@ -3,7 +3,12 @@ module Blacklight::Solr
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- self.default_processor_chain = [:default_solr_parameters, :add_query_to_solr, :add_facet_fq_to_solr, :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr, :add_sorting_to_solr, :add_group_config_to_solr ]
6
+ self.default_processor_chain = [
7
+ :default_solr_parameters, :add_query_to_solr, :add_facet_fq_to_solr,
8
+ :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr,
9
+ :add_sorting_to_solr, :add_group_config_to_solr,
10
+ :add_facet_paging_to_solr
11
+ ]
7
12
  end
8
13
 
9
14
  ####
@@ -190,6 +195,38 @@ module Blacklight::Solr
190
195
  end
191
196
  end
192
197
 
198
+ def add_facet_paging_to_solr(solr_params)
199
+ return unless facet.present?
200
+
201
+ facet_config = blacklight_config.facet_fields[facet]
202
+
203
+ # Now override with our specific things for fetching facet values
204
+ facet_ex = facet_config.respond_to?(:ex) ? facet_config.ex : nil
205
+ solr_params[:"facet.field"] = with_ex_local_param(facet_ex, facet)
206
+
207
+ limit = if scope.respond_to?(:facet_list_limit)
208
+ scope.facet_list_limit.to_s.to_i
209
+ elsif solr_params["facet.limit"]
210
+ solr_params["facet.limit"].to_i
211
+ else
212
+ 20
213
+ end
214
+
215
+ page = blacklight_params.fetch(request_keys[:page], 1).to_i
216
+ offset = (page - 1) * (limit)
217
+
218
+ sort = blacklight_params[request_keys[:sort]]
219
+
220
+ # Need to set as f.facet_field.facet.* to make sure we
221
+ # override any field-specific default in the solr request handler.
222
+ solr_params[:"f.#{facet}.facet.limit"] = limit + 1
223
+ solr_params[:"f.#{facet}.facet.offset"] = offset
224
+ if blacklight_params[request_keys[:sort]]
225
+ solr_params[:"f.#{facet}.facet.sort"] = sort
226
+ end
227
+ solr_params[:rows] = 0
228
+ end
229
+
193
230
  def with_ex_local_param(ex, value)
194
231
  if ex
195
232
  "{!ex=#{ex}}#{value}"
@@ -277,5 +314,9 @@ module Blacklight::Solr
277
314
  facet.include_in_request || (facet.include_in_request.nil? && blacklight_config.add_facet_fields_to_solr_request)
278
315
  end
279
316
  end
317
+
318
+ def request_keys
319
+ blacklight_config.facet_paginator_class.request_keys
320
+ end
280
321
  end
281
322
  end
@@ -31,7 +31,8 @@ module Blacklight::SolrResponse::Facets
31
31
  class FacetField
32
32
  attr_reader :name, :items
33
33
  def initialize name, items, options = {}
34
- @name, @items = name, items
34
+ @name = name
35
+ @items = items
35
36
  @options = options
36
37
  end
37
38
 
@@ -12,9 +12,9 @@ describe FacetsHelper do
12
12
  describe "has_facet_values?" do
13
13
  it "should be true if there are any facets to display" do
14
14
 
15
- a = double(:items => [1,2])
16
- b = double(:items => ['b','c'])
17
- empty = double(:items => [])
15
+ a = double(:items => [1,2], :name => 'a')
16
+ b = double(:items => ['b','c'], :name => 'b')
17
+ empty = double(:items => [], :name => 'empty')
18
18
 
19
19
  fields = [a,b,empty]
20
20
  expect(helper.has_facet_values?(fields)).to be true
@@ -27,6 +27,19 @@ describe FacetsHelper do
27
27
  fields = [empty]
28
28
  expect(helper.has_facet_values?(fields)).to be false
29
29
  end
30
+
31
+ it "should be false if no facets are displayable" do
32
+ @config = Blacklight::Configuration.new do |config|
33
+ config.add_facet_field 'basic_field', :if => false
34
+ end
35
+
36
+ allow(helper).to receive_messages(:blacklight_config => @config)
37
+
38
+ a = double(:items => [1,2], :name=>'basic_field')
39
+ fields = [a]
40
+
41
+ expect(helper.has_facet_values?(fields)).to be false
42
+ end
30
43
  end
31
44
 
32
45
  describe "should_render_facet?" do
@@ -289,7 +302,7 @@ describe FacetsHelper do
289
302
  describe "render_facet_value" do
290
303
  let (:item) { double(:value => 'A', :hits => 10) }
291
304
  before do
292
- allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false))
305
+ allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false, :url_method => nil))
293
306
  allow(helper).to receive(:facet_display_value).and_return('Z')
294
307
  allow(helper).to receive(:add_facet_params_and_redirect).and_return({controller:'catalog'})
295
308
 
@@ -305,6 +318,16 @@ describe FacetsHelper do
305
318
  end
306
319
  end
307
320
 
321
+ describe "when :url_method is set" do
322
+ let(:expected_html) { "<span class=\"facet-label\"><a class=\"facet_select\" href=\"/blabla\">Z</a></span><span class=\"facet-count\">10</span>" }
323
+ it "should use that method" do
324
+ allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false, :url_method => :test_method))
325
+ allow(helper).to receive(:test_method).with('simple_field', item).and_return('/blabla')
326
+ result = helper.render_facet_value('simple_field', item)
327
+ expect(result).to be_equivalent_to(expected_html).respecting_element_order
328
+ end
329
+ end
330
+
308
331
  describe "when :suppress_link is set" do
309
332
  let(:expected_html) { "<span class=\"facet-label\">Z</span><span class=\"facet-count\">10</span>" }
310
333
  it "should suppress the link" do
@@ -316,12 +339,12 @@ describe FacetsHelper do
316
339
 
317
340
  describe "#facet_display_value" do
318
341
  it "should just be the facet value for an ordinary facet" do
319
- allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil))
342
+ allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :url_method => nil))
320
343
  expect(helper.facet_display_value('simple_field', 'asdf')).to eq 'asdf'
321
344
  end
322
345
 
323
346
  it "should allow you to pass in a :helper_method argument to the configuration" do
324
- allow(helper).to receive(:facet_configuration_for_field).with('helper_field').and_return(double(:query => nil, :date => nil, :helper_method => :my_facet_value_renderer))
347
+ allow(helper).to receive(:facet_configuration_for_field).with('helper_field').and_return(double(:query => nil, :date => nil, :url_method => nil, :helper_method => :my_facet_value_renderer))
325
348
 
326
349
  allow(helper).to receive(:my_facet_value_renderer).with('qwerty').and_return('abc')
327
350
 
@@ -329,17 +352,17 @@ describe FacetsHelper do
329
352
  end
330
353
 
331
354
  it "should extract the configuration label for a query facet" do
332
- allow(helper).to receive(:facet_configuration_for_field).with('query_facet').and_return(double(:query => { 'query_key' => { :label => 'XYZ'}}, :date => nil, :helper_method => nil))
355
+ allow(helper).to receive(:facet_configuration_for_field).with('query_facet').and_return(double(:query => { 'query_key' => { :label => 'XYZ'}}, :date => nil, :helper_method => nil, :url_method => nil))
333
356
  expect(helper.facet_display_value('query_facet', 'query_key')).to eq 'XYZ'
334
357
  end
335
358
 
336
359
  it "should localize the label for date-type facets" do
337
- allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => true, :query => nil, :helper_method => nil))
360
+ allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => true, :query => nil, :helper_method => nil, :url_method => nil))
338
361
  expect(helper.facet_display_value('date_facet', '2012-01-01')).to eq 'Sun, 01 Jan 2012 00:00:00 +0000'
339
362
  end
340
363
 
341
364
  it "should localize the label for date-type facets with the supplied localization options" do
342
- allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => { :format => :short }, :query => nil, :helper_method => nil))
365
+ allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => { :format => :short }, :query => nil, :helper_method => nil, :url_method => nil))
343
366
  expect(helper.facet_display_value('date_facet', '2012-01-01')).to eq '01 Jan 00:00'
344
367
  end
345
368
  end
@@ -96,14 +96,32 @@ describe "Blacklight::Configuration" do
96
96
  expect(@config.facet_fields).to_not include(@mock_facet)
97
97
  end
98
98
 
99
- it "should not dup response_model or document_model" do
100
- @config.response_model = Blacklight::SolrResponse
101
- @config.document_model = SolrDocument
99
+ context "when model classes are customised" do
100
+ it "should not dup response_model or document_model" do
101
+ @config.response_model = Hash
102
+ @config.document_model = Array
102
103
 
103
- config_copy = @config.inheritable_copy
104
+ config_copy = @config.inheritable_copy
104
105
 
105
- expect(config_copy.response_model).to eq Blacklight::SolrResponse
106
- expect(config_copy.document_model).to eq SolrDocument
106
+ expect(config_copy.response_model).to eq Hash
107
+ expect(config_copy.document_model).to eq Array
108
+ end
109
+ end
110
+
111
+ context "when model classes are not set" do
112
+ it "should leave response_model and document_model empty" do
113
+ config_copy = @config.inheritable_copy
114
+
115
+ expect(config_copy.fetch(:response_model, nil)).to be_nil
116
+ expect(config_copy.fetch(:document_model, nil)).to be_nil
117
+ end
118
+
119
+ it "should return default classes" do
120
+ config_copy = @config.inheritable_copy
121
+
122
+ expect(config_copy.response_model).to eq Blacklight::SolrResponse
123
+ expect(config_copy.document_model).to eq SolrDocument
124
+ end
107
125
  end
108
126
 
109
127
  it "should provide cloned copies of mutable data structures" do
@@ -469,5 +487,10 @@ describe "Blacklight::Configuration" do
469
487
  expect(@config.default_search_field.key).to eq 'search_field_2'
470
488
  end
471
489
  end
472
-
490
+
491
+ describe "#facet_paginator_class" do
492
+ it "should default to Blacklight::Solr::FacetPaginator" do
493
+ expect(@config.facet_paginator_class).to eq Blacklight::Solr::FacetPaginator
494
+ end
495
+ end
473
496
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blacklight::Document::CacheKey do
4
+ let(:attributes) { {} }
5
+ let(:subject) { SolrDocument.new(attributes) }
6
+ it 'SolrDocument includes the module' do
7
+ expect(subject.class).to include(Blacklight::Document::CacheKey)
8
+ end
9
+
10
+ describe 'new record' do
11
+ before do
12
+ allow(subject).to receive_messages(new_record?: true)
13
+ end
14
+ it 'provides an acceptable cache key' do
15
+ expect(subject.cache_key).to eq 'solr_documents/new'
16
+ end
17
+ end
18
+
19
+ describe 'with version' do
20
+ let(:attributes) { { id: '12345', _version_: '1497353774427013120' } }
21
+ it 'provides a cache key with the id and version' do
22
+ expect(subject.cache_key).to eq 'solr_documents/12345-1497353774427013120'
23
+ end
24
+ describe 'as array' do
25
+ let(:attributes) { { id: '12345', _version_: ['1234', '4321'] } }
26
+ it 'provides a cache key with the id and joined version array' do
27
+ expect(subject.cache_key).to eq 'solr_documents/12345-12344321'
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'without version' do
33
+ let(:attributes) { { id: '12345' } }
34
+ it 'provides a cache key with just the id' do
35
+ expect(subject.cache_key).to eq 'solr_documents/12345'
36
+ end
37
+ end
38
+
39
+ describe '#cache_version_key' do
40
+ let(:attributes) { { id: '12345', another_version_field: '1497353774427013120' } }
41
+ before do
42
+ allow(subject).to receive_messages(cache_version_key: :another_version_field)
43
+ end
44
+ it 'provides a cache key with the defined field' do
45
+ expect(subject.cache_key).to eq 'solr_documents/12345-1497353774427013120'
46
+ end
47
+ end
48
+ end
@@ -31,4 +31,4 @@ describe Blacklight::Facet do
31
31
  end
32
32
  end
33
33
 
34
- end
34
+ end
@@ -187,6 +187,16 @@ describe Blacklight::SearchBuilder do
187
187
  end
188
188
  end
189
189
 
190
+ describe "#facet" do
191
+ it "should be nil if no value is set" do
192
+ expect(subject.facet).to be_nil
193
+ end
194
+
195
+ it "should set facet value" do
196
+ expect(subject.facet('format').facet).to eq 'format'
197
+ end
198
+ end
199
+
190
200
  describe "#search_field" do
191
201
  it "should use the requested search field" do
192
202
  blacklight_config.add_search_field 'x'
@@ -240,4 +250,4 @@ describe Blacklight::SearchBuilder do
240
250
  end
241
251
 
242
252
  end
243
- end
253
+ end
@@ -64,78 +64,6 @@ describe Blacklight::SearchHelper do
64
64
  end
65
65
  end
66
66
 
67
- describe "solr_facet_params" do
68
- before do
69
- @facet_field = 'format'
70
- @generated_solr_facet_params = subject.solr_facet_params(@facet_field)
71
-
72
- @sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
73
- @page_key = Blacklight::Solr::FacetPaginator.request_keys[:page]
74
- end
75
- let(:blacklight_config) do
76
- Blacklight::Configuration.new do |config|
77
- config.add_facet_fields_to_solr_request!
78
- config.add_facet_field 'format'
79
- config.add_facet_field 'format_ordered', :sort => :count
80
- config.add_facet_field 'format_limited', :limit => 5
81
-
82
- end
83
- end
84
-
85
- it 'sets rows to 0' do
86
- expect(@generated_solr_facet_params[:rows]).to eq 0
87
- end
88
- it 'sets facets requested to facet_field argument' do
89
- expect(@generated_solr_facet_params["facet.field".to_sym]).to eq @facet_field
90
- end
91
- it 'defaults offset to 0' do
92
- expect(@generated_solr_facet_params[:"f.#{@facet_field}.facet.offset"]).to eq 0
93
- end
94
- it 'uses offset manually set, and converts it to an integer' do
95
- solr_params = subject.solr_facet_params(@facet_field, @page_key => 2)
96
- expect(solr_params[:"f.#{@facet_field}.facet.offset"]).to eq 20
97
- end
98
- it 'defaults limit to 20' do
99
- solr_params = subject.solr_facet_params(@facet_field)
100
- expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 21
101
- end
102
-
103
- describe 'if facet_list_limit is defined in controller' do
104
- before do
105
- allow(subject).to receive_messages facet_list_limit: 1000
106
- end
107
- it 'uses controller method for limit' do
108
- solr_params = subject.solr_facet_params(@facet_field)
109
- expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
110
- end
111
-
112
- it 'uses controller method for limit when a ordinary limit is set' do
113
- solr_params = subject.solr_facet_params(@facet_field)
114
- expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
115
- end
116
- end
117
-
118
- it 'uses the default sort' do
119
- solr_params = subject.solr_facet_params(@facet_field)
120
- expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to be_blank
121
- end
122
-
123
- it 'uses sort provided in the parameters' do
124
- solr_params = subject.solr_facet_params(@facet_field, @sort_key => "index")
125
- expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to eq 'index'
126
- end
127
-
128
- it "comes up with the same params as #solr_search_params to constrain context for facet list" do
129
- search_params = {:q => 'tibetan history', :f=> {:format=>'Book', :language_facet=>'Tibetan'}}
130
- solr_facet_params = subject.solr_facet_params('format', search_params)
131
-
132
- expect(solr_facet_params).to include :"facet.field" => "format"
133
- expect(solr_facet_params).to include :"f.format.facet.limit" => 21
134
- expect(solr_facet_params).to include :"f.format.facet.offset" => 0
135
- expect(solr_facet_params).to include :"rows" => 0
136
- end
137
- end
138
-
139
67
  describe "get_facet_pagination", :integration => true do
140
68
  before do
141
69
  @facet_field = 'format'
@@ -553,7 +553,71 @@ describe Blacklight::Solr::SearchBuilder do
553
553
  end
554
554
  end
555
555
  end
556
-
556
+
557
+ describe "#add_facet_paging_to_solr" do
558
+ let(:facet_field) { 'format' }
559
+ let(:sort_key) { Blacklight::Solr::FacetPaginator.request_keys[:sort] }
560
+ let(:page_key) { Blacklight::Solr::FacetPaginator.request_keys[:page] }
561
+
562
+ let(:blacklight_config) do
563
+ Blacklight::Configuration.new do |config|
564
+ config.add_facet_fields_to_solr_request!
565
+ config.add_facet_field 'format'
566
+ config.add_facet_field 'format_ordered', sort: :count
567
+ config.add_facet_field 'format_limited', limit: 5
568
+ end
569
+ end
570
+
571
+ let(:solr_parameters) do
572
+ solr_parameters = Blacklight::Solr::Request.new
573
+ subject.facet(facet_field).add_facet_paging_to_solr(solr_parameters)
574
+ solr_parameters
575
+ end
576
+
577
+ it 'sets rows to 0' do
578
+ expect(solr_parameters[:rows]).to eq 0
579
+ end
580
+ it 'sets facets requested to facet_field argument' do
581
+ expect(solr_parameters["facet.field".to_sym]).to eq facet_field
582
+ end
583
+ it 'defaults offset to 0' do
584
+ expect(solr_parameters[:"f.#{facet_field}.facet.offset"]).to eq 0
585
+ end
586
+ context 'when offset is manually set' do
587
+ let(:user_params) { { page_key => 2 } }
588
+ it 'uses offset manually set, and converts it to an integer' do
589
+ expect(solr_parameters[:"f.#{facet_field}.facet.offset"]).to eq 20
590
+ end
591
+ end
592
+ it 'defaults limit to 20' do
593
+ expect(solr_parameters[:"f.#{facet_field}.facet.limit"]).to eq 21
594
+ end
595
+
596
+ context 'when facet_list_limit is defined in scope' do
597
+ before do
598
+ allow(context).to receive_messages facet_list_limit: 1000
599
+ end
600
+ it 'uses scope method for limit' do
601
+ expect(solr_parameters[:"f.#{facet_field}.facet.limit"]).to eq 1001
602
+ end
603
+
604
+ it 'uses controller method for limit when a ordinary limit is set' do
605
+ expect(solr_parameters[:"f.#{facet_field}.facet.limit"]).to eq 1001
606
+ end
607
+ end
608
+
609
+ it 'uses the default sort' do
610
+ expect(solr_parameters[:"f.#{facet_field}.facet.sort"]).to be_blank
611
+ end
612
+
613
+ context 'when sort is provided' do
614
+ let(:user_params) { { sort_key => 'index' } }
615
+ it 'uses sort provided in the parameters' do
616
+ expect(solr_parameters[:"f.#{facet_field}.facet.sort"]).to eq 'index'
617
+ end
618
+ end
619
+ end
620
+
557
621
  describe "#with_tag_ex" do
558
622
  it "should add an !ex local parameter if the facet configuration requests it" do
559
623
  expect(subject.with_ex_local_param("xyz", "some-value")).to eq "{!ex=xyz}some-value"
@@ -32,17 +32,6 @@ describe "catalog/_constraints_element.html.erb" do
32
32
  end
33
33
  end
34
34
 
35
- describe "with checkmark suppressed" do
36
- before do
37
- render :partial => "catalog/constraints_element", :locals => {:label => "my label", :value => "my value", :options => {:check => false}}
38
- end
39
- it "should not include checkmark" do
40
- expect(rendered).to have_selector("span.appliedFilter") do |s|
41
- expect(s).to_not have_selector("img[src$='checkmark.gif']")
42
- end
43
- end
44
- end
45
-
46
35
  describe "with custom classes" do
47
36
  before do
48
37
  render :partial => "catalog/constraints_element", :locals => {:label => "my label", :value => "my value", :options => {:classes => ["class1", "class2"]}}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.13.1
4
+ version: 5.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2015-04-16 00:00:00.000000000 Z
20
+ date: 2015-07-02 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -245,6 +245,7 @@ extensions: []
245
245
  extra_rdoc_files: []
246
246
  files:
247
247
  - ".gitignore"
248
+ - ".hound.yml"
248
249
  - ".rspec"
249
250
  - ".rubocop.yml"
250
251
  - ".rubocop_hound.yml"
@@ -256,15 +257,7 @@ files:
256
257
  - README.md
257
258
  - Rakefile
258
259
  - VERSION
259
- - app/assets/images/blacklight/bg.png
260
- - app/assets/images/blacklight/border.png
261
- - app/assets/images/blacklight/bul_sq_gry.gif
262
- - app/assets/images/blacklight/checkmark.gif
263
260
  - app/assets/images/blacklight/logo.png
264
- - app/assets/images/blacklight/magnifying_glass.gif
265
- - app/assets/images/blacklight/remove.gif
266
- - app/assets/images/blacklight/separator.gif
267
- - app/assets/images/blacklight/start_over.gif
268
261
  - app/assets/images/favicon.ico
269
262
  - app/assets/javascripts/blacklight/ajax_modal.js
270
263
  - app/assets/javascripts/blacklight/autofocus.js
@@ -407,6 +400,7 @@ files:
407
400
  - config/locales/blacklight.en.yml
408
401
  - config/locales/blacklight.es.yml
409
402
  - config/locales/blacklight.fr.yml
403
+ - config/locales/blacklight.it.yml
410
404
  - config/locales/blacklight.pt-BR.yml
411
405
  - db/migrate/20140202020201_create_searches.rb
412
406
  - db/migrate/20140202020202_create_bookmarks.rb
@@ -431,6 +425,7 @@ files:
431
425
  - lib/blacklight/controller.rb
432
426
  - lib/blacklight/document.rb
433
427
  - lib/blacklight/document/active_model_shim.rb
428
+ - lib/blacklight/document/cache_key.rb
434
429
  - lib/blacklight/document/dublin_core.rb
435
430
  - lib/blacklight/document/email.rb
436
431
  - lib/blacklight/document/export.rb
@@ -527,6 +522,7 @@ files:
527
522
  - spec/lib/blacklight/catalog/component_configuration_spec.rb
528
523
  - spec/lib/blacklight/configurable_spec.rb
529
524
  - spec/lib/blacklight/configuration_spec.rb
525
+ - spec/lib/blacklight/document/cache_key_spec.rb
530
526
  - spec/lib/blacklight/document/dublin_core_spec.rb
531
527
  - spec/lib/blacklight/document/email_spec.rb
532
528
  - spec/lib/blacklight/document/sms_spec.rb
@@ -648,6 +644,7 @@ test_files:
648
644
  - spec/lib/blacklight/catalog/component_configuration_spec.rb
649
645
  - spec/lib/blacklight/configurable_spec.rb
650
646
  - spec/lib/blacklight/configuration_spec.rb
647
+ - spec/lib/blacklight/document/cache_key_spec.rb
651
648
  - spec/lib/blacklight/document/dublin_core_spec.rb
652
649
  - spec/lib/blacklight/document/email_spec.rb
653
650
  - spec/lib/blacklight/document/sms_spec.rb
Binary file