blacklight 4.6.2 → 4.6.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2973df853ccd78aa817fb76e2b5f2aaec1273b55
4
- data.tar.gz: 4e6e6d1ad0d678deb64588ce0a3b81628c8a10dc
3
+ metadata.gz: 5982a2428034dae378c31791d1d9d4a2cfcdd02d
4
+ data.tar.gz: dbe8685099072975e318962fd879410db0bec8f4
5
5
  SHA512:
6
- metadata.gz: 0978b221b5f4308e8ee8011826ab39cad5fd69fc122399ae0b0d45ab1373e9db21ed099e6c4c69b159caa988633c02babb6988cd3eb2b6a52e684bf5df5eafe5
7
- data.tar.gz: d0f6f2e7324af35f7c9d967de599ab24f0a9153942e2d15209d9b1aee19bd7c02b7b4cfe82690bbda17ec0e708aa6c9ca8deb5f41df9591bbb6d907fb70aee5e
6
+ metadata.gz: 49c5477a3ee2d0e5418a9cd4b1cad1683864398373be03b267a7896c4e8c6f850218163a98e6f0e4faf039bacdbef5ebf5782b23a06e29257780b83af685ce64
7
+ data.tar.gz: cee3f4ff93d8301b3e30e4fd8fc784486eaae15b47c209258b50c3d1b86adf53ccd7bd64ebae4233261f5c793312925164c43f8c9262c24fcecf81b1064b6592
data/LICENSE CHANGED
@@ -1,5 +1,6 @@
1
1
  ##########################################################################
2
- # Copyright 2008 Rector and Visitors of the University of Virginia
2
+ # Copyright 2008-2014 Rector and Visitors of the University of Virginia, The Board of Trustees of the Leland Stanford Junior University, Johns Hopkins Universities, and Data Curation Experts
3
+ # Additional copyright may be held by others, as reflected in the commit log
3
4
  #
4
5
  # Licensed under the Apache License, Version 2.0 (the "License");
5
6
  # you may not use this file except in compliance with the License.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.6.2
1
+ 4.6.3
@@ -1,6 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class FeedbackController < ApplicationController
3
3
 
4
+ extend Deprecation
5
+ self.deprecation_horizon = 'Blacklight 5.x'
6
+
4
7
  # http://expressica.com/simple_captcha/
5
8
  # include SimpleCaptcha::ControllerHelpers
6
9
 
@@ -14,6 +17,7 @@ class FeedbackController < ApplicationController
14
17
  end
15
18
  end
16
19
  end
20
+ deprecation_deprecate :show
17
21
 
18
22
  protected
19
23
 
@@ -368,14 +368,18 @@ module Blacklight::BlacklightHelperBehavior
368
368
  ', '
369
369
  end
370
370
 
371
- def document_index_view_type
372
- if blacklight_config.document_index_view_types.include? params[:view]
373
- params[:view]
371
+ def document_index_view_type query_params=params
372
+ if blacklight_config.document_index_view_types.include? query_params[:view]
373
+ query_params[:view]
374
374
  else
375
- blacklight_config.document_index_view_types.first
375
+ default_document_index_view_type
376
376
  end
377
377
  end
378
378
 
379
+ def default_document_index_view_type
380
+ blacklight_config.document_index_view_types.first
381
+ end
382
+
379
383
  def render_document_index documents = nil, locals = {}
380
384
  documents ||= @document_list
381
385
  render_document_index_with_view(document_index_view_type, documents)
@@ -464,6 +468,17 @@ module Blacklight::BlacklightHelperBehavior
464
468
  link_to(query, link_url)
465
469
  end
466
470
 
471
+ ##
472
+ # Get the path to the search action with any parameters (e.g. view type)
473
+ # that should be persisted across search sessions.
474
+ def start_over_path query_params = params
475
+ h = { }
476
+ current_index_view_type = document_index_view_type(query_params)
477
+ h[:view] = current_index_view_type unless current_index_view_type == default_document_index_view_type
478
+
479
+ search_action_url(h)
480
+ end
481
+
467
482
  def render_document_index_label doc, opts
468
483
  label = nil
469
484
  label ||= doc.get(opts[:label], :sep => nil) if opts[:label].instance_of? Symbol
@@ -19,6 +19,7 @@ module Blacklight::CatalogHelperBehavior
19
19
  # kaminari paginate, passed on through.
20
20
  # will output HTML pagination controls.
21
21
  def paginate_rsolr_response(response, options = {}, &block)
22
+ Deprecation.warn Blacklight::CatalogHelperBehavior, "#paginate_rsolr_response is deprecated; the original response object is Kaminari-compatible"
22
23
  paginate response, options, &block
23
24
  end
24
25
 
