blacklight 4.5.0 → 4.6.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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -2
  3. data/VERSION +1 -1
  4. data/app/assets/javascripts/blacklight/blacklight.js +1 -1
  5. data/app/helpers/blacklight/blacklight_helper_behavior.rb +13 -3
  6. data/app/helpers/blacklight/catalog_helper_behavior.rb +47 -6
  7. data/app/helpers/blacklight/facets_helper_behavior.rb +5 -1
  8. data/app/helpers/blacklight/html_head_helper_behavior.rb +28 -13
  9. data/app/views/catalog/_paginate_compact.html.erb +1 -1
  10. data/app/views/catalog/_search_header.html.erb +5 -0
  11. data/app/views/catalog/facet.html.erb +2 -0
  12. data/app/views/catalog/index.html.erb +2 -6
  13. data/app/views/catalog/show.html.erb +1 -1
  14. data/app/views/kaminari/blacklight_compact/_paginator.html.erb +1 -1
  15. data/app/views/layouts/blacklight.html.erb +2 -2
  16. data/blacklight.gemspec +3 -1
  17. data/config/locales/blacklight.en.yml +1 -1
  18. data/gemfiles/rails3.gemfile +1 -2
  19. data/gemfiles/rails4.gemfile +0 -1
  20. data/lib/blacklight.rb +1 -0
  21. data/lib/blacklight/catalog.rb +8 -3
  22. data/lib/blacklight/catalog/search_context.rb +13 -5
  23. data/lib/blacklight/legacy_controller_methods.rb +18 -4
  24. data/lib/blacklight/solr/document.rb +7 -1
  25. data/lib/blacklight/solr/document/marc_export.rb +12 -24
  26. data/lib/blacklight/solr_helper.rb +4 -1
  27. data/lib/blacklight/solr_response/pagination_methods.rb +6 -0
  28. data/lib/generators/blacklight/blacklight_generator.rb +0 -4
  29. data/lib/generators/blacklight/marc_generator.rb +2 -2
  30. data/spec/controllers/application_controller_spec.rb +8 -6
  31. data/spec/controllers/catalog_controller_spec.rb +4 -4
  32. data/spec/features/did_you_mean_spec.rb +3 -3
  33. data/spec/features/search_filters_spec.rb +1 -1
  34. data/spec/features/search_spec.rb +1 -1
  35. data/spec/helpers/blacklight_helper_spec.rb +7 -1
  36. data/spec/helpers/catalog_helper_spec.rb +37 -21
  37. data/spec/helpers/facets_helper_spec.rb +8 -7
  38. data/spec/helpers/html_head_helper_spec.rb +25 -8
  39. data/spec/lib/blacklight_solr_response_spec.rb +9 -0
  40. data/spec/lib/marc_export_spec.rb +1 -8
  41. data/spec/views/catalog/_search_header.erb_spec.rb +17 -0
  42. data/spec/views/catalog/_show_sidebar.erb_spec.rb +2 -2
  43. data/spec/views/catalog/index.html.erb_spec.rb +13 -0
  44. metadata +34 -3
@@ -6,11 +6,15 @@
6
6
  # in here, but you may find them useful.
7
7
  module Blacklight
8
8
  module LegacyControllerMethods
9
- extend ActiveSupport::Concern
9
+ extend ActiveSupport::Concern
10
+
11
+ extend Deprecation
12
+ self.deprecation_horizon = 'Blacklight 5.x'
13
+
10
14
 
11
15
  included do
12
16
 
13
- before_filter :default_html_head # add JS/stylesheet stuff
17
+ before_filter :default_html_head_without_deprecation # add JS/stylesheet stuff
14
18
 
15
19
  helper_method :extra_head_content, :stylesheet_links, :javascript_includes
16
20
  end
@@ -25,21 +29,29 @@ module Blacklight
25
29
  # http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
26
30
  # for how to turn off a filter in a sub-class and such.
27
31
  def default_html_head
28
-
32
+ Deprecation.warn Blacklight::LegacyControllerMethods, "#default_html_head is deprecated"
29
33
  end
30
34
 
35
+ def default_html_head_without_deprecation
36
+ Deprecation.silence(Blacklight::LegacyControllerMethods) do
37
+ default_html_head
38
+ end
39
+ end
31
40
 
