blacklight 5.14.0 → 5.15.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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -10
  3. data/Gemfile +2 -1
  4. data/VERSION +1 -1
  5. data/app/helpers/blacklight/blacklight_helper_behavior.rb +2 -14
  6. data/app/helpers/blacklight/catalog_helper_behavior.rb +31 -0
  7. data/app/views/bookmarks/index.html.erb +2 -0
  8. data/app/views/catalog/_document_default.atom.builder +2 -3
  9. data/app/views/catalog/_search_results.html.erb +1 -1
  10. data/app/views/catalog/index.html.erb +1 -0
  11. data/app/views/saved_searches/index.html.erb +2 -0
  12. data/app/views/search_history/index.html.erb +2 -0
  13. data/app/views/shared/_sitelinks_search_box.html.erb +12 -0
  14. data/config/locales/blacklight.de.yml +8 -0
  15. data/config/locales/blacklight.en.yml +8 -0
  16. data/config/locales/blacklight.es.yml +8 -0
  17. data/config/locales/blacklight.fr.yml +8 -0
  18. data/config/locales/blacklight.it.yml +8 -0
  19. data/config/locales/blacklight.pt-BR.yml +8 -0
  20. data/lib/blacklight.rb +1 -0
  21. data/lib/blacklight/configuration.rb +6 -1
  22. data/lib/blacklight/document_presenter.rb +23 -0
  23. data/lib/blacklight/facet_paginator.rb +121 -0
  24. data/lib/blacklight/search_builder.rb +21 -0
  25. data/lib/blacklight/search_helper.rb +5 -1
  26. data/lib/blacklight/solr/facet_paginator.rb +4 -101
  27. data/lib/blacklight/solr_response/spelling.rb +2 -0
  28. data/spec/features/sitelinks_search_box.rb +12 -0
  29. data/spec/helpers/blacklight_helper_spec.rb +10 -55
  30. data/spec/helpers/catalog_helper_spec.rb +39 -0
  31. data/spec/lib/blacklight/facet_paginator_spec.rb +12 -12
  32. data/spec/lib/blacklight/search_builder_spec.rb +11 -0
  33. data/spec/lib/blacklight/search_helper_spec.rb +21 -0
  34. data/spec/lib/blacklight/solr/facet_paginator_spec.rb +12 -0
  35. data/spec/lib/blacklight/solr_response_spec.rb +30 -9
  36. data/spec/lib/document_presenter_spec.rb +76 -2
  37. metadata +8 -2
@@ -47,6 +47,17 @@ describe Blacklight::SearchBuilder do
47
47
  end
48
48
  end
49
49
 
50
+ describe "#except" do
51
+ let(:processor_chain) { [:a, :b, :c, :d, :e] }
52
+ it "should provide a new search builder excepting arguments" do
53
+ builder = subject.except(:b, :d, :does_not_exist)
54
+ expect(builder).not_to equal(subject)
55
+ expect(subject.processor_chain).to eq processor_chain
56
+ expect(builder.processor_chain).not_to eq subject.processor_chain
57
+ expect(builder.processor_chain).to match_array [:a, :c, :e]
58
+ end
59
+ end
60
+
50
61
  describe "#to_hash" do
51
62
  it "should append the extra parameters to the result" do
52
63
  Deprecation.silence(Blacklight::SearchBuilder) do
@@ -118,6 +118,27 @@ describe Blacklight::SearchHelper do
118
118
  end
119
119
  end
120
120
 
121
+ describe "with SearchBuilder replacement block" do
122
+ it "should pass configured SearchBuilder and use returned SearchBuilder" do
123
+ replacement_search_builder = subject.search_builder([:new_chain])
124
+
125
+ # Sorry, have to use mocks to make sure method really passes the
126
+ # block return value to the repository search, couldn't figure
127
+ # out a better way to test.
128
+ expect(subject.repository).to receive(:search) do |arg_search_builder|
129
+ expect(arg_search_builder).to equal(replacement_search_builder)
130
+ end.and_return(
131
+ blacklight_config.response_model.new({'response'=>{'docs'=>[]}}, {}, document_model: blacklight_config.document_model, blacklight_config: blacklight_config)
132
+ )
133
+
134
+ subject.search_results({q: @no_docs_query}, [:one, :two]) do |arg_search_builder|
135
+ expect(arg_search_builder.processor_chain).to eq([:one, :two])
136
+
137
+ replacement_search_builder
138
+ end
139
+ end
140
+ end
141
+
121
142
  describe "#get_search_results " do