@@ -58,7 +58,23 @@ module Blacklight::FacetsHelperBehavior
58
58
  # @param [Blacklight::SolrResponse::Facets::FacetField] display_facet
59
59
  def should_render_facet? display_facet
60
60
  # display when show is nil or true
61
- display = facet_configuration_for_field(display_facet.name).show != false
61
+ facet_config = facet_configuration_for_field(display_facet.name)
62
+
63
+ display = case facet_config.show
64
+ when Symbol
65
+ arity = method(facet_config.show).arity
66
+
67
+ if arity == 0
68
+ send(facet_config.show)
69
+ else
70
+ send(facet_config.show, display_facet)
71
+ end
72
+ when Proc
73
+ facet_config.show.call self, facet_config, display_facet
74
+ else
75
+ facet_config.show
76
+ end
77
+
62
78
  return display && display_facet.items.present?
63
79
  end
64
80
 
@@ -2,7 +2,7 @@
2
2
  <div id="appliedParams" class="constraints-container">
3
3
  <span class="constraints-label"><%= t('blacklight.search.filters.title') %></span>
4
4
 
5
- <%=link_to t('blacklight.search.start_over'), url_for(:action=>'index'), :class => "catalog_startOverLink", :id=>"startOverLink" %>
5
+ <%=link_to t('blacklight.search.start_over'), start_over_path, :class => "catalog_startOverLink btn btn-sm btn-text", :id=>"startOverLink" %>
6
6
  <%= render_constraints(params) %>
7
7
 
8
8
  </div>
@@ -10,7 +10,7 @@
10
10
  <div class="pull-right">
11
11
  <%= link_back_to_catalog %>
12
12
  |
13
- <%=link_to "#{t('blacklight.search.start_over')}", catalog_index_path, :id=>"startOverLink" %>
13
+ <%=link_to "#{t('blacklight.search.start_over')}", start_over_path(current_search_session.try(:query_params) || {}), :id=>"startOverLink" %>
14
14
  </div>
15
15
  </div>
16
16
  <% end %>
@@ -25,7 +25,8 @@ module Blacklight
25
25
  :search_history_window => Blacklight::Catalog::SearchHistoryWindow,
26
26
  :document_index_view_types => ['list'],
27
27
  :add_facet_fields_to_solr_request => false,
28
- :add_field_configuration_to_solr_request => false
28
+ :add_field_configuration_to_solr_request => false,
29
+ :http_method => :get
29
30
  }
30
31
  end
31
32
  end
@@ -7,6 +7,8 @@ module Blacklight
7
7
  self.tag = "#{self.field}_single"
8
8
  self.ex = "#{self.field}_single"
9
9
  end
10
+
11
+ self.show = true if self.show.nil?
10
12
  super
11
13
  end
12
14
  end
@@ -2,6 +2,26 @@
2
2
  module Blacklight
3
3
  class Routes
4
4
 
5
+ # adds as class and instance level accessors, default_route_sets
6
+ # returns an array of symbols for method names that define routes.
7
+ # Order is important:. (e.g. /catalog/email precedes /catalog/:id)
8
+ #
9
+ # Add-ons that want to add routes into default routing might
10
+ # monkey-patch Blacklight::Routes, say:
11
+ #
12
+ # module MyWidget::Routes
13
+ # extend ActiveSupport::Concern
14
+ # included do |klass|
15
+ # klass.default_route_sets += [:widget_routing]
16
+ # end
17
+ # def widget_routing(primary_resource)
18
+ # get "#{primary_resource}/widget", "#{primary_resource}#widget"
19
+ # end
20
+ # end
21
+ # Blacklight::Routes.send(:include, MyWidget::Routes)
22
+ class_attribute :default_route_sets
23
+ self.default_route_sets = [:bookmarks, :search_history, :saved_searches, :catalog, :solr_document, :feedback]
24
+
5
25
  def initialize(router, options)
6
26
  @router = router
7
27
  @options = options
@@ -23,10 +43,6 @@ module Blacklight
23
43
  (@options[:only] || default_route_sets) - (@options[:except] || [])
24
44
  end
25
45
 
26
- def default_route_sets
27
- [:bookmarks, :search_history, :saved_searches, :catalog, :solr_document, :feedback]
28
- end
29
-
30
46
  module RouteSets
31
47
  def bookmarks
32
48
  add_routes do |options|
@@ -415,7 +415,8 @@ module Blacklight::SolrHelper
415
415
  path = blacklight_config.solr_path
416
416
 
417
417
  # delete these parameters, otherwise rsolr will pass them through.
418
- res = blacklight_solr.send_and_receive(path, :params=>solr_params)
418
+ key = blacklight_config.http_method == :post ? :data : :params
419
+ res = blacklight_solr.send_and_receive(path, {key=>solr_params, method:blacklight_config.http_method})
419
420
 