32
41
  # An array of strings to be added to HTML HEAD section of view.
33
42
  # See ApplicationHelper#render_head_content for details.
34
43
  def extra_head_content
44
+ Deprecation.warn Blacklight::LegacyControllerMethods, "#extra_head_content is deprecated"
45
+
35
46
  @extra_head_content ||= []
36
47
  end
37
48
 
38
-
39
49
  # Array, where each element is an array of arguments to
40
50
  # Rails stylesheet_link_tag helper. See
41
51
  # ApplicationHelper#render_head_content for details.
42
52
  def stylesheet_links
53
+ Deprecation.warn Blacklight::LegacyControllerMethods, "#stylesheet_links is deprecated"
54
+
43
55
  @stylesheet_links ||= []
44
56
  end
45
57
 
@@ -47,6 +59,8 @@ module Blacklight
47
59
  # Rails javascript_include_tag helper. See
48
60
  # ApplicationHelper#render_head_content for details.
49
61
  def javascript_includes
62
+ Deprecation.warn Blacklight::LegacyControllerMethods, "#javascript_includes is deprecated"
63
+
50
64
  @javascript_includes ||= []
51
65
  end
52
66
 
@@ -16,6 +16,9 @@ require 'rsolr'
16
16
  #
17
17
 
18
18
  module Blacklight::Solr::Document
19
+ extend Deprecation
20
+ self.deprecation_horizon = 'Blacklight 5.x'
21
+
19
22
  autoload :Marc, 'blacklight/solr/document/marc'
20
23
  autoload :MarcExport, 'blacklight/solr/document/marc_export'
21
24
  autoload :DublinCore, 'blacklight/solr/document/dublin_core'
@@ -159,7 +162,10 @@ module Blacklight::Solr::Document
159
162
  attr_writer :unique_key
160
163
  def unique_key
161
164
  # XXX Blacklight.config[:unique_key] should be deprecated soon
162
- @unique_key ||= Blacklight.config[:unique_key] if Blacklight.respond_to?(:config) and Blacklight.config[:unique_key]
165
+ if Blacklight.respond_to?(:config) and Blacklight.config[:unique_key]
166
+ Deprecation.warn(self, "Setting the unique key using Blacklight.config[:unique_key] has been deprecated. Use the SolrDocument.unique_key= setter instead")
167
+ @unique_key ||= Blacklight.config[:unique_key]
168
+ end
163
169
  @unique_key ||= 'id'
164
170
 
165
171
  @unique_key
@@ -6,6 +6,9 @@
6
6
  # that provides a #to_marc returning a ruby-marc object. This module will add
7
7
  # in export_as translation methods for a variety of formats.
8
8
  module Blacklight::Solr::Document::MarcExport
9
+ extend Deprecation
10
+ self.deprecation_horizon = 'Blacklight 5.x'
11
+
9
12
 
10
13
  def self.register_export_formats(document)
11
14
  document.will_export_as(:xml)
@@ -104,14 +107,6 @@ module Blacklight::Solr::Document::MarcExport
104
107
  # proprietary marc-ish in text/plain format. See
105
108
  # http://robotlibrarian.billdueber.com/sending-marcish-data-to-refworks/
106
109
  def export_as_refworks_marc_txt
107
- # plugin/gem weirdness means we do need to manually require
108
- # here.
109
- # As of 11 May 2010, Refworks has a problem with UTF-8 if it's decomposed,
110
- # it seems to want C form normalization, although RefWorks support
111
- # couldn't tell me that. -jrochkind
112
- # DHF: moved this require a little lower in the method.
113
- # require 'unicode'
114
-
115
110
  fields = to_marc.find_all { |f| ('000'..'999') === f.tag }
116
111
  text = "LEADER #{to_marc.leader}"
117
112
  fields.each do |field|
@@ -129,19 +124,12 @@ module Blacklight::Solr::Document::MarcExport
129
124
  end
130
125
  end
131
126
 