122
143
  it "should be deprecated and return results" do
123
144
  expect(Deprecation).to receive(:warn)
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blacklight::Solr::FacetPaginator do
4
+ let(:f1) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '792', value: 'Book') }
5
+ describe "#as_json" do
6
+ subject { described_class.new([f1], offset: 0, limit: nil).as_json }
7
+ it "should be well structured" do
8
+ expect(subject).to eq("items" => [{"hits"=>"792", "value"=>"Book"}], "limit" => nil,
9
+ "offset" => 0, "sort" => "count")
10
+ end
11
+ end
12
+ end
@@ -153,17 +153,34 @@ describe Blacklight::SolrResponse do
153
153
  expect(r.spelling.words).to eq []
154
154
  end
155
155
 
156
- it 'should provide spelling suggestions for a regular spellcheck results with a collation' do
157
- raw_response = eval(mock_response_with_spellcheck_collation)
158
- r = Blacklight::SolrResponse.new(raw_response, {})
159
- expect(r.spelling.words).to include("dell")
160
- expect(r.spelling.words).to include("ultrasharp")
156
+ context "pre solr 5 spellcheck collation syntax" do
157
+ it 'should provide spelling suggestions for a regular spellcheck results with a collation' do
158
+ raw_response = eval(mock_response_with_spellcheck_collation)
159
+ r = Blacklight::SolrResponse.new(raw_response, {})
160
+ expect(r.spelling.words).to include("dell")
161
+ expect(r.spelling.words).to include("ultrasharp")
162
+ end
163
+
164
+ it 'should provide spelling suggestion collation' do
165
+ raw_response = eval(mock_response_with_spellcheck_collation)
166
+ r = Blacklight::SolrResponse.new(raw_response, {})
167
+ expect(r.spelling.collation).to eq 'dell ultrasharp'
168
+ end
161
169
  end
162
170
 
163
- it 'should provide spelling suggestion collation' do
164
- raw_response = eval(mock_response_with_spellcheck_collation)
165
- r = Blacklight::SolrResponse.new(raw_response, {})
166
- expect(r.spelling.collation).to eq 'dell ultrasharp'
171
+ context "solr 5 spellcheck collation syntax" do
172
+ it 'should provide spelling suggestions for a regular spellcheck results with a collation' do
173
+ raw_response = eval(mock_response_with_spellcheck_collation_solr5)
174
+ r = Blacklight::SolrResponse.new(raw_response, {})
175
+ expect(r.spelling.words).to include("dell")
176
+ expect(r.spelling.words).to include("ultrasharp")
177
+ end
178
+
179
+ it 'should provide spelling suggestion collation' do
180
+ raw_response = eval(mock_response_with_spellcheck_collation_solr5)
181
+ r = Blacklight::SolrResponse.new(raw_response, {})
182
+ expect(r.spelling.collation).to eq 'dell ultrasharp'
183
+ end
167
184
  end
168
185
 
169
186
  it "should provide MoreLikeThis suggestions" do
@@ -207,6 +224,10 @@ describe Blacklight::SolrResponse do
207
224
  def mock_response_with_spellcheck_collation
208
225
  %|{'responseHeader'=>{'status'=>0,'QTime'=>3,'params'=>{'spellspellcheck.build'=>'true','spellcheck'=>'true','q'=>'hell','spellcheck.q'=>'hell ultrashar','wt'=>'ruby','spellcheck.collate'=>'true'}},'response'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'spellcheck'=>{'suggestions'=>['hell',{'numFound'=>1,'startOffset'=>0,'endOffset'=>4,'suggestion'=>['dell']},'ultrashar',{'numFound'=>1,'startOffset'=>5,'endOffset'=>14,'suggestion'=>['ultrasharp']},'collation','dell ultrasharp']}}|
209
226
  end