420
421
  solr_response = Blacklight::SolrResponse.new(force_to_utf8(res), solr_params)
421
422
 
@@ -334,6 +334,26 @@ describe BlacklightHelper do
334
334
  params[:view] = 'not_in_list'
335
335
  document_index_view_type.should == 'list'
336
336
  end
337
+
338
+ it "should pluck values from supplied params" do
339
+ blacklight_config.stub(:document_index_view_types) { ['list', 'asdf'] }
340
+ params[:view] = 'asdf'
341
+ expect(document_index_view_type(:view => 'list')).to eq 'list'
342
+ end
343
+ end
344
+
345
+ describe "start_over_path" do
346
+ it 'should be the catalog path with the current view type' do
347
+ blacklight_config.stub(:document_index_view_types) { ['list', 'abc'] }
348
+ helper.stub(:blacklight_config => blacklight_config)
349
+ expect(helper.start_over_path(:view => 'abc')).to eq catalog_index_url(:view => 'abc')
350
+ end
351
+
352
+ it 'should not include the current view type if it is the default' do
353
+ blacklight_config.stub(:document_index_view_types) { ['list', 'abc'] }
354
+ helper.stub(:blacklight_config => blacklight_config)
355
+ expect(helper.start_over_path(:view => 'list')).to eq catalog_index_url
356
+ end
337
357
  end
338
358
 
339
359
  describe "render_document_index" do
@@ -34,11 +34,16 @@ describe FacetsHelper do
34
34
  before do
35
35
  @config = Blacklight::Configuration.new do |config|
36
36
  config.add_facet_field 'basic_field'
37
- config.add_facet_field 'no_show', :show=>false
37
+ config.add_facet_field 'no_show', :show => false
38
+ config.add_facet_field 'helper_show', :show => :my_helper
39
+ config.add_facet_field 'helper_with_an_arg_show', :show => :my_helper_with_an_arg
40
+ config.add_facet_field 'lambda_show', :show => lambda { |context, config, field| true }
41
+ config.add_facet_field 'lambda_no_show', :show => lambda { |context, config, field| false }
38
42
  end
39
43
 
40
44
  helper.stub(:blacklight_config => @config)
41
45
  end
46
+
42
47
  it "should render facets with items" do
43
48
  a = double(:items => [1,2], :name=>'basic_field')
44
49
  helper.should_render_facet?(a).should == true
@@ -52,6 +57,27 @@ describe FacetsHelper do
52
57
  a = double(:items => [1,2], :name=>'no_show')
53
58
  helper.should_render_facet?(a).should == false
54
59
  end
60
+
61
+ it "should call a helper to determine if it should render a field" do
62
+ helper.stub(:my_helper => true)
63
+ a = double(:items => [1,2], :name=>'helper_show')
64
+ expect(helper.should_render_facet?(a)).to be_true
65
+ end
66
+
67
+ it "should call a helper to determine if it should render a field" do
68
+ a = double(:items => [1,2], :name=>'helper_with_an_arg_show')
69
+ helper.should_receive(:my_helper_with_an_arg).with(a).and_return(true)
70
+ expect(helper.should_render_facet?(a)).to be_true
71
+ end
72
+
73
+
74
+ it "should evaluate a Proc to determine if it should render a field" do
75
+ a = double(:items => [1,2], :name=>'lambda_show')
76
+ expect(helper.should_render_facet?(a)).to be_true
77
+
78
+ a = double(:items => [1,2], :name=>'lambda_no_show')
79
+ expect(helper.should_render_facet?(a)).to be_false
80
+ end
55
81
  end
56
82
 
57
83
  describe "facet_by_field_name" do
@@ -1150,5 +1150,40 @@ describe 'Blacklight::SolrHelper' do
1150
1150
  end
1151
1151
  end
1152
1152
 
1153
+ describe "http_method configuration" do
1154
+ describe "using default" do
1155
+ let (:blacklight_config) {Blacklight::Configuration.new}
1156
+
1157
+ it "defaults to get" do
1158
+ expect(blacklight_config.http_method).to eq :get
1159
+ Blacklight.solr.should_receive(:send_and_receive) do |path, params|
1160
+ expect(path).to eq 'select'
1161
+ expect(params[:method]).to eq :get
1162
+ expect(params[:params]).to include(:q)
1163
+ end.and_return({'response'=>{'docs'=>[]}})
1164
+ get_search_results(:q => @all_docs_query)
1165
+ end
1166
+ end
1167
+
1168
+ describe "setting to post" do
1169
+ let (:blacklight_config) {config = Blacklight::Configuration.new; config.http_method=:post; config}
1170
+
1171
+ it "keep value set to post" do
1172
+ expect(blacklight_config.http_method).to eq :post
1173
+ Blacklight.solr.should_receive(:send_and_receive) do |path, params|
1174
+ expect(path).to eq 'select'
1175
+ expect(params[:method]).to eq :post
1176
+ expect(params[:data]).to include(:q)
1177
+ end.and_return({'response'=>{'docs'=>[]}})
1178
+ get_search_results(:q => @all_docs_query)
1179
+ end
1180
+
1181
+ it "should send a post request to solr", :integration => true do
1182
+ response, docs = get_search_results(:q => @all_docs_query)
1183
+ expect(docs.length).to be >= 1
1184
+ end
1185
+ end
1186
+ end
1187
+
1153
1188
  end
