blacklight 7.10.0 → 7.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +56 -7
- data/.rubocop_todo.yml +113 -98
- data/.travis.yml +0 -2
- data/Gemfile +0 -7
- data/README.md +1 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +1 -2
- data/app/components/blacklight/document/bookmark_component.html.erb +16 -0
- data/app/components/blacklight/document/bookmark_component.rb +19 -0
- data/app/components/blacklight/document/citation_component.html.erb +9 -0
- data/app/components/blacklight/document/citation_component.rb +24 -0
- data/app/components/blacklight/document/more_like_this_component.html.erb +12 -0
- data/app/components/blacklight/document/more_like_this_component.rb +21 -0
- data/app/components/blacklight/document_component.html.erb +29 -0
- data/app/components/blacklight/document_component.rb +121 -0
- data/app/components/blacklight/document_metadata_component.html.erb +5 -0
- data/app/components/blacklight/document_metadata_component.rb +21 -0
- data/app/components/blacklight/facet_item_component.rb +6 -6
- data/app/components/blacklight/metadata_field_component.html.erb +8 -0
- data/app/components/blacklight/metadata_field_component.rb +31 -0
- data/app/components/blacklight/metadata_field_layout_component.html.erb +2 -0
- data/app/components/blacklight/metadata_field_layout_component.rb +16 -0
- data/app/components/blacklight/response/facet_group_component.html.erb +25 -0
- data/app/components/blacklight/response/facet_group_component.rb +19 -0
- data/app/components/blacklight/response/pagination_component.html.erb +3 -0
- data/app/components/blacklight/response/pagination_component.rb +17 -0
- data/app/components/blacklight/response/sort_component.html.erb +6 -0
- data/app/components/blacklight/response/sort_component.rb +16 -0
- data/app/components/blacklight/response/spellcheck_component.html.erb +7 -0
- data/app/components/blacklight/response/spellcheck_component.rb +20 -0
- data/app/components/blacklight/search_bar_component.html.erb +29 -0
- data/app/components/blacklight/search_bar_component.rb +45 -0
- data/app/components/blacklight/search_context_component.html.erb +10 -0
- data/app/components/blacklight/search_context_component.rb +30 -0
- data/app/components/blacklight/system/dropdown_component.html.erb +12 -0
- data/app/components/blacklight/system/dropdown_component.rb +42 -0
- data/app/components/blacklight/system/modal_component.html.erb +25 -0
- data/app/components/blacklight/system/modal_component.rb +9 -0
- data/app/controllers/concerns/blacklight/catalog.rb +5 -4
- data/app/controllers/concerns/blacklight/default_component_configuration.rb +2 -2
- data/app/controllers/concerns/blacklight/searchable.rb +11 -0
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +14 -3
- data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -0
- data/app/helpers/blacklight/component_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/configuration_helper_behavior.rb +6 -0
- data/app/helpers/blacklight/facets_helper_behavior.rb +1 -1
- data/app/helpers/blacklight/icon_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +7 -10
- data/app/helpers/blacklight/url_helper_behavior.rb +3 -3
- data/app/javascript/blacklight/search_context.js +0 -1
- data/app/models/blacklight/icon.rb +1 -0
- data/app/models/concerns/blacklight/document.rb +1 -0
- data/app/models/record_mailer.rb +1 -1
- data/app/presenters/blacklight/document_presenter.rb +7 -1
- data/app/presenters/blacklight/field_presenter.rb +1 -0
- data/app/presenters/blacklight/rendering/microdata.rb +1 -1
- data/app/services/blacklight/field_retriever.rb +1 -0
- data/app/services/blacklight/search_service.rb +1 -0
- data/app/views/catalog/_bookmark_control.html.erb +1 -36
- data/app/views/catalog/_citation.html.erb +4 -25
- data/app/views/catalog/_did_you_mean.html.erb +1 -5
- data/app/views/catalog/_document.atom.builder +3 -3
- data/app/views/catalog/_document.html.erb +5 -5
- data/app/views/catalog/_facet_group.html.erb +5 -19
- data/app/views/catalog/_index.html.erb +1 -10
- data/app/views/catalog/_paginate_compact.html.erb +6 -6
- data/app/views/catalog/_per_page_widget.html.erb +9 -12
- data/app/views/catalog/_previous_next_doc.html.erb +1 -12
- data/app/views/catalog/_results_pagination.html.erb +1 -3
- data/app/views/catalog/_search_form.html.erb +6 -27
- data/app/views/catalog/_show.html.erb +6 -8
- data/app/views/catalog/_show_main_content.html.erb +19 -13
- data/app/views/catalog/_show_sidebar.html.erb +1 -11
- data/app/views/catalog/_sort_widget.html.erb +5 -12
- data/app/views/catalog/email.html.erb +7 -7
- data/app/views/catalog/email_success.html.erb +5 -12
- data/app/views/catalog/facet.html.erb +14 -17
- data/app/views/catalog/index.atom.builder +0 -1
- data/app/views/catalog/sms.html.erb +7 -7
- data/app/views/catalog/sms_success.html.erb +5 -12
- data/blacklight.gemspec +3 -2
- data/config/i18n-tasks.yml +3 -0
- data/config/locales/blacklight.ar.yml +2 -0
- data/config/locales/blacklight.de.yml +2 -0
- data/config/locales/blacklight.en.yml +2 -0
- data/config/locales/blacklight.es.yml +4 -2
- data/config/locales/blacklight.fr.yml +2 -0
- data/config/locales/blacklight.hu.yml +2 -0
- data/config/locales/blacklight.it.yml +2 -0
- data/config/locales/blacklight.nl.yml +2 -0
- data/config/locales/blacklight.pt-BR.yml +2 -0
- data/config/locales/blacklight.sq.yml +2 -0
- data/config/locales/blacklight.zh.yml +2 -0
- data/lib/blacklight.rb +10 -0
- data/lib/blacklight/configuration.rb +8 -3
- data/lib/blacklight/configuration/fields.rb +5 -7
- data/lib/blacklight/engine.rb +1 -1
- data/lib/blacklight/nested_open_struct_with_hash_access.rb +1 -0
- data/lib/blacklight/search_state.rb +21 -7
- data/lib/blacklight/solr/response.rb +1 -0
- data/lib/blacklight/solr/response/facets.rb +9 -8
- data/lib/generators/blacklight/models_generator.rb +2 -0
- data/lib/generators/blacklight/templates/config/blacklight.yml +1 -0
- data/lib/railties/blacklight.rake +18 -13
- data/package.json +1 -1
- data/spec/components/blacklight/constraint_layout_component_spec.rb +1 -0
- data/spec/components/blacklight/document_component_spec.rb +129 -0
- data/spec/components/blacklight/document_metadata_component_spec.rb +0 -0
- data/spec/components/blacklight/metadata_field_component_spec.rb +41 -0
- data/spec/controllers/blacklight/search_fields_spec.rb +2 -2
- data/spec/controllers/catalog_controller_spec.rb +20 -0
- data/spec/features/search_context_spec.rb +12 -2
- data/spec/features/search_filters_spec.rb +4 -0
- data/spec/features/search_results_spec.rb +1 -0
- data/spec/features/sitelinks_search_box.rb +1 -0
- data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +3 -0
- data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +1 -0
- data/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb +2 -0
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +14 -1
- data/spec/helpers/catalog_helper_spec.rb +1 -4
- data/spec/lib/blacklight/search_state_spec.rb +32 -0
- data/spec/models/blacklight/configuration_spec.rb +5 -0
- data/spec/models/blacklight/document/cache_key_spec.rb +1 -0
- data/spec/models/blacklight/document/email_spec.rb +2 -0
- data/spec/models/blacklight/document/sms_spec.rb +2 -0
- data/spec/models/blacklight/facet_paginator_spec.rb +3 -0
- data/spec/models/blacklight/icon_spec.rb +6 -0
- data/spec/models/blacklight/solr/document_spec.rb +10 -0
- data/spec/models/blacklight/solr/response/facets_spec.rb +1 -1
- data/spec/models/blacklight/solr/response/group_response_spec.rb +2 -0
- data/spec/models/blacklight/solr/search_builder_spec.rb +10 -0
- data/spec/models/record_mailer_spec.rb +9 -0
- data/spec/models/search_spec.rb +1 -0
- data/spec/presenters/blacklight/show_presenter_spec.rb +8 -0
- data/spec/routing/catalog_routing_spec.rb +4 -0
- data/spec/services/blacklight/search_service_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/views/catalog/_document.html.erb_spec.rb +13 -11
- data/spec/views/catalog/_facet_group.html.erb_spec.rb +1 -0
- data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +1 -0
- data/spec/views/catalog/_previous_next_doc.html.erb_spec.rb +4 -0
- data/spec/views/catalog/index.atom.builder_spec.rb +40 -3
- data/spec/views/catalog/show.html.erb_spec.rb +14 -0
- data/tasks/blacklight.rake +7 -7
- metadata +56 -6
@@ -16,24 +16,38 @@ module Blacklight
|
|
16
16
|
# @param [Blacklight::Config] blacklight_config
|
17
17
|
# @param [ApplicationController] controller used for the routing helpers
|
18
18
|
def initialize(params, blacklight_config, controller = nil)
|
19
|
+
@params = self.class.normalize_params(params)
|
20
|
+
@blacklight_config = blacklight_config
|
21
|
+
@controller = controller
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.normalize_params(untrusted_params = {})
|
25
|
+
params = untrusted_params
|
26
|
+
|
19
27
|
if params.respond_to?(:to_unsafe_h)
|
20
28
|
# This is the typical (not-ActionView::TestCase) code path.
|
21
|
-
|
29
|
+
params = params.to_unsafe_h
|
22
30
|
# In Rails 5 to_unsafe_h returns a HashWithIndifferentAccess, in Rails 4 it returns Hash
|
23
|
-
|
31
|
+
params = params.with_indifferent_access if params.instance_of? Hash
|
24
32
|
elsif params.is_a? Hash
|
25
33
|
# This is an ActionView::TestCase workaround for Rails 4.2.
|
26
|
-
|
34
|
+
params = params.dup.with_indifferent_access
|
27
35
|
else
|
28
|
-
|
36
|
+
params = params.dup.to_h.with_indifferent_access
|
29
37
|
end
|
30
38
|
|
31
|
-
|
32
|
-
|
39
|
+
# Normalize facet parameters mangled by facebook
|
40
|
+
if params[:f].is_a?(Hash) && params[:f].values.any? { |x| x.is_a?(Hash) }
|
41
|
+
params[:f] = params[:f].transform_values do |value|
|
42
|
+
value.is_a?(Hash) ? value.values : value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
params
|
33
47
|
end
|
34
48
|
|
35
49
|
def to_hash
|
36
|
-
@params
|
50
|
+
@params.deep_dup
|
37
51
|
end
|
38
52
|
alias to_h to_hash
|
39
53
|
|
@@ -19,6 +19,7 @@ class Blacklight::Solr::Response < ActiveSupport::HashWithIndifferentAccess
|
|
19
19
|
|
20
20
|
attr_reader :request_params
|
21
21
|
attr_accessor :blacklight_config, :options
|
22
|
+
|
22
23
|
delegate :document_factory, to: :blacklight_config
|
23
24
|
|
24
25
|
def initialize(data, request_params, options = {})
|
@@ -29,6 +29,7 @@ module Blacklight::Solr::Response::Facets
|
|
29
29
|
# represents a facet; which is a field and its values
|
30
30
|
class FacetField
|
31
31
|
attr_reader :name, :items
|
32
|
+
|
32
33
|
def initialize name, items, options = {}
|
33
34
|
@name = name
|
34
35
|
@items = items
|
@@ -138,14 +139,14 @@ module Blacklight::Solr::Response::Facets
|
|
138
139
|
if solr_list.values.first.is_a? Hash
|
139
140
|
solr_list
|
140
141
|
else
|
141
|
-
solr_list.
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
142
|
+
solr_list.transform_values do |values|
|
143
|
+
if values.first.is_a? Array
|
144
|
+
# arrarr
|
145
|
+
Hash[values]
|
146
|
+
else
|
147
|
+
# flat
|
148
|
+
Hash[values.each_slice(2).to_a]
|
149
|
+
end
|
149
150
|
end
|
150
151
|
end
|
151
152
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'rails/generators'
|
3
3
|
require 'rails/generators/migration'
|
4
|
+
require 'blacklight/version'
|
4
5
|
|
5
6
|
module Blacklight
|
6
7
|
class ModelsGenerator < Rails::Generators::Base
|
@@ -17,6 +18,7 @@ module Blacklight
|
|
17
18
|
# Copy all files in templates/config directory to host config
|
18
19
|
def create_configuration_files
|
19
20
|
copy_file "config/blacklight.yml", "config/blacklight.yml"
|
21
|
+
gsub_file 'config/blacklight.yml', '__VERSION__', Blacklight::VERSION
|
20
22
|
end
|
21
23
|
|
22
24
|
# Setup the database migrations
|
@@ -12,11 +12,18 @@ namespace :blacklight do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
namespace :index do
|
15
|
-
desc
|
16
|
-
|
15
|
+
desc <<-EODESC.gsub(/\n\s*/, ' ')
|
16
|
+
Index sample data (from FILE, ./spec/fixtures/sample_solr_documents.yml in this application,
|
17
|
+
or the test fixtures from blacklight) into solr.
|
18
|
+
EODESC
|
19
|
+
task seed: [:environment] do
|
17
20
|
require 'yaml'
|
18
21
|
|
19
|
-
|
22
|
+
app_file = Rails.root && Rails.root + 'spec/fixtures/sample_solr_documents.yml'
|
23
|
+
file = ENV['FILE'] ||
|
24
|
+
(app_file && File.exist?(app_file) && app_file) ||
|
25
|
+
File.join(Blacklight.root, 'spec', 'fixtures', 'sample_solr_documents.yml')
|
26
|
+
docs = YAML.safe_load(File.open(file))
|
20
27
|
conn = Blacklight.default_index.connection
|
21
28
|
conn.add docs
|
22
29
|
conn.commit
|
@@ -26,18 +33,16 @@ namespace :blacklight do
|
|
26
33
|
namespace :check do
|
27
34
|
desc "Check the Solr connection and controller configuration"
|
28
35
|
task :solr, [:controller_name] => [:environment] do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
puts "Unable to reach: #{conn.uri}"
|
35
|
-
exit 1
|
36
|
-
end
|
37
|
-
rescue => e
|
38
|
-
puts e.to_s
|
36
|
+
conn = Blacklight.default_index
|
37
|
+
if conn.ping
|
38
|
+
puts "OK"
|
39
|
+
else
|
40
|
+
puts "Unable to reach: #{conn.uri}"
|
39
41
|
exit 1
|
40
42
|
end
|
43
|
+
rescue => e
|
44
|
+
puts e.to_s
|
45
|
+
exit 1
|
41
46
|
end
|
42
47
|
|
43
48
|
task :controller, [:controller_name] => [:environment] do |_, args|
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "blacklight-frontend",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.10.0",
|
4
4
|
"description": "[![Build Status](https://travis-ci.org/projectblacklight/blacklight.png?branch=master)](https://travis-ci.org/projectblacklight/blacklight) [![Gem Version](https://badge.fury.io/rb/blacklight.png)](http://badge.fury.io/rb/blacklight) [![Coverage Status](https://coveralls.io/repos/github/projectblacklight/blacklight/badge.svg?branch=master)](https://coveralls.io/github/projectblacklight/blacklight?branch=master)",
|
5
5
|
"main": "app/assets/javascripts/blacklight",
|
6
6
|
"scripts": {
|
@@ -36,6 +36,7 @@ RSpec.describe Blacklight::ConstraintLayoutComponent, type: :component do
|
|
36
36
|
expect(s).to have_selector(".remove[href='http://remove']")
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
39
40
|
it "has an accessible remove label" do
|
40
41
|
expect(rendered).to have_selector(".remove") do |s|
|
41
42
|
expect(s).to have_selector('.sr-only', text: 'Remove constraint my label: my value')
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::DocumentComponent, type: :component do
|
6
|
+
subject(:component) { described_class.new(document: document, **attr) }
|
7
|
+
|
8
|
+
let(:attr) { {} }
|
9
|
+
let(:view_context) { controller.view_context }
|
10
|
+
let(:render) do
|
11
|
+
component.render_in(view_context)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:rendered) do
|
15
|
+
Capybara::Node::Simple.new(render)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:document) do
|
19
|
+
SolrDocument.new(
|
20
|
+
id: 'x',
|
21
|
+
thumbnail_path_ss: 'http://example.com/image.jpg',
|
22
|
+
title_tsim: 'Title',
|
23
|
+
isbn_ssim: ['Value']
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:blacklight_config) do
|
28
|
+
CatalogController.blacklight_config.deep_copy.tap do |config|
|
29
|
+
config.track_search_session = false
|
30
|
+
config.index.thumbnail_field = 'thumbnail_path_ss'
|
31
|
+
config.index.document_actions[:bookmark].partial = '/catalog/bookmark_control.html.erb'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(controller).to receive(:current_or_guest_user).and_return(User.new)
|
37
|
+
allow(controller).to receive(:blacklight_config).and_return(blacklight_config)
|
38
|
+
allow(view_context).to receive(:search_session).and_return({})
|
39
|
+
allow(view_context).to receive(:current_search_session).and_return(nil)
|
40
|
+
allow(view_context).to receive(:current_bookmarks).and_return([])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'has some defined content areas' do
|
44
|
+
component.with(:title, 'Title')
|
45
|
+
component.with(:metadata, 'Metadata')
|
46
|
+
component.with(:thumbnail, 'Thumbnail')
|
47
|
+
component.with(:actions, 'Actions')
|
48
|
+
|
49
|
+
expect(rendered).to have_content 'Title'
|
50
|
+
expect(rendered).to have_content 'Metadata'
|
51
|
+
expect(rendered).to have_content 'Thumbnail'
|
52
|
+
expect(rendered).to have_content 'Actions'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'has schema.org properties' do
|
56
|
+
component.with(:body, '-')
|
57
|
+
|
58
|
+
expect(rendered).to have_selector 'article[@itemtype="http://schema.org/Thing"]'
|
59
|
+
expect(rendered).to have_selector 'article[@itemscope]'
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with a provided body' do
|
63
|
+
it 'opts-out of normal component content' do
|
64
|
+
component.with(:body, 'Body content')
|
65
|
+
|
66
|
+
expect(rendered).to have_content 'Body content'
|
67
|
+
expect(rendered).not_to have_selector 'header'
|
68
|
+
expect(rendered).not_to have_selector 'dl'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'index view' do
|
73
|
+
let(:attr) { { counter: 5 } }
|
74
|
+
|
75
|
+
it 'has data properties' do
|
76
|
+
component.with(:body, '-')
|
77
|
+
|
78
|
+
expect(rendered).to have_selector 'article[@data-document-id="x"]'
|
79
|
+
expect(rendered).to have_selector 'article[@data-document-counter="5"]'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'renders a linked title' do
|
83
|
+
expect(rendered).to have_link 'Title', href: '/catalog/x'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'renders a counter with the title' do
|
87
|
+
expect(rendered).to have_selector 'header', text: '5. Title'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'renders actions' do
|
91
|
+
expect(rendered).to have_selector '.index-document-functions'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'renders a thumbnail' do
|
95
|
+
expect(rendered).to have_selector 'a[href="/catalog/x"] img[src="http://example.com/image.jpg"]'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'show view' do
|
100
|
+
let(:attr) { { title_component: :h1, show: true } }
|
101
|
+
|
102
|
+
before do
|
103
|
+
allow(view_context).to receive(:action_name).and_return('show')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'renders with an id' do
|
107
|
+
component.with(:body, '-')
|
108
|
+
|
109
|
+
expect(rendered).to have_selector 'article#document'
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'renders a title' do
|
113
|
+
expect(rendered).to have_selector 'h1', text: 'Title'
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'renders with show-specific metadata' do
|
117
|
+
expect(rendered).to have_selector 'dl.document-metadata'
|
118
|
+
expect(rendered).to have_selector 'dt', text: 'ISBN:'
|
119
|
+
expect(rendered).to have_selector 'dd', text: 'Value'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'renders metadata' do
|
124
|
+
expect(rendered).to have_selector 'dl.document-metadata'
|
125
|
+
expect(rendered).to have_selector 'dt', text: 'Title:'
|
126
|
+
expect(rendered).to have_selector 'dd', text: 'Title'
|
127
|
+
expect(rendered).not_to have_selector 'dt', text: 'ISBN:'
|
128
|
+
end
|
129
|
+
end
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::MetadataFieldComponent, type: :component do
|
6
|
+
subject(:render) do
|
7
|
+
render_inline(described_class.new(field: field))
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:view_context) { controller.view_context }
|
11
|
+
let(:document) { SolrDocument.new('field' => ['Value']) }
|
12
|
+
let(:field_config) { Blacklight::Configuration::Field.new(key: 'field', field: 'field', label: 'Field label') }
|
13
|
+
|
14
|
+
let(:field) do
|
15
|
+
Blacklight::FieldPresenter.new(view_context, document, field_config)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:rendered) do
|
19
|
+
Capybara::Node::Simple.new(render)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'renders the field label' do
|
23
|
+
expect(rendered).to have_selector 'dt.blacklight-field', text: 'Field label'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'renders the field value' do
|
27
|
+
expect(rendered).to have_selector 'dd.blacklight-field', text: 'Value'
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'from a show view' do
|
31
|
+
subject(:render) do
|
32
|
+
render_inline(described_class.new(field: field, show: true))
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'renders the right field label' do
|
36
|
+
allow(field).to receive(:label).with('show').and_return('custom label')
|
37
|
+
|
38
|
+
expect(rendered).to have_selector 'dt.blacklight-field', text: 'custom label'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -39,7 +39,7 @@ RSpec.describe Blacklight::SearchFields do
|
|
39
39
|
config.add_search_field label: 'All Fields', qt: 'all_fields'
|
40
40
|
config.add_search_field 'title', qt: 'title_search'
|
41
41
|
end)
|
42
|
-
end
|
42
|
+
end.to raise_error ArgumentError
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -54,7 +54,7 @@ RSpec.describe Blacklight::SearchFields do
|
|
54
54
|
config.add_search_field 'my_key', label: 'All Fields'
|
55
55
|
config.add_search_field 'my_key', label: 'title'
|
56
56
|
end)
|
57
|
-
end
|
57
|
+
end.to raise_error RuntimeError
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -30,11 +30,13 @@ RSpec.describe CatalogController, api: true do
|
|
30
30
|
expect(assigns(:response).docs).not_to be_empty
|
31
31
|
assert_facets_have_values(assigns(:response).aggregations)
|
32
32
|
end
|
33
|
+
|
33
34
|
it "has docs and facets for existing facet value", integration: true do
|
34
35
|
get :index, params: { f: { "format" => 'Book' } }
|
35
36
|
expect(assigns(:response).docs).not_to be_empty
|
36
37
|
assert_facets_have_values(assigns(:response).aggregations)
|
37
38
|
end
|
39
|
+
|
38
40
|
it "has docs and facets for non-default results per page", integration: true do
|
39
41
|
num_per_page = 7
|
40
42
|
get :index, params: { per_page: num_per_page }
|
@@ -98,6 +100,7 @@ RSpec.describe CatalogController, api: true do
|
|
98
100
|
get :index
|
99
101
|
expect(assigns(:response).docs).not_to be_empty
|
100
102
|
end
|
103
|
+
|
101
104
|
it "gets facets when no query", integration: true do
|
102
105
|
get :index
|
103
106
|
assert_facets_have_values(assigns(:response).aggregations)
|
@@ -237,6 +240,11 @@ RSpec.describe CatalogController, api: true do
|
|
237
240
|
expect(session[:search]['per_page']).to eq "15"
|
238
241
|
end
|
239
242
|
|
243
|
+
it "records the document id being viewed" do
|
244
|
+
put :track, params: { id: doc_id, counter: 3, document_id: 1234 }
|
245
|
+
expect(session[:search]['document_id']).to eq "1234"
|
246
|
+
end
|
247
|
+
|
240
248
|
it "redirects to show action for doc id" do
|
241
249
|
put :track, params: { id: doc_id, counter: 3 }
|
242
250
|
assert_redirected_to(solr_document_path(doc_id))
|
@@ -456,6 +464,7 @@ RSpec.describe CatalogController, api: true do
|
|
456
464
|
get :suggest, params: { format: 'json' }
|
457
465
|
expect(response.body).to eq [].to_json
|
458
466
|
end
|
467
|
+
|
459
468
|
it 'returns suggestions' do
|
460
469
|
get :suggest, params: { format: 'json', q: 'new' }
|
461
470
|
json = JSON.parse(response.body)
|
@@ -485,14 +494,17 @@ RSpec.describe CatalogController, api: true do
|
|
485
494
|
post :email, params: { id: doc_id }
|
486
495
|
expect(request.flash[:error]).to eq "You must enter a recipient in order to send this message"
|
487
496
|
end
|
497
|
+
|
488
498
|
it "gives an error if the email address is not valid" do
|
489
499
|
post :email, params: { id: doc_id, to: 'test_bad_email' }
|
490
500
|
expect(request.flash[:error]).to eq "You must enter a valid email address"
|
491
501
|
end
|
502
|
+
|
492
503
|
it "does not give error if no Message parameter is set" do
|
493
504
|
post :email, params: { id: doc_id, to: 'test_email@projectblacklight.org' }
|
494
505
|
expect(request.flash[:error]).to be_nil
|
495
506
|
end
|
507
|
+
|
496
508
|
it "redirects back to the record upon success" do
|
497
509
|
allow(RecordMailer).to receive(:email_record)
|
498
510
|
.with(anything, { to: 'test_email@projectblacklight.org', message: 'xyz' }, hash_including(host: 'test.host'))
|
@@ -501,6 +513,7 @@ RSpec.describe CatalogController, api: true do
|
|
501
513
|
expect(request.flash[:error]).to be_nil
|
502
514
|
expect(request).to redirect_to(solr_document_path(doc_id))
|
503
515
|
end
|
516
|
+
|
504
517
|
it "renders email_success for XHR requests" do
|
505
518
|
post :email, xhr: true, params: { id: doc_id, to: 'test_email@projectblacklight.org' }
|
506
519
|
expect(request).to render_template 'email_success'
|
@@ -513,23 +526,28 @@ RSpec.describe CatalogController, api: true do
|
|
513
526
|
post :sms, params: { id: doc_id, carrier: 'att' }
|
514
527
|
expect(request.flash[:error]).to eq "You must enter a recipient's phone number in order to send this message"
|
515
528
|
end
|
529
|
+
|
516
530
|
it "gives an error when a carrier is not provided" do
|
517
531
|
post :sms, params: { id: doc_id, to: '5555555555', carrier: '' }
|
518
532
|
expect(request.flash[:error]).to eq "You must select a carrier"
|
519
533
|
end
|
534
|
+
|
520
535
|
it "gives an error when the phone number is not 10 digits" do
|
521
536
|
post :sms, params: { id: doc_id, to: '555555555', carrier: 'txt.att.net' }
|
522
537
|
expect(request.flash[:error]).to eq "You must enter a valid 10 digit phone number"
|
523
538
|
end
|
539
|
+
|
524
540
|
it "gives an error when the carrier is not in our list of carriers" do
|
525
541
|
post :sms, params: { id: doc_id, to: '5555555555', carrier: 'no-such-carrier' }
|
526
542
|
expect(request.flash[:error]).to eq "You must enter a valid carrier"
|
527
543
|
end
|
544
|
+
|
528
545
|
it "allows punctuation in phone number" do
|
529
546
|
post :sms, params: { id: doc_id, to: '(555) 555-5555', carrier: 'txt.att.net' }
|
530
547
|
expect(request.flash[:error]).to be_nil
|
531
548
|
expect(request).to redirect_to(solr_document_path(doc_id))
|
532
549
|
end
|
550
|
+
|
533
551
|
it "sends to the appropriate carrier email address" do
|
534
552
|
expect(RecordMailer)
|
535
553
|
.to receive(:sms_record)
|
@@ -537,11 +555,13 @@ RSpec.describe CatalogController, api: true do
|
|
537
555
|
.and_return double(deliver: nil)
|
538
556
|
post :sms, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
|
539
557
|
end
|
558
|
+
|
540
559
|
it "redirects back to the record upon success" do
|
541
560
|
post :sms, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
|
542
561
|
expect(request.flash[:error]).to eq nil
|
543
562
|
expect(request).to redirect_to(solr_document_path(doc_id))
|
544
563
|
end
|
564
|
+
|
545
565
|
it "renders sms_success template for XHR requests" do
|
546
566
|
post :sms, xhr: true, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
|
547
567
|
expect(request).to render_template 'sms_success'
|