132
- if Blacklight.jruby?
133
- require 'java'
134
- java_import java.text.Normalizer
135
- Normalizer.normalize(text, Normalizer::Form::NFC).to_s
136
- else
137
- begin
138
- require 'unicode'
139
- Unicode.normalize_C(text)
140
- rescue LoadError
141
- Blacklight.logger.warn "Unable to load unicode library in #export_as_refworks_marc_txt; skipping unicode normalization"
142
- text
143
- end
144
- end
127
+ # As of 11 May 2010, Refworks has a problem with UTF-8 if it's decomposed,
128
+ # it seems to want C form normalization, although RefWorks support
129
+ # couldn't tell me that. -jrochkind
130
+ text = ActiveSupport::Multibyte::Unicode.normalize(text, :c)
131
+
132
+ return text
145
133
  end
146
134
 
147
135
  # Endnote Import Format. See the EndNote User Guide at:
@@ -209,17 +197,17 @@ module Blacklight::Solr::Document::MarcExport
209
197
  # be gotten rid of eventually.
210
198
 
211
199
  def to_zotero(format)
212
- warn("[DEPRECATION] Simply call document.export_as_openurl_kev to get an openURL kev context object suitable for including in a COinS; then have view code make the span for the COinS. ")
200
+ Deprecation.warn(self, "Simply call document.export_as_openurl_kev to get an openURL kev context object suitable for including in a COinS; then have view code make the span for the COinS. ")
213
201
  "<span class=\"Z3988\" title=\"#{export_as_openurl_kev(format)}\"></span>"
214
202
  end
215
203
 
216
204
  def to_apa
217
- warn("[DEPRECATION] Call document.export_as_apa_citation instead.")
205
+ Deprecation.warn(self, "Call document.export_as_apa_citation instead.")
218
206
  export_as_apa_citation
219
207
  end
220
208
 
221
209
  def to_mla
222
- warn("[DEPRECATION] Call document.export_as_mla_citation instead.")
210
+ Deprecation.warn(self, "Call document.export_as_mla_citation instead.")
223
211
  end
224
212
 
225
213
 
@@ -45,6 +45,9 @@
45
45
  # end
46
46
 
47
47
  module Blacklight::SolrHelper
48
+ extend Deprecation
49
+ self.deprecation_horizon = 'Blacklight 5.x'
50
+
48
51
  extend ActiveSupport::Concern
49
52
  include Blacklight::SearchFields
50
53
  include Blacklight::Facet
@@ -148,7 +151,7 @@ module Blacklight::SolrHelper
148
151
  # generated blacklight_config.default_solr_params with that
149
152
  # value. Move it over to rows.
150
153
  if solr_params.has_key?(:per_page)
151
- $stderr.puts "DEPRECATION WARNING: Blacklight::SolrHelper#solr_search_params: magic :per_page key deprecated, use :rows instead. (Check default_solr_params in blacklight config?)"
154
+ Deprecation.warn self, "Blacklight::SolrHelper#solr_search_params: magic :per_page key deprecated, use :rows instead. (Check default_solr_params in blacklight config?)"
152
155
  per_page = solr_params.delete(:per_page)
153
156
  solr_params[:rows] ||= per_page
154
157
  end
@@ -15,6 +15,12 @@ module Blacklight::SolrResponse::PaginationMethods
15
15
  total
16
16
  end
17
17
 
18
+ def model_name
19
+ if !docs.empty? and docs.first.respond_to? :model_name
20
+ docs.first.model_name
21
+ end
22
+ end
23
+
18
24
  ## Methods in kaminari master that we'd like to use today.
19
25
  # Next page number in the collection
20
26
  def next_page
@@ -20,10 +20,6 @@ This generator makes the following changes to your application:
20
20
  Thank you for Installing Blacklight.