1154
1189
 
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Blacklight::Routes" do
4
+ describe "default_route_sets" do
5
+ around do |example|
6
+ @original = Blacklight::Routes.default_route_sets.dup.freeze
7
+
8
+ example.run
9
+
10
+ Blacklight::Routes.default_route_sets = @original
11
+ end
12
+
13
+ it "is settable" do
14
+ Blacklight::Routes.default_route_sets += [:foo]
15
+
16
+ # Order DOES matter.
17
+ expect(Blacklight::Routes.default_route_sets).to eq(@original + [:foo])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe "catalog/constraints" do
4
+ let :blacklight_config do
5
+ Blacklight::Configuration.new :document_index_view_types => ['list', 'xyz']
6
+ end
7
+
8
+ it "should render nothing if no constraints are set" do
9
+ view.stub(query_has_constraints?: false)
10
+ render partial: "catalog/constraints"
11
+ expect(rendered).to be_empty
12
+ end
13
+
14
+ it "should render a start over link" do
15
+ view.should_receive(:search_action_url).with({}).and_return('http://xyz')
16
+ view.stub(query_has_constraints?: true)
17
+ view.stub(:blacklight_config).and_return(blacklight_config)
18
+ render partial: "catalog/constraints"
19
+ expect(rendered).to have_selector("#startOverLink")
20
+ expect(rendered).to have_link("Start Over", :href => 'http://xyz')
21
+ end
22
+
23
+ it "should render a start over link with the current view type" do
24
+ view.should_receive(:search_action_url).with(view: 'xyz').and_return('http://xyz?view=xyz')
25
+ view.stub(query_has_constraints?: true)
26
+ params[:view] = 'xyz'
27
+ view.stub(:blacklight_config).and_return(blacklight_config)
28
+ render partial: "catalog/constraints"
29
+ expect(rendered).to have_selector("#startOverLink")
30
+ expect(rendered).to have_link("Start Over", :href => 'http://xyz?view=xyz')
31
+ end
32
+
33
+ end
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: 4.6.2
4
+ version: 4.6.3
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: 2014-01-17 00:00:00.000000000 Z
20
+ date: 2014-01-30 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -502,6 +502,7 @@ files:
502
502
  - spec/rcov.opts
503
503
  - spec/requests/alternate_controller_spec.rb
504
504
  - spec/routing/catalog_routing_spec.rb
505
+ - spec/routing/routes_spec.rb
505
506
  - spec/spec.opts
506
507
  - spec/spec_helper.rb
507
508
  - spec/support/assert_difference.rb
@@ -511,6 +512,7 @@ files:
511
512
  - spec/test_app_templates/Gemfile.extra
512
513
  - spec/test_app_templates/lib/generators/test_app_generator.rb
513
514
  - spec/test_app_templates/lib/tasks/blacklight_test_app.rake
515
+ - spec/views/catalog/_constraints.html.erb_spec.rb
514
516
  - spec/views/catalog/_constraints_element.html.erb_spec.rb
515
517
  - spec/views/catalog/_document.html.erb_spec.rb
516
518
  - spec/views/catalog/_document_list.html.erb_spec.rb
@@ -604,6 +606,7 @@ test_files:
604
606
  - spec/rcov.opts
605
607
  - spec/requests/alternate_controller_spec.rb
606
608
  - spec/routing/catalog_routing_spec.rb
609
+ - spec/routing/routes_spec.rb
607
610
  - spec/spec.opts
608
611
  - spec/spec_helper.rb
609
612
  - spec/support/assert_difference.rb
@@ -613,6 +616,7 @@ test_files:
613
616
  - spec/test_app_templates/Gemfile.extra
614
617
  - spec/test_app_templates/lib/generators/test_app_generator.rb
615
618
  - spec/test_app_templates/lib/tasks/blacklight_test_app.rake
619
+ - spec/views/catalog/_constraints.html.erb_spec.rb
616
620
  - spec/views/catalog/_constraints_element.html.erb_spec.rb
617
621
  - spec/views/catalog/_document.html.erb_spec.rb
618
622
  - spec/views/catalog/_document_list.html.erb_spec.rb