blacklight 5.0.0.pre3 → 5.0.0.pre4
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 +4 -4
- data/.gitignore +9 -16
- data/Gemfile +4 -0
- data/README.md +15 -1
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_bookmark.css.scss +1 -1
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +2 -12
- data/app/assets/stylesheets/blacklight/_facets.css.scss +1 -1
- data/app/assets/stylesheets/blacklight/_header.css.scss +1 -0
- data/app/assets/stylesheets/blacklight/_modal.css.scss +4 -2
- data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +0 -5
- data/app/controllers/bookmarks_controller.rb +4 -0
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +26 -187
- data/app/helpers/blacklight/catalog_helper_behavior.rb +20 -8
- data/app/helpers/blacklight/facets_helper_behavior.rb +0 -83
- data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +1 -1
- data/app/helpers/blacklight/url_helper_behavior.rb +201 -0
- data/app/helpers/blacklight_url_helper.rb +3 -0
- data/app/views/bookmarks/_tools.html.erb +4 -7
- data/app/views/catalog/_citation.html.erb +1 -1
- data/app/views/catalog/_did_you_mean.html.erb +1 -1
- data/app/views/catalog/_document.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_show_more_like_this.html.erb +1 -1
- data/app/views/catalog/_view_type_group.html.erb +4 -4
- data/app/views/catalog/email.html.erb +2 -2
- data/app/views/catalog/facet.html.erb +1 -1
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/catalog/sms.html.erb +1 -1
- data/blacklight.gemspec +2 -2
- data/config/jetty.yml +4 -1
- data/config/locales/blacklight.en.yml +3 -0
- data/config/locales/blacklight.fr.yml +3 -0
- data/{lib/generators/blacklight/templates/migrations/create_searches.rb → db/migrate/20140202020201_create_searches.rb} +2 -0
- data/{lib/generators/blacklight/templates/migrations/create_bookmarks.rb → db/migrate/20140202020202_create_bookmarks.rb} +1 -2
- data/gemfiles/rails3.gemfile +2 -0
- data/gemfiles/rails4.gemfile +2 -0
- data/lib/blacklight.rb +1 -40
- data/lib/blacklight/base.rb +3 -9
- data/lib/blacklight/catalog.rb +3 -16
- data/lib/blacklight/catalog/search_context.rb +8 -1
- data/lib/blacklight/configurable.rb +1 -2
- data/lib/blacklight/configuration.rb +13 -3
- data/lib/blacklight/configuration/view_config.rb +71 -0
- data/lib/blacklight/engine.rb +1 -0
- data/lib/blacklight/routes.rb +0 -1
- data/lib/blacklight/solr/document.rb +0 -4
- data/lib/blacklight/solr_helper.rb +8 -2
- data/lib/blacklight/user.rb +1 -16
- data/lib/blacklight/utils.rb +72 -1
- data/lib/generators/blacklight/install_generator.rb +92 -0
- data/lib/generators/blacklight/models_generator.rb +1 -25
- data/lib/generators/blacklight/templates/catalog_controller.rb +28 -32
- data/spec/helpers/blacklight_helper_spec.rb +24 -417
- data/spec/helpers/catalog_helper_spec.rb +13 -13
- data/spec/helpers/facets_helper_spec.rb +0 -127
- data/spec/helpers/hash_as_hidden_fields_spec.rb +1 -1
- data/spec/helpers/url_helper_spec.rb +360 -0
- data/spec/lib/blacklight/configuration_spec.rb +2 -3
- data/spec/lib/blacklight/solr_helper_spec.rb +11 -17
- data/spec/lib/blacklight/user_spec.rb +0 -41
- data/spec/lib/blacklight_spec.rb +0 -22
- data/spec/lib/utils_spec.rb +35 -4
- data/spec/spec_helper.rb +4 -3
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +2 -2
- data/spec/views/catalog/_constraints.html.erb_spec.rb +4 -2
- data/spec/views/catalog/_index_default.erb_spec.rb +1 -1
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +1 -5
- data/spec/views/catalog/_show_default.erb_spec.rb +1 -1
- data/spec/views/catalog/_view_type_group.html.erb_spec.rb +11 -3
- data/tasks/blacklight.rake +1 -5
- metadata +14 -16
- data/.gitmodules +0 -0
- data/app/views/catalog/endnote.endnote.erb +0 -1
- data/app/views/catalog/show.endnote.erb +0 -1
- data/lib/generators/blacklight/blacklight_generator.rb +0 -97
- data/lib/generators/blacklight/templates/migrations/add_user_types_to_bookmarks_searches.rb +0 -16
- data/lib/generators/blacklight/templates/migrations/remove_editable_fields_from_bookmarks.rb +0 -12
- data/lib/railties/all_tests.rake +0 -39
- data/lib/railties/blacklight_rspec.rake +0 -128
data/lib/blacklight/user.rb
CHANGED
@@ -12,19 +12,10 @@ module Blacklight::User
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def has_bookmarks?
|
16
|
-
bookmarks.any?
|
17
|
-
end
|
18
|
-
|
19
|
-
def has_searches?
|
20
|
-
searches.any?
|
21
|
-
end
|
22
|
-
|
23
15
|
def bookmarked_document_ids
|
24
16
|
self.bookmarks.pluck(:document_id)
|
25
17
|
end
|
26
|
-
|
27
|
-
# see #current_bookmark_for, is easier
|
18
|
+
|
28
19
|
def document_is_bookmarked?(document_id)
|
29
20
|
bookmarked_document_ids.include? document_id.to_s
|
30
21
|
end
|
@@ -34,10 +25,4 @@ module Blacklight::User
|
|
34
25
|
def existing_bookmark_for(document_id)
|
35
26
|
self.bookmarks.where(:document_id => document_id).first
|
36
27
|
end
|
37
|
-
|
38
|
-
def documents_to_bookmark=(docs)
|
39
|
-
docs.reject { |doc| document_is_bookmarked?(doc[:document_id]) }.each do |doc|
|
40
|
-
self.bookmarks.create(doc)
|
41
|
-
end
|
42
|
-
end
|
43
28
|
end
|
data/lib/blacklight/utils.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
module Blacklight
|
3
3
|
class OpenStructWithHashAccess < OpenStruct
|
4
|
-
delegate :keys, :
|
4
|
+
delegate :keys, :has_key?, :delete, :length, :reject!, :select!, :include, :fetch, :to => :to_h
|
5
5
|
|
6
6
|
def []=(key, value)
|
7
7
|
send "#{key}=", value
|
@@ -14,5 +14,76 @@ module Blacklight
|
|
14
14
|
def to_h
|
15
15
|
@table
|
16
16
|
end
|
17
|
+
|
18
|
+
def merge other_hash
|
19
|
+
self.class.new to_h.merge((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
|
20
|
+
end
|
21
|
+
|
22
|
+
def merge! other_hash
|
23
|
+
@table.merge!((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class NestedOpenStructWithHashAccess < OpenStructWithHashAccess
|
28
|
+
attr_reader :nested_class
|
29
|
+
delegate :default_proc=, :to => :to_h
|
30
|
+
|
31
|
+
def initialize klass, *args
|
32
|
+
@nested_class = klass
|
33
|
+
hash = {}
|
34
|
+
|
35
|
+
hashes_and_keys = args.flatten
|
36
|
+
lazy_configs = hashes_and_keys.extract_options!
|
37
|
+
|
38
|
+
args.each do |v|
|
39
|
+
if v.is_a? Hash
|
40
|
+
key = v.first
|
41
|
+
value = v[key]
|
42
|
+
|
43
|
+
hash[key] = nested_class.new value
|
44
|
+
else
|
45
|
+
hash[v] = nested_class.new
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
lazy_configs.each do |k,v|
|
50
|
+
hash[k] = nested_class.new v
|
51
|
+
end
|
52
|
+
|
53
|
+
super hash
|
54
|
+
set_default_proc!
|
55
|
+
end
|
56
|
+
|
57
|
+
def << key
|
58
|
+
@table[key]
|
59
|
+
end
|
60
|
+
|
61
|
+
def []=(key, value)
|
62
|
+
if value.is_a? Hash
|
63
|
+
send "#{key}=", nested_class.new(value)
|
64
|
+
else
|
65
|
+
send "#{key}=", value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def marshal_dump
|
70
|
+
h = to_h.dup
|
71
|
+
h.default = nil
|
72
|
+
|
73
|
+
[nested_class, h]
|
74
|
+
end
|
75
|
+
|
76
|
+
def marshal_load x
|
77
|
+
@nested_class = x.first
|
78
|
+
super x.last
|
79
|
+
set_default_proc!
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def set_default_proc!
|
84
|
+
self.default_proc = lambda do |hash, key|
|
85
|
+
hash[key] = self.nested_class.new
|
86
|
+
end
|
87
|
+
end
|
17
88
|
end
|
18
89
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Blacklight
|
2
|
+
class Install < Rails::Generators::Base
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :model_name, :type => :string , :default => "user"
|
7
|
+
class_option :devise , :type => :boolean, :default => false, :aliases => "-d", :desc => "Use Devise as authentication logic."
|
8
|
+
class_option :marc , :type => :boolean, :default => false, :aliases => "-m", :desc => "Generate MARC-based demo ."
|
9
|
+
|
10
|
+
desc """
|
11
|
+
This generator makes the following changes to your application:
|
12
|
+
1. Generates blacklight:models
|
13
|
+
2. Creates a number of public assets, including images, stylesheets, and javascript
|
14
|
+
3. Injects behavior into your user application_controller.rb
|
15
|
+
4. Adds example configurations for dealing with MARC-like data
|
16
|
+
5. Adds Blacklight routes to your ./config/routes.rb
|
17
|
+
|
18
|
+
|
19
|
+
Thank you for Installing Blacklight.
|
20
|
+
"""
|
21
|
+
|
22
|
+
def bundle_install
|
23
|
+
Bundler.with_clean_env do
|
24
|
+
run "bundle install"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Copy all files in templates/public/ directory to public/
|
29
|
+
# Call external generator in AssetsGenerator, so we can
|
30
|
+
# leave that callable seperately too.
|
31
|
+
def copy_public_assets
|
32
|
+
generate "blacklight:assets"
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate_blacklight_models
|
36
|
+
|
37
|
+
generator_args = []
|
38
|
+
if options[:devise]
|
39
|
+
generator_args << "--devise #{options[:devise]}"
|
40
|
+
end
|
41
|
+
|
42
|
+
generate 'blacklight:models', generator_args.join(" ")
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add Blacklight to the application controller
|
46
|
+
def inject_blacklight_controller_behavior
|
47
|
+
# prepend_file("app/controllers/application_controller.rb", "require 'blacklight/controller'\n\n")
|
48
|
+
inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
|
49
|
+
" # Adds a few additional behaviors into the application controller \n " +
|
50
|
+
" include Blacklight::Controller\n" +
|
51
|
+
" # Please be sure to impelement current_user and user_session. Blacklight depends on \n" +
|
52
|
+
" # these methods in order to perform user specific actions. \n\n" +
|
53
|
+
" layout 'blacklight'\n\n"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Generate blacklight catalog controller
|
58
|
+
def create_blacklight_catalog
|
59
|
+
copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_blacklight_marc_demo
|
63
|
+
if options[:marc]
|
64
|
+
gem "blacklight_marc", ">= 0.0.9"
|
65
|
+
|
66
|
+
Bundler.with_clean_env do
|
67
|
+
run "bundle install"
|
68
|
+
end
|
69
|
+
|
70
|
+
generate 'blacklight_marc:marc'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def inject_blacklight_routes
|
75
|
+
# These will end up in routes.rb file in reverse order
|
76
|
+
# we add em, since each is added at the top of file.
|
77
|
+
# we want "root" to be FIRST for optimal url generation.
|
78
|
+
route('blacklight_for :catalog')
|
79
|
+
route('root :to => "catalog#index"')
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_sass_configuration
|
83
|
+
|
84
|
+
insert_into_file "config/application.rb", :after => "config.assets.enabled = true" do <<EOF
|
85
|
+
|
86
|
+
# Default SASS Configuration, check out https://github.com/rails/sass-rails for details
|
87
|
+
config.assets.compress = !Rails.env.development?
|
88
|
+
EOF
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -17,20 +17,6 @@ This generator makes the following changes to your application:
|
|
17
17
|
3. Injects behavior into your user model
|
18
18
|
4. Creates a blacklight document in your /app/models directory
|
19
19
|
"""
|
20
|
-
# Implement the required interface for Rails::Generators::Migration.
|
21
|
-
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
22
|
-
def self.next_migration_number(path)
|
23
|
-
if @prev_migration_nr
|
24
|
-
@prev_migration_nr += 1
|
25
|
-
else
|
26
|
-
if last_migration = Dir[File.join(path, '*.rb')].sort.last
|
27
|
-
@prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
|
28
|
-
else
|
29
|
-
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
30
|
-
end
|
31
|
-
end
|
32
|
-
@prev_migration_nr.to_s
|
33
|
-
end
|
34
20
|
|
35
21
|
def check_arguments
|
36
22
|
if File.exists?("app/models/#{model_name}.rb") and options[:devise]
|
@@ -77,11 +63,7 @@ This generator makes the following changes to your application:
|
|
77
63
|
|
78
64
|
# Setup the database migrations
|
79
65
|
def copy_migrations
|
80
|
-
|
81
|
-
better_migration_template "create_searches.rb"
|
82
|
-
better_migration_template "create_bookmarks.rb"
|
83
|
-
better_migration_template "remove_editable_fields_from_bookmarks.rb"
|
84
|
-
better_migration_template "add_user_types_to_bookmarks_searches.rb"
|
66
|
+
rake "blacklight:install:migrations"
|
85
67
|
end
|
86
68
|
|
87
69
|
|
@@ -103,11 +85,5 @@ This generator makes the following changes to your application:
|
|
103
85
|
copy_file "solr_document.rb", "app/models/solr_document.rb"
|
104
86
|
end
|
105
87
|
|
106
|
-
private
|
107
|
-
|
108
|
-
def better_migration_template(file)
|
109
|
-
migration_template "migrations/#{file}", "db/migrate/#{file}"
|
110
|
-
end
|
111
|
-
|
112
88
|
end
|
113
89
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
|
2
|
+
#
|
4
3
|
class CatalogController < ApplicationController
|
5
4
|
|
6
5
|
include Blacklight::Catalog
|
@@ -24,13 +23,12 @@ class CatalogController < ApplicationController
|
|
24
23
|
#}
|
25
24
|
|
26
25
|
# solr field configuration for search results/index views
|
27
|
-
config.index.
|
28
|
-
config.index.
|
26
|
+
config.index.title_field = 'title_display'
|
27
|
+
config.index.display_type_field = 'format'
|
29
28
|
|
30
29
|
# solr field configuration for document/show views
|
31
|
-
config.show.
|
32
|
-
config.show.
|
33
|
-
config.show.display_type = 'format'
|
30
|
+
#config.show.title_field = 'title_display'
|
31
|
+
#config.show.display_type_field = 'format'
|
34
32
|
|
35
33
|
# solr fields that will be treated as facets by the blacklight application
|
36
34
|
# The ordering of the field names is the order of the display
|
@@ -75,32 +73,32 @@ class CatalogController < ApplicationController
|
|
75
73
|
|
76
74
|
# solr fields to be displayed in the index (search results) view
|
77
75
|
# The ordering of the field names is the order of the display
|
78
|
-
config.add_index_field 'title_display', :label => 'Title
|
79
|
-
config.add_index_field 'title_vern_display', :label => 'Title
|
80
|
-
config.add_index_field 'author_display', :label => 'Author
|
81
|
-
config.add_index_field 'author_vern_display', :label => 'Author
|
82
|
-
config.add_index_field 'format', :label => 'Format
|
83
|
-
config.add_index_field 'language_facet', :label => 'Language
|
84
|
-
config.add_index_field 'published_display', :label => 'Published
|
85
|
-
config.add_index_field 'published_vern_display', :label => 'Published
|
86
|
-
config.add_index_field 'lc_callnum_display', :label => 'Call number
|
76
|
+
config.add_index_field 'title_display', :label => 'Title'
|
77
|
+
config.add_index_field 'title_vern_display', :label => 'Title'
|
78
|
+
config.add_index_field 'author_display', :label => 'Author'
|
79
|
+
config.add_index_field 'author_vern_display', :label => 'Author'
|
80
|
+
config.add_index_field 'format', :label => 'Format'
|
81
|
+
config.add_index_field 'language_facet', :label => 'Language'
|
82
|
+
config.add_index_field 'published_display', :label => 'Published'
|
83
|
+
config.add_index_field 'published_vern_display', :label => 'Published'
|
84
|
+
config.add_index_field 'lc_callnum_display', :label => 'Call number'
|
87
85
|
|
88
86
|
# solr fields to be displayed in the show (single result) view
|
89
87
|
# The ordering of the field names is the order of the display
|
90
|
-
config.add_show_field 'title_display', :label => 'Title
|
91
|
-
config.add_show_field 'title_vern_display', :label => 'Title
|
92
|
-
config.add_show_field 'subtitle_display', :label => 'Subtitle
|
93
|
-
config.add_show_field 'subtitle_vern_display', :label => 'Subtitle
|
94
|
-
config.add_show_field 'author_display', :label => 'Author
|
95
|
-
config.add_show_field 'author_vern_display', :label => 'Author
|
96
|
-
config.add_show_field 'format', :label => 'Format
|
97
|
-
config.add_show_field 'url_fulltext_display', :label => 'URL
|
98
|
-
config.add_show_field 'url_suppl_display', :label => 'More Information
|
99
|
-
config.add_show_field 'language_facet', :label => 'Language
|
100
|
-
config.add_show_field 'published_display', :label => 'Published
|
101
|
-
config.add_show_field 'published_vern_display', :label => 'Published
|
102
|
-
config.add_show_field 'lc_callnum_display', :label => 'Call number
|
103
|
-
config.add_show_field 'isbn_t', :label => 'ISBN
|
88
|
+
config.add_show_field 'title_display', :label => 'Title'
|
89
|
+
config.add_show_field 'title_vern_display', :label => 'Title'
|
90
|
+
config.add_show_field 'subtitle_display', :label => 'Subtitle'
|
91
|
+
config.add_show_field 'subtitle_vern_display', :label => 'Subtitle'
|
92
|
+
config.add_show_field 'author_display', :label => 'Author'
|
93
|
+
config.add_show_field 'author_vern_display', :label => 'Author'
|
94
|
+
config.add_show_field 'format', :label => 'Format'
|
95
|
+
config.add_show_field 'url_fulltext_display', :label => 'URL'
|
96
|
+
config.add_show_field 'url_suppl_display', :label => 'More Information'
|
97
|
+
config.add_show_field 'language_facet', :label => 'Language'
|
98
|
+
config.add_show_field 'published_display', :label => 'Published'
|
99
|
+
config.add_show_field 'published_vern_display', :label => 'Published'
|
100
|
+
config.add_show_field 'lc_callnum_display', :label => 'Call number'
|
101
|
+
config.add_show_field 'isbn_t', :label => 'ISBN'
|
104
102
|
|
105
103
|
# "fielded" search configuration. Used by pulldown among other places.
|
106
104
|
# For supported keys in hash, see rdoc for Blacklight::SearchFields
|
@@ -175,6 +173,4 @@ class CatalogController < ApplicationController
|
|
175
173
|
config.spell_max = 5
|
176
174
|
end
|
177
175
|
|
178
|
-
|
179
|
-
|
180
176
|
end
|
@@ -1,82 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
def exportable_record
|
4
|
-
"<record>
|
5
|
-
<leader>01828cjm a2200409 a 4500</leader>
|
6
|
-
<controlfield tag=\"001\">a4768316</controlfield>
|
7
|
-
<controlfield tag=\"003\">SIRSI</controlfield>
|
8
|
-
<controlfield tag=\"007\">sd fungnnmmned</controlfield>
|
9
|
-
<controlfield tag=\"008\">020117p20011990xxuzz h d</controlfield>
|
10
|
-
|
11
|
-
<datafield tag=\"245\" ind1=\"0\" ind2=\"0\">
|
12
|
-
<subfield code=\"a\">Music for horn</subfield>
|
13
|
-
<subfield code=\"h\">[sound recording] /</subfield>
|
14
|
-
<subfield code=\"c\">Brahms, Beethoven, von Krufft.</subfield>
|
15
|
-
</datafield>
|
16
|
-
|
17
|
-
<datafield tag=\"260\" ind1=\" \" ind2=\" \">
|
18
|
-
<subfield code=\"a\">[United States] :</subfield>
|
19
|
-
<subfield code=\"b\">Harmonia Mundi USA,</subfield>
|
20
|
-
<subfield code=\"c\">p2001.</subfield>
|
21
|
-
</datafield>
|
22
|
-
|
23
|
-
<datafield tag=\"700\" ind1=\"1\" ind2=\" \">
|
24
|
-
<subfield code=\"a\">Greer, Lowell.</subfield>
|
25
|
-
</datafield>
|
26
|
-
|
27
|
-
<datafield tag=\"700\" ind1=\"1\" ind2=\" \">
|
28
|
-
<subfield code=\"a\">Lubin, Steven.</subfield>
|
29
|
-
</datafield>
|
30
|
-
|
31
|
-
<datafield tag=\"700\" ind1=\"1\" ind2=\" \">
|
32
|
-
<subfield code=\"a\">Chase, Stephanie,</subfield>
|
33
|
-
<subfield code=\"d\">1957-</subfield>
|
34
|
-
</datafield>
|
35
|
-
|
36
|
-
<datafield tag=\"700\" ind1=\"1\" ind2=\"2\">
|
37
|
-
<subfield code=\"a\">Brahms, Johannes,</subfield>
|
38
|
-
<subfield code=\"d\">1833-1897.</subfield>
|
39
|
-
<subfield code=\"t\">Trios,</subfield>
|
40
|
-
<subfield code=\"m\">piano, violin, horn,</subfield>
|
41
|
-
<subfield code=\"n\">op. 40,</subfield>
|
42
|
-
<subfield code=\"r\">E? major.</subfield>
|
43
|
-
</datafield>
|
44
|
-
|
45
|
-
<datafield tag=\"700\" ind1=\"1\" ind2=\"2\">
|
46
|
-
<subfield code=\"a\">Beethoven, Ludwig van,</subfield>
|
47
|
-
<subfield code=\"d\">1770-1827.</subfield>
|
48
|
-
<subfield code=\"t\">Sonatas,</subfield>
|
49
|
-
<subfield code=\"m\">horn, piano,</subfield>
|
50
|
-
<subfield code=\"n\">op. 17,</subfield>
|
51
|
-
<subfield code=\"r\">F major.</subfield>
|
52
|
-
</datafield>
|
53
|
-
|
54
|
-
<datafield tag=\"700\" ind1=\"1\" ind2=\"2\">
|
55
|
-
<subfield code=\"a\">Krufft, Nikolaus von,</subfield>
|
56
|
-
<subfield code=\"d\">1779-1818.</subfield>
|
57
|
-
<subfield code=\"t\">Sonata,</subfield>
|
58
|
-
<subfield code=\"m\">horn, piano,</subfield>
|
59
|
-
<subfield code=\"r\">F major.</subfield>
|
60
|
-
</datafield>
|
61
|
-
</record>"
|
62
|
-
end
|
63
|
-
|
64
3
|
describe BlacklightHelper do
|
65
4
|
include ERB::Util
|
66
5
|
include BlacklightHelper
|
67
6
|
include Devise::TestHelpers
|
68
7
|
def blacklight_config
|
69
8
|
@config ||= Blacklight::Configuration.new.configure do |config|
|
70
|
-
config.
|
71
|
-
config.
|
72
|
-
config.show.display_type = 'format'
|
73
|
-
|
74
|
-
config.index.show_link = 'title_display'
|
75
|
-
config.index.record_display_type = 'format'
|
9
|
+
config.index.title_field = 'title_display'
|
10
|
+
config.index.display_type_field = 'format'
|
76
11
|
end
|
77
|
-
|
78
|
-
#CatalogController.blacklight_config
|
79
|
-
#@config ||= {:show => {:html_title => 'title_display', :heading => 'title_display', :display_type => 'format'}, :index => { :show_link => 'title_display', :record_display_type => 'format' } }
|
80
12
|
end
|
81
13
|
|
82
14
|
before(:each) do
|
@@ -100,344 +32,6 @@ describe BlacklightHelper do
|
|
100
32
|
end
|
101
33
|
end
|
102
34
|
|
103
|
-
describe "link_back_to_catalog" do
|
104
|
-
let(:query_params) {{:q => "query", :f => "facets", :per_page => "10", :page => "2", :controller=>'catalog'}}
|
105
|
-
let(:bookmarks_query_params) {{ :page => "2", :controller=>'bookmarks'}}
|
106
|
-
|
107
|
-
it "should build a link tag to catalog using session[:search] for query params" do
|
108
|
-
helper.stub(:current_search_session).and_return double(:query_params => query_params)
|
109
|
-
tag = helper.link_back_to_catalog
|
110
|
-
expect(tag).to match /q=query/
|
111
|
-
expect(tag).to match /f=facets/
|
112
|
-
expect(tag).to match /per_page=10/
|
113
|
-
expect(tag).to match /page=2/
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should build a link tag to bookmarks using session[:search] for query params" do
|
117
|
-
helper.stub(:current_search_session).and_return double(:query_params => bookmarks_query_params)
|
118
|
-
tag = helper.link_back_to_catalog
|
119
|
-
expect(tag).to match /Back to Bookmarks/
|
120
|
-
expect(tag).to match /\/bookmarks/
|
121
|
-
expect(tag).to match /page=2/
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "when an alternate scope is passed in" do
|
125
|
-
let(:my_engine) { double("Engine") }
|
126
|
-
|
127
|
-
it "should call url_for on the engine scope" do
|
128
|
-
helper.stub(:current_search_session).and_return double(:query_params => query_params)
|
129
|
-
expect(my_engine).to receive(:url_for).and_return(url_for(query_params))
|
130
|
-
tag = helper.link_back_to_catalog(route_set: my_engine)
|
131
|
-
expect(tag).to match /Back to Search/
|
132
|
-
expect(tag).to match /q=query/
|
133
|
-
expect(tag).to match /f=facets/
|
134
|
-
expect(tag).to match /per_page=10/
|
135
|
-
expect(tag).to match /page=2/
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "link_to_query" do
|
141
|
-
it "should build a link tag to catalog using query string (no other params)" do
|
142
|
-
query = "brilliant"
|
143
|
-
self.should_receive(:params).and_return({})
|
144
|
-
tag = link_to_query(query)
|
145
|
-
expect(tag).to match /q=#{query}/
|
146
|
-
expect(tag).to match />#{query}<\/a>/
|
147
|
-
end
|
148
|
-
it "should build a link tag to catalog using query string and other existing params" do
|
149
|
-
query = "wonderful"
|
150
|
-
self.should_receive(:params).and_return({:qt => "title_search", :per_page => "50"})
|
151
|
-
tag = link_to_query(query)
|
152
|
-
expect(tag).to match /qt=title_search/
|
153
|
-
expect(tag).to match /per_page=50/
|
154
|
-
end
|
155
|
-
it "should ignore existing :page param" do
|
156
|
-
query = "yes"
|
157
|
-
self.should_receive(:params).and_return({:page => "2", :qt => "author_search"})
|
158
|
-
tag = link_to_query(query)
|
159
|
-
expect(tag).to match /qt=author_search/
|
160
|
-
expect(tag).to_not match /page/
|
161
|
-
end
|
162
|
-
it "should be html_safe" do
|
163
|
-
query = "brilliant"
|
164
|
-
self.should_receive(:params).and_return({:page => "2", :qt => "author_search"})
|
165
|
-
tag = link_to_query(query)
|
166
|
-
expect(tag).to be_html_safe
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "params_for_search" do
|
171
|
-
def params
|
172
|
-
{ 'default' => 'params'}
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should default to using the controller's params" do
|
176
|
-
result = params_for_search
|
177
|
-
expect(result).to eq params
|
178
|
-
expect(params.object_id).to_not eq result.object_id
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should let you pass in params to use" do
|
182
|
-
source_params = { :q => 'query'}
|
183
|
-
result = params_for_search(:params => source_params )
|
184
|
-
expect(source_params).to eq result
|
185
|
-
expect(source_params.object_id).to_not eq result.object_id
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should not return blacklisted elements" do
|
189
|
-
source_params = { :action => 'action', :controller => 'controller', :id => "id", :commit => 'commit'}
|
190
|
-
result = params_for_search(:params => source_params )
|
191
|
-
expect(result.keys).to_not include(:action, :controller, :commit, :id)
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should adjust the current page if the per_page changes" do
|
195
|
-
source_params = { :per_page => 20, :page => 5}
|
196
|
-
result = params_for_search(:params => source_params, :per_page => 100)
|
197
|
-
expect(result[:page]).to eq 1
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should not adjust the current page if the per_page is the same as it always was" do
|
201
|
-
source_params = { :per_page => 20, :page => 5}
|
202
|
-
result = params_for_search(:params => source_params, :per_page => 20)
|
203
|
-
expect(result[:page]).to eq 5
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should adjust the current page if the sort changes" do
|
207
|
-
source_params = { :sort => 'field_a', :page => 5}
|
208
|
-
result = params_for_search(:params => source_params, :sort => 'field_b')
|
209
|
-
expect(result[:page]).to eq 1
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should not adjust the current page if the sort is the same as it always was" do
|
213
|
-
source_params = { :sort => 'field_a', :page => 5}
|
214
|
-
result = params_for_search(:params => source_params, :sort => 'field_a')
|
215
|
-
expect(result[:page]).to eq 5
|
216
|
-
end
|
217
|
-
|
218
|
-
describe "omit keys parameter" do
|
219
|
-
it "should omit keys by key name" do
|
220
|
-
source_params = { :a => 1, :b => 2, :c => 3}
|
221
|
-
result = params_for_search(:params => source_params, :omit_keys => [:a, :b] )
|
222
|
-
|
223
|
-
result.keys.should_not include(:a, :b)
|
224
|
-
expect(result[:c]).to eq 3
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should remove keys if a key/value pair was passed and no values are left for that key" do
|
228
|
-
source_params = { :f => ['a']}
|
229
|
-
result = params_for_search(:params => source_params, :omit_keys => [{:f => 'a' }])
|
230
|
-
expect(result.keys).to_not include(:f)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should only remove keys when a key/value pair is based that are in that pair" do
|
234
|
-
|
235
|
-
source_params = { :f => ['a', 'b']}
|
236
|
-
result = params_for_search(:params => source_params, :omit_keys => [{:f => 'a' }])
|
237
|
-
expect(result[:f]).to_not include('a')
|
238
|
-
expect(result[:f]).to include('b')
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
end
|
243
|
-
|
244
|
-
describe "search_as_hidden_fields" do
|
245
|
-
def params
|
246
|
-
{:q => "query", :sort => "sort", :per_page => "20", :search_field => "search_field", :page => 100, :arbitrary_key => "arbitrary_value", :f => {"field" => ["value1", "value2"], "other_field" => ['asdf']}, :controller => "catalog", :action => "index", :commit => "search"}
|
247
|
-
end
|
248
|
-
describe "for default arguments" do
|
249
|
-
it "should default to omitting :page" do
|
250
|
-
expect(search_as_hidden_fields).to_not have_selector("input[name='page']")
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
|
256
|
-
describe "render body class" do
|
257
|
-
it "should include a serialization of the current controller name" do
|
258
|
-
@controller = double("controller")
|
259
|
-
@controller.stub(:controller_name).and_return("123456")
|
260
|
-
@controller.stub(:action_name).and_return("abcdef")
|
261
|
-
|
262
|
-
expect(render_body_class.split(' ')).to include('blacklight-123456')
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should include a serialization of the current action name" do
|
266
|
-
@controller = double("controller")
|
267
|
-
@controller.stub(:controller_name).and_return("123456")
|
268
|
-
@controller.stub(:action_name).and_return("abcdef")
|
269
|
-
|
270
|
-
expect(render_body_class.split(' ')).to include('blacklight-123456-abcdef')
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
describe "document_heading" do
|
275
|
-
|
276
|
-
it "should consist of the show heading field when available" do
|
277
|
-
@document = SolrDocument.new('title_display' => "A Fake Document")
|
278
|
-
|
279
|
-
expect(document_heading).to eq "A Fake Document"
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should fallback on the document id if no title is available" do
|
283
|
-
@document = SolrDocument.new(:id => '123456')
|
284
|
-
expect(document_heading).to eq '123456'
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
describe "render_document_heading" do
|
289
|
-
it "should consist of #document_heading wrapped in a <h1>" do
|
290
|
-
@document = SolrDocument.new('title_display' => "A Fake Document")
|
291
|
-
|
292
|
-
expect(render_document_heading).to have_selector("h4", :text => "A Fake Document", :count => 1)
|
293
|
-
expect(render_document_heading).to be_html_safe
|
294
|
-
end
|
295
|
-
|
296
|
-
it "should have a schema.org itemprop for name" do
|
297
|
-
@document = SolrDocument.new('title_display' => "A Fake Document")
|
298
|
-
|
299
|
-
expect(render_document_heading).to have_selector("h4[@itemprop='name']", :text => "A Fake Document")
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should join the values if it is an array" do
|
303
|
-
@document = SolrDocument.new('title_display' => ["A Fake Document", 'Something Else'])
|
304
|
-
|
305
|
-
expect(render_document_heading).to have_selector("h4", :text => "A Fake Document, Something Else", :count => 1)
|
306
|
-
expect(render_document_heading).to be_html_safe
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
describe "document_show_html_title" do
|
311
|
-
it "should join the values if it is an array" do
|
312
|
-
@document = SolrDocument.new('title_display' => ["A Fake Document", 'Something Else'])
|
313
|
-
expect(document_show_html_title).to eq "A Fake Document, Something Else"
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
describe "document_index_view_type" do
|
318
|
-
it "should default to 'list'" do
|
319
|
-
expect(document_index_view_type).to eq 'list'
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should pluck values out of params" do
|
323
|
-
blacklight_config.stub(:document_index_view_types) { ['list', 'asdf'] }
|
324
|
-
params[:view] = 'asdf'
|
325
|
-
expect(document_index_view_type).to eq 'asdf'
|
326
|
-
|
327
|
-
params[:view] = 'not_in_list'
|
328
|
-
expect(document_index_view_type).to eq 'list'
|
329
|
-
end
|
330
|
-
|
331
|
-
it "should pluck values from supplied params" do
|
332
|
-
blacklight_config.stub(:document_index_view_types) { ['list', 'asdf'] }
|
333
|
-
params[:view] = 'asdf'
|
334
|
-
expect(document_index_view_type(:view => 'list')).to eq 'list'
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
describe "start_over_path" do
|
339
|
-
it 'should be the catalog path with the current view type' do
|
340
|
-
blacklight_config.stub(:document_index_view_types) { ['list', 'abc'] }
|
341
|
-
helper.stub(:blacklight_config => blacklight_config)
|
342
|
-
expect(helper.start_over_path(:view => 'abc')).to eq catalog_index_url(:view => 'abc')
|
343
|
-
end
|
344
|
-
|
345
|
-
it 'should not include the current view type if it is the default' do
|
346
|
-
blacklight_config.stub(:document_index_view_types) { ['list', 'abc'] }
|
347
|
-
helper.stub(:blacklight_config => blacklight_config)
|
348
|
-
expect(helper.start_over_path(:view => 'list')).to eq catalog_index_url
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe "render_document_index" do
|
353
|
-
it "should render the document_list" do
|
354
|
-
@document_list = ['a', 'b']
|
355
|
-
self.should_receive(:render).with(hash_including(:partial => 'document_gallery'))
|
356
|
-
render_document_index_with_view 'gallery', @document_list
|
357
|
-
end
|
358
|
-
|
359
|
-
it "should fall back on more specific templates" do
|
360
|
-
ex = ActionView::MissingTemplate.new [], '', '', '',''
|
361
|
-
self.should_receive(:render).with(hash_including(:partial => 'document_gallery')).and_raise(ex)
|
362
|
-
self.should_receive(:render).with(hash_including(:partial => 'catalog/document_gallery')).and_raise(ex)
|
363
|
-
self.should_receive(:render).with(hash_including(:partial => 'catalog/document_list'))
|
364
|
-
render_document_index_with_view 'gallery', @document_list
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
describe "document_partial_name" do
|
369
|
-
it "should default to 'default' when a format blank" do
|
370
|
-
expect(document_partial_name({})).to eq "default"
|
371
|
-
end
|
372
|
-
it "should handle normal formats correctly" do
|
373
|
-
expect(document_partial_name({"format" => "myformat"})).to eq "myformat"
|
374
|
-
end
|
375
|
-
it "should handle spaces correctly" do
|
376
|
-
expect(document_partial_name({"format" => "my format"})).to eq "my_format"
|
377
|
-
end
|
378
|
-
it "should handle capitalization correctly" do
|
379
|
-
expect(document_partial_name({"format" => "MyFormat"})).to eq "myformat"
|
380
|
-
end
|
381
|
-
it "should handle puncuation correctly" do
|
382
|
-
expect(document_partial_name({"format" => "My.Format"})).to eq "my_format"
|
383
|
-
end
|
384
|
-
it "should handle multi-valued fields correctly" do
|
385
|
-
expect(document_partial_name({"format" => ["My Format", "My OtherFormat"]})).to eq "my_format_my_otherformat"
|
386
|
-
end
|
387
|
-
it "should remove - characters because they will throw errors" do
|
388
|
-
expect(document_partial_name({"format" => "My-Format"})).to eq "my_format"
|
389
|
-
expect(document_partial_name({"format" => ["My-Format",["My Other-Format"]]})).to eq "my_format_my_other_format"
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
describe "link_to_document" do
|
394
|
-
it "should consist of the document title wrapped in a <a>" do
|
395
|
-
data = {'id'=>'123456','title_display'=>['654321'] }
|
396
|
-
@document = SolrDocument.new(data)
|
397
|
-
expect(link_to_document(@document, { :label => :title_display })).to have_selector("a", :text => '654321', :count => 1)
|
398
|
-
end
|
399
|
-
|
400
|
-
it "should accept and return a string label" do
|
401
|
-
data = {'id'=>'123456','title_display'=>['654321'] }
|
402
|
-
@document = SolrDocument.new(data)
|
403
|
-
expect(link_to_document(@document, { :label => "title_display" })).to have_selector("a", :text => 'title_display', :count => 1)
|
404
|
-
end
|
405
|
-
|
406
|
-
it "should accept and return a Proc" do
|
407
|
-
data = {'id'=>'123456','title_display'=>['654321'] }
|
408
|
-
@document = SolrDocument.new(data)
|
409
|
-
expect(link_to_document(@document, { :label => Proc.new { |doc, opts| doc.get(:id) + ": " + doc.get(:title_display) } })).to have_selector("a", :text => '123456: 654321', :count => 1)
|
410
|
-
end
|
411
|
-
it "should return id when label is missing" do
|
412
|
-
data = {'id'=>'123456'}
|
413
|
-
@document = SolrDocument.new(data)
|
414
|
-
expect(link_to_document(@document, { :label => :title_display })).to have_selector("a", :text => '123456', :count => 1)
|
415
|
-
end
|
416
|
-
|
417
|
-
it "should be html safe" do
|
418
|
-
data = {'id'=>'123456'}
|
419
|
-
@document = SolrDocument.new(data)
|
420
|
-
expect(link_to_document(@document, { :label => :title_display })).to be_html_safe
|
421
|
-
end
|
422
|
-
|
423
|
-
it "should convert the counter parameter into a data- attribute" do
|
424
|
-
data = {'id'=>'123456','title_display'=>['654321']}
|
425
|
-
@document = SolrDocument.new(data)
|
426
|
-
expect(link_to_document(@document, { :label => :title_display, :counter => 5 })).to match /data-counter="5"/
|
427
|
-
end
|
428
|
-
|
429
|
-
it "passes on the title attribute to the link_to_with_data method" do
|
430
|
-
@document = SolrDocument.new('id'=>'123456')
|
431
|
-
expect(link_to_document(@document,:label=>"Some crazy long label...",:title=>"Some crazy longer label")).to match(/title=\"Some crazy longer label\"/)
|
432
|
-
end
|
433
|
-
|
434
|
-
it "doesn't add an erroneous title attribute if one isn't provided" do
|
435
|
-
@document = SolrDocument.new('id'=>'123456')
|
436
|
-
expect(link_to_document(@document,:label=>"Some crazy long label...")).to_not match(/title=/)
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
|
441
35
|
describe "render_link_rel_alternates" do
|
442
36
|
class MockDocumentAppHelper
|
443
37
|
include Blacklight::Solr::Document
|
@@ -504,12 +98,8 @@ describe BlacklightHelper do
|
|
504
98
|
describe "with a config" do
|
505
99
|
before do
|
506
100
|
@config = Blacklight::Configuration.new.configure do |config|
|
507
|
-
config.
|
508
|
-
config.
|
509
|
-
config.show.display_type = 'format'
|
510
|
-
|
511
|
-
config.index.show_link = 'title_display'
|
512
|
-
config.index.record_display_type = 'format'
|
101
|
+
config.index.title_field = 'title_display'
|
102
|
+
config.index.display_type_field = 'format'
|
513
103
|
end
|
514
104
|
|
515
105
|
@document = SolrDocument.new('title_display' => "A Fake Document", 'id'=>'8')
|
@@ -626,7 +216,6 @@ describe BlacklightHelper do
|
|
626
216
|
end
|
627
217
|
end
|
628
218
|
|
629
|
-
|
630
219
|
describe "render_document_show_field_value" do
|
631
220
|
before do
|
632
221
|
@config = Blacklight::Configuration.new.configure do |config|
|
@@ -757,7 +346,6 @@ describe BlacklightHelper do
|
|
757
346
|
end
|
758
347
|
end
|
759
348
|
|
760
|
-
|
761
349
|
describe "#should_render_show_field?" do
|
762
350
|
it "should if the document has the field value" do
|
763
351
|
doc = double()
|
@@ -783,7 +371,6 @@ describe BlacklightHelper do
|
|
783
371
|
end
|
784
372
|
end
|
785
373
|
|
786
|
-
|
787
374
|
describe "render_grouped_response?" do
|
788
375
|
it "should check if the response ivar contains grouped data" do
|
789
376
|
assign(:response, double("SolrResponse", :grouped? => true))
|
@@ -819,4 +406,24 @@ describe BlacklightHelper do
|
|
819
406
|
expect(helper.render_field_value('a', double(:separator => nil, :itemprop => 'some-prop'))).to have_selector("span[@itemprop='some-prop']", :text => "a")
|
820
407
|
end
|
821
408
|
end
|
409
|
+
|
410
|
+
describe "should_show_spellcheck_suggestions?" do
|
411
|
+
before :each do
|
412
|
+
helper.stub spell_check_max: 5
|
413
|
+
end
|
414
|
+
it "should not show suggestions if there are enough results" do
|
415
|
+
response = double(total: 10)
|
416
|
+
expect(helper.should_show_spellcheck_suggestions? response).to be_false
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should only show suggestions if there are very few results" do
|
420
|
+
response = double(total: 4, spelling: double(words: [1]))
|
421
|
+
expect(helper.should_show_spellcheck_suggestions? response).to be_true
|
422
|
+
end
|
423
|
+
|
424
|
+
it "should show suggestions only if there are spelling suggestions available" do
|
425
|
+
response = double(total: 4, spelling: double(words: []))
|
426
|
+
expect(helper.should_show_spellcheck_suggestions? response).to be_false
|
427
|
+
end
|
428
|
+
end
|
822
429
|
end
|