227
+
228
+ def mock_response_with_spellcheck_collation_solr5
229
+ %|{'responseHeader'=>{'status'=>0,'QTime'=>3,'params'=>{'spellspellcheck.build'=>'true','spellcheck'=>'true','q'=>'hell','spellcheck.q'=>'hell ultrashar','wt'=>'ruby','spellcheck.collate'=>'true'}},'response'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'spellcheck'=>{'suggestions'=>['hell',{'numFound'=>1,'startOffset'=>0,'endOffset'=>4,'suggestion'=>['dell']},'ultrashar',{'numFound'=>1,'startOffset'=>5,'endOffset'=>14,'suggestion'=>['ultrasharp']}],'collations'=>['collation','dell ultrasharp']}}|
230
+ end
210
231
 
211
232
  def mock_response_with_more_like_this
212
233
  %({'responseHeader'=>{'status'=>0,'QTime'=>8,'params'=>{'facet'=>'false','mlt.mindf'=>'1','mlt.fl'=>'subject_t','fl'=>'id','mlt.count'=>'3','mlt.mintf'=>'0','mlt'=>'true','q.alt'=>'*:*','qt'=>'search','wt'=>'ruby'}},'response'=>{'numFound'=>30,'start'=>0,'docs'=>[{'id'=>'00282214'},{'id'=>'00282371'},{'id'=>'00313831'},{'id'=>'00314247'},{'id'=>'43037890'},{'id'=>'53029833'},{'id'=>'77826928'},{'id'=>'78908283'},{'id'=>'79930185'},{'id'=>'85910001'}]},'moreLikeThis'=>{'00282214'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'00282371'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'00313831'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'96933325'}]},'00314247'=>{'numFound'=>3,'start'=>0,'docs'=>[{'id'=>'2008543486'},{'id'=>'96933325'},{'id'=>'2009373513'}]},'43037890'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'53029833'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'77826928'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'94120425'}]},'78908283'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'79930185'=>{'numFound'=>2,'start'=>0,'docs'=>[{'id'=>'94120425'},{'id'=>'2007020969'}]},'85910001'=>{'numFound'=>0,'start'=>0,'docs'=>[]}}})
@@ -5,8 +5,9 @@ describe Blacklight::DocumentPresenter do
5
5
  let(:request_context) { double(:add_facet_params => '') }
6
6
  let(:config) { Blacklight::Configuration.new }
7
7
 
8
- subject { Blacklight::DocumentPresenter.new(document, request_context, config) }
9
-
8
+ subject { presenter }
9
+ let(:presenter) { Blacklight::DocumentPresenter.new(document, request_context, config) }
10
+
10
11
  let(:document) do
11
12
  SolrDocument.new(id: 1,
12
13
  'link_to_search_true' => 'x',
@@ -15,6 +16,79 @@ describe Blacklight::DocumentPresenter do
15
16
  'mnbv' => 'document mnbv value')
16
17
  end
17
18
 
19
+ describe "link_rel_alternates" do
20
+ before do
21
+ class MockDocument
22
+ include Blacklight::Solr::Document
23
+ end
24
+
25
+ module MockExtension
26
+ def self.extended(document)
27
+ document.will_export_as(:weird, "application/weird")
28
+ document.will_export_as(:weirder, "application/weirder")
29
+ document.will_export_as(:weird_dup, "application/weird")
30
+ end
31
+ def export_as_weird ; "weird" ; end
32
+ def export_as_weirder ; "weirder" ; end
33
+ def export_as_weird_dup ; "weird_dup" ; end
34
+ end
35
+
36
+ MockDocument.use_extension(MockExtension)
37
+
38
+ def mock_document_app_helper_url *args
39
+ solr_document_url(*args)
40
+ end
41
+
42
+ allow(request_context).to receive(:polymorphic_url) do |_, opts|
43
+ "url.#{opts[:format]}"
44
+ end
45
+ end
46
+
47
+ let(:document) { MockDocument.new(id: "MOCK_ID1") }
48
+
49
+ context "with no arguments" do
50
+ subject { presenter.link_rel_alternates }
51
+
52
+ it "generates <link rel=alternate> tags" do
53
+ tmp_value = Capybara.ignore_hidden_elements
54
+ Capybara.ignore_hidden_elements = false
55
+ document.export_formats.each_pair do |format, spec|
56
+ expect(subject).to have_selector("link[href$='.#{ format }']") do |matches|
57
+ expect(matches).to have(1).match
58
+ tag = matches[0]
59
+ expect(tag.attributes["rel"].value).to eq "alternate"
60
+ expect(tag.attributes["title"].value).to eq format.to_s
61
+ expect(tag.attributes["href"].value).to eq mock_document_app_helper_url(document, format: format)
62
+ end
63
+ end
64
+ Capybara.ignore_hidden_elements = tmp_value
65
+ end
66
+
67
+ it { is_expected.to be_html_safe }
68
+ end
69
+
70
+ context "with unique: true" do
71
+ subject { presenter.link_rel_alternates(unique: true) }
72
+
73
+ it "respects unique: true" do
74
+ tmp_value = Capybara.ignore_hidden_elements
75
+ Capybara.ignore_hidden_elements = false
76
+ expect(subject).to have_selector("link[type='application/weird']", count: 1)
77
+ Capybara.ignore_hidden_elements = tmp_value
78
+ end
79
+ end
80
+
81
+ context "with exclude" do
82
+ subject { presenter.link_rel_alternates(unique: true) }
83
+ it "excludes formats from :exclude" do
84
+ tmp_value = Capybara.ignore_hidden_elements
85
+ Capybara.ignore_hidden_elements = false
86
+ expect(subject).to_not have_selector("link[href$='.weird_dup']")
87
+ Capybara.ignore_hidden_elements = tmp_value
88
+ end
89
+ end
90
+ end
91
+
18
92
  describe "render_index_field_value" do