21
21
  """
22
22
 
23
- def add_unicode_gem
24
- gem "unicode", :platforms => [:mri_18, :mri_19] unless defined?(:RUBY_VERSION) and RUBY_VERSION == '2.0.0'
25
- end
26
-
27
23
  def add_bootstrap_gem
28
24
  # Don't need a version here, because we specify the version in blacklight.gemspec
29
25
  gem 'bootstrap-sass'
@@ -17,7 +17,7 @@ module Blacklight
17
17
  # register_alias) will allow content-negotiation for the format.
18
18
  def add_mime_types
19
19
  puts "Updating Mime Types"
20
- insert_into_file "config/initializers/mime_types.rb", :after => "# Be sure to restart your server when you modify this file." do <<EOF
20
+ insert_into_file "config/initializers/mime_types.rb", :after => "# Be sure to restart your server when you modify this file.\n" do <<EOF
21
21
  Mime::Type.register_alias "text/plain", :refworks_marc_txt
22
22
  Mime::Type.register_alias "text/plain", :openurl_kev
23
23
  Mime::Type.register "application/x-endnote-refer", :endnote
@@ -63,4 +63,4 @@ EOF
63
63
  end
64
64
 
65
65
  end
66
- end
66
+ end
@@ -7,12 +7,14 @@ describe ApplicationController do
7
7
  describe "head content from variables" do
8
8
 
9
9
  describe "#default_html_head" do
10
- it "should setup js and css defaults" do
11
- controller.send(:default_html_head)
12
-
13
- # by default, these should be empty, but left in for backwards compatibility
14
- controller.javascript_includes.should be_empty
15
- controller.stylesheet_links.should be_empty
10
+ it "should setup js and css defaults" do
11
+ Deprecation.silence(Blacklight::LegacyControllerMethods) do
12
+ controller.send(:default_html_head)
13
+
14
+ # by default, these should be empty, but left in for backwards compatibility
15
+ controller.javascript_includes.should be_empty
16
+ controller.stylesheet_links.should be_empty
17
+ end
16
18
  end
17
19
  end
18
20
 
@@ -138,7 +138,7 @@ describe CatalogController do
138
138
 
139
139
  it "should get the documents" do
140
140
  docs.size.should == 10
141
- docs.first.keys.should == ["published_display", "author_display", "lc_callnum_display", "pub_date", "subtitle_display", "format", "material_type_display", "title_display", "id", "subject_topic_facet", "language_facet", "score"]
141
+ expect(docs.first.keys).to match_array(["published_display", "author_display", "lc_callnum_display", "pub_date", "subtitle_display", "format", "material_type_display", "title_display", "id", "subject_topic_facet", "language_facet", "score"])
142
142
  end
143
143
 
144
144
  it "should get the facets" do
@@ -150,8 +150,8 @@ describe CatalogController do
150
150
  let(:query_facet_items) { facets.last['items'] }
151
151
  let(:regular_facet_items) { facets.first['items'] }
152
152
  it "should have items with labels and values" do
153
- query_facet_items.first['label'].should == 'within 5 Years'
154
- query_facet_items.first['value'].should == 'years_5'
153
+ query_facet_items.first['label'].should == 'within 10 Years'
154
+ query_facet_items.first['value'].should == 'years_10'
155
155
  regular_facet_items.first['label'].should == "Book"
156
156
  regular_facet_items.first['value'].should == "Book"
157
157
  end
@@ -191,7 +191,7 @@ describe CatalogController do
191
191
  get :show, id: doc_id, format: 'json'
192
192
  response.should be_success
193
193
  json = JSON.parse response.body
194
- json["response"]["document"].keys.should == ["author_t", "opensearch_display", "marc_display", "published_display", "author_display", "lc_callnum_display", "title_t", "pub_date", "pub_date_sort", "subtitle_display", "format", "url_suppl_display", "material_type_display", "title_display", "subject_addl_t", "subject_t", "isbn_t", "id", "title_addl_t", "subject_geo_facet", "subject_topic_facet", "author_addl_t", "language_facet", "subtitle_t", "timestamp"]
194
+ expect(json["response"]["document"].keys).to match_array(["author_t", "opensearch_display", "marc_display", "published_display", "author_display", "lc_callnum_display", "title_t", "pub_date", "pub_date_sort", "subtitle_display", "format", "url_suppl_display", "material_type_display", "title_display", "subject_addl_t", "subject_t", "isbn_t", "id", "title_addl_t", "subject_geo_facet", "subject_topic_facet", "author_addl_t", "language_facet", "subtitle_t", "timestamp"])
195
195
  end
196
196
  end
197
197
 
@@ -26,7 +26,7 @@ describe "Did You Mean" do
26
26
  expect(page).to have_content("Did you mean")
27
27
  click_link 'yehudiyim'
28
28
  within ("#sortAndPerPage") do
29
- expect(page).to have_content "1 to 1 of 1"
29
+ expect(page).to have_content "1 entry found"
30
30
  end
31
31
  within ("select#search_field") do
32
32
  expect(page).to have_selector("option[selected]", text: "Title")
@@ -44,7 +44,7 @@ describe "Did You Mean" do
44
44
  expect(page).to have_content("Did you mean")
45
45
  click_link 'sharma'
46
46
  within ("#sortAndPerPage") do
47
- expect(page).to have_content "1 to 1 of 1"
47
+ expect(page).to have_content "1 entry found"
48
48
  end
49
49
  within ("select#search_field") do
50
50
  expect(page).to have_selector("option[selected]", text: "Author")
@@ -91,7 +91,7 @@ describe "Did You Mean" do
91
91
 
92
92
  click_link 'bon'
93
93
  within ("#sortAndPerPage") do
94
- expect(page).to have_content "1 to 1 of 1"
94
+ expect(page).to have_content "1 entry found"
95
95
  end
96
96
  end
97
97
 
@@ -46,7 +46,7 @@ describe "Facets" do
46
46
  click_link "2004"
47
47
 
48
48
  within ("#sortAndPerPage") do
49
- expect(page).to have_content "1 to 1 of 1"
49
+ expect(page).to have_content "1 entry found"
50
50
  end
51
51
  within(".blacklight-language_facet") do
52
52
  expect(page).to have_selector("span.selected", :text => "Tibetan 1")
@@ -74,7 +74,7 @@ describe "Search Page" do
74
74
  expect(page).to have_content "1."
75
75
  end
76
76
  within ("#sortAndPerPage") do
77
- expect(page).to have_content "1 to 1 of 1"
77
+ expect(page).to have_content "1 entry found"
78
78
  end
79
79
  end
80
80
 
@@ -670,10 +670,16 @@ describe BlacklightHelper do
670
670
 
671
671
 
672
672
  describe "render_grouped_response?" do
673
- it "should check if the response contains grouped data" do
673
+ it "should check if the response ivar contains grouped data" do
674
674
  assign(:response, double("SolrResponse", :grouped? => true))
675
675
  expect(helper.render_grouped_response?).to be_true
676
676
  end
677
+
678
+
679
+ it "should check if the response param contains grouped data" do
680
+ response = double("SolrResponse", :grouped? => true)
681
+ expect(helper.render_grouped_response?(response)).to be_true
682
+ end
677
683
  end
678
684
 
679
685
  describe "render_grouped_document_index" do
@@ -10,14 +10,11 @@ describe CatalogHelper do
10
10
  total = args[:total]
11
11
  start = (current_page - 1) * per_page
12
12
 
13
- mock_response = double("Blacklight::SolrResponse")
14
- mock_response.stub(:total_count).and_return(total)
15
- mock_response.stub(:current_page).and_return(current_page)
16
- mock_response.stub(:total_pages).and_return((total / per_page).to_i + 1)
17
- mock_response.stub(:rows).and_return(per_page)
18
- mock_response.stub(:start).and_return(start)
19
- mock_response.stub(:docs).and_return((1..total).to_a.slice(start, per_page))
13
+ mock_docs = (1..total).to_a.map { {}.with_indifferent_access }
14
+
15
+ mock_response = Kaminari.paginate_array(mock_docs).page(current_page).per(per_page)
20
16
 
17
+ mock_response.stub(:docs).and_return(mock_docs.slice(start, per_page))
21
18
  mock_response
22
19
  end
23
20
 
@@ -26,14 +23,14 @@ describe CatalogHelper do
26
23
  end
27
24
 
28
25
 
29
- describe "render_pagination_info" do
26
+ describe "page_entries_info" do
30
27
  before(:all) do
31
28
  end
32
29
 
33
30
  it "with no results" do
34
31
  @response = mock_response :total => 0
35
32
 
36
- html = render_pagination_info(@response, { :entry_name => 'entry_name' })
33
+ html = page_entries_info(@response, { :entry_name => 'entry_name' })
37
34
  html.should == "No entry_names found"
38
35
  html.html_safe?.should == true
39
36
  end
@@ -41,23 +38,42 @@ describe CatalogHelper do
41
38
  it "with no results (and no entry_name provided)" do
42
39
  @response = mock_response :total => 0
43
40
 
44
- html = render_pagination_info(@response)
41
+ html = page_entries_info(@response)
45
42
  html.should == "No entries found"
46
43
  html.html_safe?.should == true
47
44
  end
48
45
 
49
- it "with a single result" do
50
- @response = mock_response :total => 1
46
+ describe "with a single result" do
47
+ it "should use the provided entry name" do
48
+ response = mock_response :total => 1
51
49
 
52
- html = render_pagination_info(@response, { :entry_name => 'entry_name' })
53
- html.should == "<strong>1</strong> to <strong>1</strong> of <strong>1</strong>"
54
- html.html_safe?.should == true
50
+ html = page_entries_info(response, { :entry_name => 'entry_name' })
51
+ html.should == "<strong>1</strong> entry_name found"
52
+ html.html_safe?.should == true
53
+ end
54
+
55
+ it "should infer a name" do
56
+ response = mock_response :total => 1
57
+
58
+ html = page_entries_info(response)
59
+ html.should == "<strong>1</strong> entry found"
60
+ html.html_safe?.should == true
61
+ end
62
+
63
+ it "should use the model_name from the response" do
64
+ response = mock_response :total => 1
65
+ response.stub(:model_name).and_return('thingy')
66
+
67
+ html = page_entries_info(response)
68
+ expect(html).to eq "<strong>1</strong> thingy found"
69
+ expect(html).to be_html_safe
70
+ end
55
71
  end
56
72
 
57
73
  it "with a single page of results" do
58
- @response = mock_response :total => 7
74
+ response = mock_response :total => 7
59
75
 
60
- html = render_pagination_info(@response, { :entry_name => 'entry_name' })
76
+ html = page_entries_info(response, { :entry_name => 'entry_name' })
61
77
  html.should == "<strong>1</strong> - <strong>7</strong> of <strong>7</strong>"
62
78
  html.html_safe?.should == true
63
79
  end
@@ -65,7 +81,7 @@ describe CatalogHelper do
65
81
  it "on the first page of multiple pages of results" do
66
82
  @response = mock_response :total => 15, :per_page => 10
67
83
 
68
- html = render_pagination_info(@response, { :entry_name => 'entry_name' })
84
+ html = page_entries_info(@response, { :entry_name => 'entry_name' })
69
85
  html.should == "<strong>1</strong> - <strong>10</strong> of <strong>15</strong>"
70
86
  html.html_safe?.should == true
71
87
  end
@@ -73,7 +89,7 @@ describe CatalogHelper do
73
89
  it "on the second page of multiple pages of results" do
74
90
  @response = mock_response :total => 47, :per_page => 10, :current_page => 2
75
91
 
76
- html = render_pagination_info(@response, { :entry_name => 'entry_name' })
92
+ html = page_entries_info(@response, { :entry_name => 'entry_name' })
77
93
  html.should == "<strong>11</strong> - <strong>20</strong> of <strong>47</strong>"
78
94
  html.html_safe?.should == true
79
95
  end
@@ -81,14 +97,14 @@ describe CatalogHelper do
81
97
  it "on the last page of results" do
82
98
  @response = mock_response :total => 47, :per_page => 10, :current_page => 5
83
99
 
84
- html = render_pagination_info(@response, { :entry_name => 'entry_name' })
100
+ html = page_entries_info(@response, { :entry_name => 'entry_name' })
85
101
  html.should == "<strong>41</strong> - <strong>47</strong> of <strong>47</strong>"
86
102
  html.html_safe?.should == true
87
103
  end
88
104
  it "should work with rows the same as per_page" do
89
105
  @response = mock_response :total => 47, :rows => 20, :current_page => 2
90
106
 
91
- html = render_pagination_info(@response, { :entry_name => 'entry_name' })
107
+ html = page_entries_info(@response, { :entry_name => 'entry_name' })
92
108
  html.should == "<strong>21</strong> - <strong>40</strong> of <strong>47</strong>"
93
109
  html.html_safe?.should == true
94
110
  end