blacklight 5.7.2 → 5.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/Gemfile +1 -4
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +38 -1
- data/app/assets/stylesheets/blacklight/_facets.css.scss +10 -0
- data/app/assets/stylesheets/blacklight/_layout.css.scss +6 -0
- data/app/controllers/bookmarks_controller.rb +3 -163
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +18 -186
- data/app/helpers/blacklight/catalog_helper_behavior.rb +36 -2
- data/app/helpers/blacklight/component_helper_behavior.rb +77 -0
- data/app/helpers/blacklight/configuration_helper_behavior.rb +30 -21
- data/app/helpers/blacklight/render_partials_helper.rb +185 -0
- data/app/helpers/blacklight/url_helper_behavior.rb +24 -3
- data/app/helpers/component_helper.rb +3 -0
- data/app/views/_user_util_links.html.erb +2 -15
- data/app/views/blacklight/nav/_bookmark.html.erb +4 -0
- data/app/views/blacklight/nav/_saved_searches.html.erb +1 -0
- data/app/views/blacklight/nav/_search_history.html.erb +1 -0
- data/app/views/bookmarks/_tools.html.erb +6 -9
- data/app/views/bookmarks/index.html.erb +1 -1
- data/app/views/catalog/_bookmark_control.html.erb +8 -8
- data/app/views/catalog/_constraints_element.html.erb +1 -1
- data/app/views/catalog/_document_action.html.erb +4 -0
- data/app/views/catalog/_email_form.html.erb +1 -1
- data/app/views/catalog/_facet_limit.html.erb +1 -1
- data/app/views/catalog/_index_header_default.html.erb +5 -6
- data/app/views/catalog/_per_page_widget.html.erb +3 -1
- data/app/views/catalog/_results_pagination.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +5 -8
- data/app/views/catalog/_show_more_like_this.html.erb +2 -2
- data/app/views/catalog/_show_tools.html.erb +5 -34
- data/app/views/catalog/_sms_form.html.erb +1 -1
- data/app/views/catalog/_sort_and_per_page.html.erb +2 -6
- data/app/views/catalog/_sort_widget.html.erb +1 -1
- data/app/views/catalog/_zero_results.html.erb +2 -2
- data/app/views/catalog/citation.js.erb +1 -1
- data/app/views/catalog/email_sent.html.erb +2 -9
- data/app/views/catalog/email_success.html.erb +9 -0
- data/app/views/catalog/sms_sent.html.erb +2 -9
- data/app/views/catalog/sms_success.html.erb +9 -0
- data/app/views/kaminari/blacklight/_gap.html.erb +1 -1
- data/app/views/kaminari/blacklight/_page.html.erb +5 -1
- data/app/views/shared/_header_navbar.html.erb +1 -1
- data/config/locales/blacklight.en.yml +1 -1
- data/config/locales/blacklight.es.yml +1 -1
- data/config/locales/blacklight.fr.yml +1 -1
- data/config/locales/blacklight.pt-BR.yml +1 -1
- data/lib/blacklight.rb +3 -0
- data/lib/blacklight/base.rb +0 -1
- data/lib/blacklight/bookmarks.rb +135 -0
- data/lib/blacklight/catalog.rb +58 -77
- data/lib/blacklight/catalog/component_configuration.rb +99 -0
- data/lib/blacklight/configuration.rb +82 -4
- data/lib/blacklight/configuration/tool_config.rb +4 -0
- data/lib/blacklight/controller.rb +5 -1
- data/lib/blacklight/document_presenter.rb +17 -8
- data/lib/blacklight/request_builders.rb +136 -4
- data/lib/blacklight/routes.rb +5 -0
- data/lib/blacklight/solr_helper.rb +90 -208
- data/lib/blacklight/solr_repository.rb +69 -0
- data/lib/blacklight/token_based_user.rb +58 -0
- data/lib/blacklight/utils.rb +13 -1
- data/lib/generators/blacklight/install_generator.rb +6 -7
- data/spec/controllers/alternate_controller_spec.rb +19 -0
- data/spec/controllers/catalog_controller_spec.rb +89 -4
- data/spec/features/alternate_controller_spec.rb +0 -1
- data/spec/features/bookmarks_spec.rb +31 -6
- data/spec/features/search_results_spec.rb +11 -0
- data/spec/features/search_spec.rb +5 -0
- data/spec/helpers/blacklight_helper_spec.rb +49 -8
- data/spec/helpers/catalog_helper_spec.rb +56 -8
- data/spec/helpers/configuration_helper_spec.rb +5 -5
- data/spec/helpers/url_helper_spec.rb +15 -8
- data/spec/lib/blacklight/catalog/component_configuration_spec.rb +29 -0
- data/spec/lib/blacklight/configuration_spec.rb +15 -0
- data/spec/lib/blacklight/solr_helper_spec.rb +44 -104
- data/spec/lib/blacklight/solr_repository_spec.rb +113 -0
- data/spec/lib/utils_spec.rb +27 -0
- data/spec/views/_user_util_links.html.erb_spec.rb +6 -3
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +8 -2
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +82 -0
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +15 -1
- data/tasks/blacklight.rake +25 -1
- metadata +24 -2
@@ -0,0 +1,69 @@
|
|
1
|
+
module Blacklight
|
2
|
+
class SolrRepository
|
3
|
+
attr_accessor :blacklight_config, :blacklight_solr
|
4
|
+
|
5
|
+
# ActiveSupport::Benchmarkable requires a logger method
|
6
|
+
attr_accessor :logger
|
7
|
+
|
8
|
+
include ActiveSupport::Benchmarkable
|
9
|
+
|
10
|
+
def initialize blacklight_config
|
11
|
+
@blacklight_config = blacklight_config
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Find a single solr document result (by id) using the document configuration
|
16
|
+
# @param [String] document's unique key value
|
17
|
+
# @param [Hash] additional solr query parameters
|
18
|
+
def find id, params = {}
|
19
|
+
solr_response = send_and_receive blacklight_config.document_solr_path || blacklight_config.solr_path, {qt: blacklight_config.document_solr_request_handler}.merge(blacklight_config.default_document_solr_params.merge(params).merge(blacklight_config.document_unique_id_param => id))
|
20
|
+
raise Blacklight::Exceptions::InvalidSolrID.new if solr_response.documents.empty?
|
21
|
+
solr_response
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Execute a search query against solr
|
26
|
+
# @param [Hash] solr query parameters
|
27
|
+
def search params = {}
|
28
|
+
send_and_receive blacklight_config.solr_path, { qt: blacklight_config.qt }.merge(params)
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Execute a solr query
|
33
|
+
# @see [RSolr::Client#send_and_receive]
|
34
|
+
# @overload find(solr_path, params)
|
35
|
+
# Execute a solr query at the given path with the parameters
|
36
|
+
# @param [String] solr path (defaults to blacklight_config.solr_path)
|
37
|
+
# @param [Hash] parameters for RSolr::Client#send_and_receive
|
38
|
+
# @overload find(params)
|
39
|
+
# @param [Hash] parameters for RSolr::Client#send_and_receive
|
40
|
+
# @return [Blacklight::SolrResponse] the solr response object
|
41
|
+
def send_and_receive(path, solr_params = {})
|
42
|
+
benchmark("Solr fetch", level: :debug) do
|
43
|
+
key = blacklight_config.http_method == :post ? :data : :params
|
44
|
+
res = blacklight_solr.send_and_receive(path, {key=>solr_params.to_hash, method:blacklight_config.http_method})
|
45
|
+
|
46
|
+
solr_response = blacklight_config.solr_response_model.new(res, solr_params, solr_document_model: blacklight_config.solr_document_model)
|
47
|
+
|
48
|
+
Rails.logger.debug("Solr query: #{solr_params.inspect}")
|
49
|
+
Rails.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) and ::BLACKLIGHT_VERBOSE_LOGGING
|
50
|
+
solr_response
|
51
|
+
end
|
52
|
+
rescue Errno::ECONNREFUSED => e
|
53
|
+
raise Blacklight::Exceptions::ECONNREFUSED.new("Unable to connect to Solr instance using #{blacklight_solr.inspect}")
|
54
|
+
end
|
55
|
+
|
56
|
+
def blacklight_solr
|
57
|
+
@blacklight_solr ||= RSolr.connect(blacklight_solr_config)
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
def blacklight_solr_config
|
62
|
+
@blacklight_solr_config ||= Blacklight.solr_config
|
63
|
+
end
|
64
|
+
|
65
|
+
def logger
|
66
|
+
@logger ||= Rails.logger if defined? Rails
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Blacklight::TokenBasedUser
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
helper_method :encrypt_user_id
|
6
|
+
|
7
|
+
rescue_from Blacklight::Exceptions::ExpiredSessionToken do
|
8
|
+
head :unauthorized
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def token_or_current_or_guest_user
|
16
|
+
token_user || current_or_guest_user
|
17
|
+
end
|
18
|
+
|
19
|
+
def token_user
|
20
|
+
@token_user ||= if params[:encrypted_user_id]
|
21
|
+
user_id = decrypt_user_id params[:encrypted_user_id]
|
22
|
+
User.find(user_id)
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Used for #export action, with encrypted user_id.
|
29
|
+
def decrypt_user_id(encrypted_user_id)
|
30
|
+
user_id, timestamp = message_encryptor.decrypt_and_verify(encrypted_user_id)
|
31
|
+
|
32
|
+
if timestamp < 1.hour.ago
|
33
|
+
raise Blacklight::Exceptions::ExpiredSessionToken.new
|
34
|
+
end
|
35
|
+
|
36
|
+
user_id
|
37
|
+
end
|
38
|
+
|
39
|
+
# Used for #export action with encrypted user_id, available
|
40
|
+
# as a helper method for views.
|
41
|
+
def encrypt_user_id(user_id)
|
42
|
+
message_encryptor.encrypt_and_sign([user_id, Time.now])
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# This method provides Rails 3 compatibility to our message encryptor.
|
47
|
+
# When we drop support for Rails 3, we can just use the AS::KeyGenerator
|
48
|
+
# directly instead of this helper.
|
49
|
+
def export_secret_token salt
|
50
|
+
OpenSSL::PKCS5.pbkdf2_hmac_sha1(Blacklight.secret_key, salt, 1000, 64)
|
51
|
+
end
|
52
|
+
|
53
|
+
def message_encryptor
|
54
|
+
derived_secret = export_secret_token("encrypted user session key")
|
55
|
+
ActiveSupport::MessageEncryptor.new(derived_secret)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/blacklight/utils.rb
CHANGED
@@ -13,6 +13,10 @@ module Blacklight
|
|
13
13
|
def [](key)
|
14
14
|
send key
|
15
15
|
end
|
16
|
+
|
17
|
+
def respond_to? method, *args
|
18
|
+
super(method, *args) || has_key?(method.to_sym)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
##
|
@@ -40,7 +44,11 @@ module Blacklight
|
|
40
44
|
# @return [OpenStructWithHashAccess] a new instance of an OpenStructWithHashAccess
|
41
45
|
def merge! other_hash
|
42
46
|
@table.merge!((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
|
43
|
-
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def deep_dup
|
50
|
+
self.class.new @table.deep_dup
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
|
@@ -119,6 +127,10 @@ module Blacklight
|
|
119
127
|
set_default_proc!
|
120
128
|
end
|
121
129
|
|
130
|
+
def deep_dup
|
131
|
+
self.class.new self.nested_class, @table.deep_dup
|
132
|
+
end
|
133
|
+
|
122
134
|
def select *args, &block
|
123
135
|
self.class.new nested_class, to_h.select(*args, &block)
|
124
136
|
end
|
@@ -55,14 +55,13 @@ module Blacklight
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Add Blacklight to the application controller
|
58
|
-
def inject_blacklight_controller_behavior
|
59
|
-
# prepend_file("app/controllers/application_controller.rb", "require 'blacklight/controller'\n\n")
|
58
|
+
def inject_blacklight_controller_behavior
|
60
59
|
inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
|
61
|
-
" # Adds a few additional behaviors into the application controller \n
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
" # Adds a few additional behaviors into the application controller \n" +
|
61
|
+
" include Blacklight::Controller\n" +
|
62
|
+
" # Please be sure to impelement current_user and user_session. Blacklight depends on \n" +
|
63
|
+
" # these methods in order to perform user specific actions. \n\n" +
|
64
|
+
" layout 'blacklight'\n\n"
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AlternateController do
|
4
|
+
describe "the search results tools" do
|
5
|
+
it "should inherit tools from CatalogController" do
|
6
|
+
expect(AlternateController.blacklight_config.index.document_actions).to have_key(:bookmark)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when deleting partials from the AlternateController" do
|
10
|
+
before do
|
11
|
+
AlternateController.blacklight_config.index.document_actions.delete(:bookmark)
|
12
|
+
end
|
13
|
+
it "should not affect the CatalogController" do
|
14
|
+
expect(AlternateController.blacklight_config.index.document_actions).to be_empty
|
15
|
+
expect(CatalogController.blacklight_config.index.document_actions).to have_key(:bookmark)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -28,6 +28,33 @@ describe CatalogController do
|
|
28
28
|
expect(session[:history]).to be_empty
|
29
29
|
end
|
30
30
|
|
31
|
+
describe "preferred view" do
|
32
|
+
it "should save the view choice" do
|
33
|
+
get :index, q: 'foo', view: 'gallery'
|
34
|
+
expect(session[:preferred_view]).to eq 'gallery'
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when they have a preferred view" do
|
38
|
+
before do
|
39
|
+
session[:preferred_view] = 'gallery'
|
40
|
+
end
|
41
|
+
|
42
|
+
context "and no view is specified" do
|
43
|
+
it "should use the saved preference" do
|
44
|
+
get :index, q: 'foo'
|
45
|
+
expect(controller.params[:view]).to eq 'gallery'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "and a view is specified" do
|
50
|
+
it "should use the saved preference" do
|
51
|
+
get :index, q: 'foo', view: 'list'
|
52
|
+
expect(controller.params[:view]).to eq 'list'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
31
58
|
# check each user manipulated parameter
|
32
59
|
it "should have docs and facets for query with results", :integration => true do
|
33
60
|
get :index, q: user_query
|
@@ -425,9 +452,9 @@ describe CatalogController do
|
|
425
452
|
expect(request.flash[:error]).to be_nil
|
426
453
|
expect(request).to redirect_to(catalog_path(doc_id))
|
427
454
|
end
|
428
|
-
it "should render
|
455
|
+
it "should render email_success for XHR requests" do
|
429
456
|
xhr :post, :email, :id => doc_id, :to => 'test_email@projectblacklight.org'
|
430
|
-
expect(request).to render_template '
|
457
|
+
expect(request).to render_template 'email_success'
|
431
458
|
expect(request.flash[:success]).to eq "Email Sent"
|
432
459
|
end
|
433
460
|
end
|
@@ -465,9 +492,9 @@ describe CatalogController do
|
|
465
492
|
expect(request).to redirect_to(catalog_path(doc_id))
|
466
493
|
end
|
467
494
|
|
468
|
-
it "should render
|
495
|
+
it "should render sms_success template for XHR requests" do
|
469
496
|
xhr :post, :sms, :id => doc_id, :to => '5555555555', :carrier => 'txt.att.net'
|
470
|
-
expect(request).to render_template '
|
497
|
+
expect(request).to render_template 'sms_success'
|
471
498
|
expect(request.flash[:success]).to eq "SMS Sent"
|
472
499
|
end
|
473
500
|
end
|
@@ -665,6 +692,64 @@ describe CatalogController do
|
|
665
692
|
end
|
666
693
|
end
|
667
694
|
|
695
|
+
describe "#add_show_tools_partial" do
|
696
|
+
before do
|
697
|
+
CatalogController.add_show_tools_partial(:like, callback: :perform_like, validator: :validate_like_params)
|
698
|
+
allow(controller).to receive(:perform_like)
|
699
|
+
allow(controller).to receive(:catalog_path).and_return('catalog/1')
|
700
|
+
Rails.application.routes.draw do
|
701
|
+
get 'catalog/like', as: :catalog_like
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
after do
|
706
|
+
CatalogController.blacklight_config.show.document_actions.delete(:like)
|
707
|
+
Rails.application.reload_routes!
|
708
|
+
end
|
709
|
+
|
710
|
+
it "should add the action to a list" do
|
711
|
+
expect(CatalogController.blacklight_config.show.document_actions).to have_key(:like)
|
712
|
+
end
|
713
|
+
|
714
|
+
it "should define the action method" do
|
715
|
+
expect(controller.respond_to?(:like)).to be true
|
716
|
+
end
|
717
|
+
|
718
|
+
describe "when posting to the action" do
|
719
|
+
describe "with success" do
|
720
|
+
before do
|
721
|
+
allow(controller).to receive(:validate_like_params).and_return(true)
|
722
|
+
post :like
|
723
|
+
end
|
724
|
+
it "should call the supplied method on post" do
|
725
|
+
expect(controller).to have_received(:perform_like)
|
726
|
+
end
|
727
|
+
end
|
728
|
+
|
729
|
+
describe "with failure" do
|
730
|
+
describe "with invalid params" do
|
731
|
+
before { allow(controller).to receive(:validate_like_params).and_return(false) }
|
732
|
+
it "should not call the supplied method if validation failed" do
|
733
|
+
expect(controller).not_to have_received(:perform_like)
|
734
|
+
end
|
735
|
+
end
|
736
|
+
end
|
737
|
+
end
|
738
|
+
end
|
739
|
+
|
740
|
+
describe "search_action_url" do
|
741
|
+
it "should be the same as the catalog url" do
|
742
|
+
get :index, :page => 1
|
743
|
+
expect(controller.send(:search_action_url, q: "xyz")).to eq root_url(q: "xyz")
|
744
|
+
end
|
745
|
+
end
|
746
|
+
|
747
|
+
describe "search_facet_url" do
|
748
|
+
it "should be the same as the catalog url" do
|
749
|
+
get :index, :page => 1
|
750
|
+
expect(controller.send(:search_facet_url, id: "some_facet", page: 5)).to eq catalog_facet_url(id: "some_facet")
|
751
|
+
end
|
752
|
+
end
|
668
753
|
end
|
669
754
|
|
670
755
|
|
@@ -18,6 +18,7 @@ describe "Bookmarks" do
|
|
18
18
|
expect(page).to have_content 'Cleared your bookmarks.'
|
19
19
|
expect(page).to have_content 'You have no bookmarks'
|
20
20
|
end
|
21
|
+
|
21
22
|
it "add and remove bookmarks from search results" do
|
22
23
|
sign_in 'user1'
|
23
24
|
visit root_path
|
@@ -30,7 +31,7 @@ describe "Bookmarks" do
|
|
30
31
|
click_button 'Remove bookmark'
|
31
32
|
expect(page).to have_content 'Successfully removed bookmark.'
|
32
33
|
end
|
33
|
-
|
34
|
+
|
34
35
|
it "should add and delete bookmarks from the show page" do
|
35
36
|
sign_in 'user1'
|
36
37
|
visit catalog_path('2007020969')
|
@@ -38,7 +39,7 @@ describe "Bookmarks" do
|
|
38
39
|
click_button 'Remove bookmark'
|
39
40
|
expect(page).to have_content 'Successfully removed bookmark.'
|
40
41
|
end
|
41
|
-
|
42
|
+
|
42
43
|
it "should add bookmarks after a user logs in" do
|
43
44
|
visit catalog_path('2007020969')
|
44
45
|
click_button 'Bookmark'
|
@@ -55,18 +56,42 @@ describe "Bookmarks" do
|
|
55
56
|
click_link 'Cite'
|
56
57
|
expect(page).to have_content 'Strong Medicine speaks'
|
57
58
|
end
|
58
|
-
|
59
|
+
|
60
|
+
it "should cite items in current bookmarks page" do
|
61
|
+
visit catalog_path('2009373513')
|
62
|
+
click_button 'Bookmark'
|
63
|
+
|
64
|
+
visit catalog_path('2007020969')
|
65
|
+
click_button 'Bookmark'
|
66
|
+
|
67
|
+
visit "/bookmarks?per_page=1"
|
68
|
+
expect(page).to have_content 'Ci an zhou bian'
|
69
|
+
expect(page).not_to have_content 'Strong Medicine speaks'
|
70
|
+
|
71
|
+
click_link 'Cite'
|
72
|
+
expect(page).to have_content 'Ci an zhou bian'
|
73
|
+
expect(page).not_to have_content 'Strong Medicine speaks'
|
74
|
+
|
75
|
+
visit "/bookmarks?per_page=1"
|
76
|
+
click_link "2"
|
77
|
+
expect(page).to have_content 'Strong Medicine speaks'
|
78
|
+
|
79
|
+
click_link 'Cite'
|
80
|
+
expect(page).to have_content 'Strong Medicine speaks'
|
81
|
+
expect(page).not_to have_content 'Ci an zhou bian'
|
82
|
+
end
|
83
|
+
|
59
84
|
it "should have an endnote export" do
|
60
85
|
visit catalog_path('2007020969')
|
61
86
|
click_button 'Bookmark'
|
62
|
-
visit "/bookmarks.endnote?q="
|
87
|
+
visit "/bookmarks.endnote?q="
|
63
88
|
expect(page).to have_content " %@ 9780743297790"
|
64
89
|
end
|
65
|
-
|
90
|
+
|
66
91
|
it "should have a refworks export" do
|
67
92
|
visit catalog_path('2007020969')
|
68
93
|
click_button 'Bookmark'
|
69
|
-
visit "/bookmarks.refworks_marc_txt?q="
|
94
|
+
visit "/bookmarks.refworks_marc_txt?q="
|
70
95
|
expect(page).to have_content "LEADER 01490cam a2200361 a 4500001 2007020969"
|
71
96
|
end
|
72
97
|
end
|
@@ -48,6 +48,17 @@ describe "Search Results" do
|
|
48
48
|
search_for 'asdfghj'
|
49
49
|
expect(page).to have_content "No results found for your search"
|
50
50
|
end
|
51
|
+
|
52
|
+
it "should provide search hints if there are no results" do
|
53
|
+
visit root_path
|
54
|
+
fill_in "q", with: "inmul"
|
55
|
+
select "Author", from: "search_field"
|
56
|
+
click_button 'search'
|
57
|
+
expect(page).to have_content "No results found for your search"
|
58
|
+
expect(page).to have_content "you searched by Author"
|
59
|
+
click_on "try searching everything"
|
60
|
+
expect(page).to have_xpath("//a[contains(@href, #{77826928})]")
|
61
|
+
end
|
51
62
|
end
|
52
63
|
|
53
64
|
|
@@ -111,5 +111,10 @@ describe "Search Page" do
|
|
111
111
|
expect(page).to have_content "Welcome!"
|
112
112
|
expect(page).to_not have_selector "#q[value='history']"
|
113
113
|
end
|
114
|
+
|
115
|
+
it "should gracefully handle searches with invalid facet parameters" do
|
116
|
+
visit root_path f: { missing_s: [1]}
|
117
|
+
expect(page).to have_content "No results found for your search"
|
118
|
+
end
|
114
119
|
end
|
115
120
|
|
@@ -111,37 +111,54 @@ describe BlacklightHelper do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
describe "with a config" do
|
114
|
-
|
115
|
-
|
114
|
+
let(:config) do
|
115
|
+
Blacklight::Configuration.new.configure do |config|
|
116
116
|
config.index.title_field = 'title_display'
|
117
117
|
config.index.display_type_field = 'format'
|
118
118
|
end
|
119
|
+
end
|
119
120
|
|
120
|
-
|
121
|
-
|
121
|
+
let(:document) { SolrDocument.new('title_display' => "A Fake Document", 'id'=>'8') }
|
122
|
+
|
123
|
+
before do
|
124
|
+
config.add_show_tools_partial(:bookmark, partial: 'catalog/bookmark_control', if: :render_bookmarks_control?)
|
125
|
+
config.add_results_document_tool(:bookmark, partial: 'catalog/bookmark_control', if: :render_bookmarks_control?)
|
126
|
+
config.add_nav_action(:bookmark, partial: 'blacklight/nav/bookmark', if: :render_bookmarks_control?)
|
127
|
+
allow(helper).to receive(:blacklight_config).and_return(config)
|
122
128
|
allow(helper).to receive(:has_user_authentication_provider?).and_return(true)
|
123
129
|
allow(helper).to receive(:current_or_guest_user).and_return(User.new)
|
124
130
|
allow(helper).to receive_messages(current_bookmarks: [])
|
125
131
|
end
|
132
|
+
|
133
|
+
describe "render_nav_actions" do
|
134
|
+
it "should render partials" do
|
135
|
+
buff = ''
|
136
|
+
helper.render_nav_actions { |config, item| buff << "<foo>#{item}</foo>" }
|
137
|
+
expect(buff).to have_selector "foo a#bookmarks_nav[href=\"/bookmarks\"]"
|
138
|
+
expect(buff).to have_selector "foo a span[data-role='bookmark-counter']", text: '0'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
126
142
|
describe "render_index_doc_actions" do
|
127
143
|
it "should render partials" do
|
128
|
-
response = helper.render_index_doc_actions(
|
144
|
+
response = helper.render_index_doc_actions(document)
|
129
145
|
expect(response).to have_selector(".bookmark_toggle")
|
130
146
|
end
|
131
147
|
end
|
148
|
+
|
132
149
|
describe "render_show_doc_actions" do
|
133
150
|
it "should render partials" do
|
134
|
-
response = helper.render_show_doc_actions(
|
151
|
+
response = helper.render_show_doc_actions(document)
|
135
152
|
expect(response).to have_selector(".bookmark_toggle")
|
136
153
|
end
|
137
154
|
end
|
138
155
|
end
|
139
|
-
|
156
|
+
|
140
157
|
describe "#should_render_index_field?" do
|
141
158
|
before do
|
142
159
|
allow(helper).to receive_messages(should_render_field?: true, document_has_value?: true)
|
143
160
|
end
|
144
|
-
|
161
|
+
|
145
162
|
it "should be true" do
|
146
163
|
expect(helper.should_render_index_field?(double, double)).to be true
|
147
164
|
end
|
@@ -467,6 +484,7 @@ describe BlacklightHelper do
|
|
467
484
|
let(:doc) { double }
|
468
485
|
before do
|
469
486
|
allow(helper).to receive_messages(document_partial_path_templates: [])
|
487
|
+
allow(helper).to receive_messages(document_index_view_type: 'index_header')
|
470
488
|
end
|
471
489
|
|
472
490
|
it "should get the document format from document_partial_name" do
|
@@ -593,4 +611,27 @@ describe BlacklightHelper do
|
|
593
611
|
expect(response).to match /<div id="documents">/
|
594
612
|
end
|
595
613
|
end
|
614
|
+
|
615
|
+
describe "#presenter_class" do
|
616
|
+
before do
|
617
|
+
allow(helper).to receive(:blacklight_config).and_return(blacklight_config)
|
618
|
+
end
|
619
|
+
|
620
|
+
let :blacklight_config do
|
621
|
+
Blacklight::Configuration.new
|
622
|
+
end
|
623
|
+
|
624
|
+
let :presenter_class do
|
625
|
+
double
|
626
|
+
end
|
627
|
+
|
628
|
+
it "should use the value defined in the blacklight configuration" do
|
629
|
+
blacklight_config.document_presenter_class = presenter_class
|
630
|
+
expect(helper.presenter_class).to eq presenter_class
|
631
|
+
end
|
632
|
+
|
633
|
+
it "should default to Blacklight::DocumentPresenter" do
|
634
|
+
expect(helper.presenter_class).to eq Blacklight::DocumentPresenter
|
635
|
+
end
|
636
|
+
end
|
596
637
|
end
|