19
93
  let(:config) do
20
94
  Blacklight::Configuration.new.configure do |config|
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.14.0
4
+ version: 5.15.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-07-02 00:00:00.000000000 Z
20
+ date: 2015-09-30 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -394,6 +394,7 @@ files:
394
394
  - app/views/shared/_flash_messages.html.erb
395
395
  - app/views/shared/_footer.html.erb
396
396
  - app/views/shared/_header_navbar.html.erb
397
+ - app/views/shared/_sitelinks_search_box.html.erb
397
398
  - blacklight.gemspec
398
399
  - config/jetty.yml
399
400
  - config/locales/blacklight.de.yml
@@ -437,6 +438,7 @@ files:
437
438
  - lib/blacklight/engine.rb
438
439
  - lib/blacklight/exceptions.rb
439
440
  - lib/blacklight/facet.rb
441
+ - lib/blacklight/facet_paginator.rb
440
442
  - lib/blacklight/rails/routes.rb
441
443
  - lib/blacklight/request_builders.rb
442
444
  - lib/blacklight/routes.rb
@@ -509,6 +511,7 @@ files:
509
511
  - spec/features/search_results_spec.rb
510
512
  - spec/features/search_sort_spec.rb
511
513
  - spec/features/search_spec.rb
514
+ - spec/features/sitelinks_search_box.rb
512
515
  - spec/helpers/blacklight_helper_spec.rb
513
516
  - spec/helpers/catalog_helper_spec.rb
514
517
  - spec/helpers/component_helper_spec.rb
@@ -535,6 +538,7 @@ files:
535
538
  - spec/lib/blacklight/search_helper_spec.rb
536
539
  - spec/lib/blacklight/solr/document/more_like_this_spec.rb
537
540
  - spec/lib/blacklight/solr/document_spec.rb
541
+ - spec/lib/blacklight/solr/facet_paginator_spec.rb
538
542
  - spec/lib/blacklight/solr/request_spec.rb
539
543
  - spec/lib/blacklight/solr/search_builder_spec.rb
540
544
  - spec/lib/blacklight/solr_helper_spec.rb
@@ -631,6 +635,7 @@ test_files:
631
635
  - spec/features/search_results_spec.rb
632
636
  - spec/features/search_sort_spec.rb
633
637
  - spec/features/search_spec.rb
638
+ - spec/features/sitelinks_search_box.rb
634
639
  - spec/helpers/blacklight_helper_spec.rb
635
640
  - spec/helpers/catalog_helper_spec.rb
636
641
  - spec/helpers/component_helper_spec.rb
@@ -657,6 +662,7 @@ test_files:
657
662
  - spec/lib/blacklight/search_helper_spec.rb
658
663
  - spec/lib/blacklight/solr/document/more_like_this_spec.rb
659
664
  - spec/lib/blacklight/solr/document_spec.rb
665
+ - spec/lib/blacklight/solr/facet_paginator_spec.rb
660
666
  - spec/lib/blacklight/solr/request_spec.rb
661
667
  - spec/lib/blacklight/solr/search_builder_spec.rb
662
668
  - spec/lib/blacklight/solr_helper_spec.rb