blacklight 3.3.2 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/VERSION +1 -1
  2. data/app/helpers/blacklight/blacklight_helper_behavior.rb +2 -0
  3. data/app/views/catalog/_email_form.html.erb +6 -0
  4. data/app/views/folder/_tools.html.erb +3 -3
  5. data/blacklight.gemspec +3 -3
  6. data/lib/blacklight.rb +30 -4
  7. data/lib/blacklight/catalog.rb +5 -4
  8. data/lib/blacklight/configuration.rb +5 -2
  9. data/lib/blacklight/exceptions.rb +2 -0
  10. data/lib/blacklight/solr_helper.rb +18 -12
  11. data/lib/generators/blacklight/templates/catalog_controller.rb +12 -0
  12. data/lib/generators/blacklight/templates/config/solr.yml +2 -2
  13. data/lib/generators/blacklight/templates/migrations/add_user_types_to_bookmarks_searches.rb +2 -2
  14. data/lib/railties/all_tests.rake +16 -12
  15. data/lib/railties/blacklight_cucumber.rake +8 -10
  16. data/lib/railties/blacklight_rspec.rake +7 -7
  17. data/lib/railties/solr_marc.rake +13 -18
  18. data/test_support/bin/test.sh +1 -1
  19. data/test_support/features/record_view.feature +6 -0
  20. data/test_support/features/step_definitions/web_steps.rb +5 -0
  21. data/test_support/spec/controllers/catalog_controller_spec.rb +6 -2
  22. data/test_support/spec/helpers/blacklight_helper_spec.rb +70 -2
  23. data/test_support/spec/helpers/render_constraints_helper_spec.rb +5 -4
  24. data/test_support/spec/lib/blacklight_configuration_spec.rb +7 -0
  25. data/test_support/spec/lib/solr_helper_spec.rb +44 -4
  26. data/test_support/spec/lib/tasks/solr_marc_task_spec.rb +1 -1
  27. data/test_support/spec/views/catalog/index.atom.builder_spec.rb +13 -39
  28. metadata +10 -11
  29. data/test_support/spec/support/action_controller.rb +0 -43
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.3.2
1
+ 3.4.0
@@ -118,6 +118,7 @@ module Blacklight::BlacklightHelperBehavior
118
118
 
119
119
  def render_index_field_value args
120
120
  value = args[:value]
121
+ value ||= send(blacklight_config.index_fields[args[:field]][:helper_method], args) if args[:field] and blacklight_config.index_fields[args[:field]][:helper_method]
121
122
  value ||= args[:document].get(args[:field], :sep => nil) if args[:document] and args[:field]
122
123
  render_field_value value
123
124
  end
@@ -173,6 +174,7 @@ module Blacklight::BlacklightHelperBehavior
173
174
 
174
175
  def render_document_show_field_value args
175
176
  value = args[:value]
177
+ value ||= send(blacklight_config.show_fields[args[:field]][:helper_method], args) if args[:field] and blacklight_config.show_fields[args[:field]][:helper_method]
176
178
  value ||= args[:document].get(args[:field], :sep => nil) if args[:document] and args[:field]
177
179
  render_field_value value
178
180
  end
@@ -7,5 +7,11 @@
7
7
  <% @documents.each do |doc| %>
8
8
  <%=hidden_field_tag "id[]", doc.get(:id)%>
9
9
  <% end %>
10
+ <%- if params[:sort] -%>
11
+ <%= hidden_field_tag "sort", params[:sort] %>
12
+ <%- end -%>
13
+ <%- if params[:per_page] -%>
14
+ <%= hidden_field_tag "per_page", params[:per_page] %>
15
+ <%- end -%>
10
16
  <%= submit_tag "Send" %>
11
17
  <% end %>
@@ -1,15 +1,15 @@
1
1
  <ul class="folderTools">
2
2
  <li class="cite">
3
- <%= link_to "Cite", citation_catalog_path(:id => @documents.collect{|doc| doc.id}), {:id => 'citeLink', :name => 'citation'} %>
3
+ <%= link_to "Cite", citation_catalog_path(:sort=>params[:sort], :per_page=>params[:per_page], :id => @documents.collect{|doc| doc.id}), {:id => 'citeLink', :name => 'citation'} %>
4
4
  </li>
5
5
  <li class="refworks">
6
6
  <%= render :partial => 'catalog/refworks_form', :locals => {:documents=>@documents} %>
7
7
  </li>
8
8
  <li class="endnote">
9
- <%= link_to "Export to EndNote", endnote_catalog_path(:id => @documents.collect {|doc| doc.id}, :format => 'endnote')%>
9
+ <%= link_to "Export to EndNote", endnote_catalog_path(:sort=>params[:sort], :per_page=>params[:per_page], :id => @documents.collect {|doc| doc.id}, :format => 'endnote')%>
10
10
  </li>
11
11
  <li class="email">
12
- <%= link_to "Email", email_catalog_path(:id => @documents.collect {|doc| doc.id}), :class=>"lightboxLink", :id => "emailLink" %>
12
+ <%= link_to "Email", email_catalog_path(:sort=>params[:sort], :per_page=>params[:per_page], :id => @documents.collect {|doc| doc.id}), :class=>"lightboxLink", :id => "emailLink" %>
13
13
  </li>
14
14
  <% if has_user_authentication_provider? and current_user %>
15
15
  <li>
data/blacklight.gemspec CHANGED
@@ -5,11 +5,11 @@ Gem::Specification.new do |s|
5
5
  s.name = "blacklight"
6
6
  s.version = Blacklight::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["Jonathan Rochkind", "Matt Mitchell", "Chris Beer", "Jessie Keck", "Jason Ronallo", "Vernon Chapman", "Mark A. Matienzo", "Dan Funk"]
8
+ s.authors = ["Jonathan Rochkind", "Matt Mitchell", "Chris Beer", "Jessie Keck", "Jason Ronallo", "Vernon Chapman", "Mark A. Matienzo", "Dan Funk", "Naomi Dushay"]
9
9
  s.email = ["blacklight-development@googlegroups.com"]
10
10
  s.homepage = "http://projectblacklight.org/"
11
- s.summary = "A next-generation Library Catalag for Universities"
12
- s.description = %q{Blacklight is a free and open source ruby-on-rails based discovery interface (a.k.a. “next-generation catalog”) especially optimized for heterogeneous collections. You can use it as a library catalog, as a front end for a digital repository, or as a single-search interface to aggregate digital content that would otherwise be siloed.}
11
+ s.summary = "Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr) index."
12
+ s.description = %q{Blacklight is an open source Solr user interface discovery platform. You can use Blacklight to enable searching and browsing of your collections. Blacklight uses the Apache Solr search engine to search full text and/or metadata.}
13
13
 
14
14
  s.rubyforge_project = "blacklight"
15
15
 
data/lib/blacklight.rb CHANGED
@@ -55,13 +55,39 @@ module Blacklight
55
55
 
56
56
  def self.solr_config
57
57
  @solr_config ||= begin
58
- raise "You are missing a solr configuration file: #{solr_file}. Have you run \"rails generate blacklight\"?" unless File.exists?(solr_file)
59
- solr_config = YAML::load(File.open(solr_file))
60
- raise "The #{::Rails.env} environment settings were not found in the solr.yml config" unless solr_config[::Rails.env]
61
- solr_config[::Rails.env].symbolize_keys
58
+ raise "The #{::Rails.env} environment settings were not found in the solr.yml config" unless solr_yml[::Rails.env]
59
+ solr_yml[::Rails.env].symbolize_keys
62
60
  end
63
61
  end
64
62
 
63
+ def self.solr_yml
64
+ require 'erb'
65
+ require 'yaml'
66
+
67
+ return @solr_yml if @solr_yml
68
+ unless File.exists?(solr_file)
69
+ raise "You are missing a solr configuration file: #{solr_file}. Have you run \"rails generate blacklight\"?"
70
+ end
71
+
72
+ begin
73
+ @solr_erb = ERB.new(IO.read(solr_file)).result(binding)
74
+ rescue Exception => e
75
+ raise("solr.yml was found, but could not be parsed with ERB. \n#{$!.inspect}")
76
+ end
77
+
78
+ begin
79
+ @solr_yml = YAML::load(@solr_erb)
80
+ rescue StandardError => e
81
+ raise("solr.yml was found, but could not be parsed.\n")
82
+ end
83
+
84
+ if @solr_yml.nil? || !@solr_yml.is_a?(Hash)
85
+ raise("solr.yml was found, but was blank or malformed.\n")
86
+ end
87
+
88
+ return @solr_yml
89
+ end
90
+
65
91
  def self.logger
66
92
  ::Rails.logger
67
93
  end
@@ -255,11 +255,12 @@ module Blacklight::Catalog
255
255
  # Set the notice flag if the flash[:notice] is already set to the error that we are setting.
256
256
  # This is intended to stop the redirect loop error
257
257
  notice = flash[:notice] if flash[:notice] == flash_notice
258
+ logger.error exception
258
259
  unless notice
259
260
  flash[:notice] = flash_notice
260
261
  redirect_to root_path, :status => 500
261
262
  else
262
- render :template => "public/500.html", :layout => false, :status => 500
263
+ render :file => "#{Rails.root}/public/500.html", :status => 500
263
264
  end
264
265
  end
265
266
  end
@@ -270,9 +271,9 @@ module Blacklight::Catalog
270
271
  render # will give us the stack trace
271
272
  else
272
273
  flash[:notice] = "Sorry, you have requested a record that doesn't exist."
273
- redirect_to root_path, :status => 404
274
+ params.delete(:id)
275
+ index
276
+ render "index", :status => 404
274
277
  end
275
-
276
278
  end
277
-
278
279
  end
@@ -8,9 +8,12 @@ module Blacklight
8
8
  # the basic, required Blacklight fields
9
9
  class << self; attr_accessor :default_values; end
10
10
  @default_values = {
11
+ :solr_request_handler => 'select',
11
12
  :default_solr_params => {},
12
- :show => OpenStructWithHashAccess.new,
13
- :index => OpenStructWithHashAccess.new,
13
+ :document_solr_request_handler => nil,
14
+ :default_document_solr_params => {},
15
+ :show => OpenStructWithHashAccess.new(:html_title => SolrDocument.unique_key, :heading => SolrDocument.unique_key),
16
+ :index => OpenStructWithHashAccess.new(:show_link => SolrDocument.unique_key),
14
17
  :spell_max => 5,
15
18
  :max_per_page => 100
16
19
  }
@@ -10,5 +10,7 @@ module Blacklight
10
10
  class InvalidSolrID < RuntimeError
11
11
  end
12
12
 
13
+ class ECONNREFUSED < ::Errno::ECONNREFUSED; end
14
+
13
15
  end
14
16
  end
@@ -81,8 +81,11 @@ module Blacklight::SolrHelper
81
81
  value
82
82
  end
83
83
 
84
- def find(params)
85
- response = force_to_utf8(Blacklight.solr.find(params))
84
+ def find(*args)
85
+ response = Blacklight.solr.find(*args)
86
+ force_to_utf8(response)
87
+ rescue Errno::ECONNREFUSED => e
88
+ raise Blacklight::Exceptions::ECONNREFUSED.new("Unable to connect to Solr instance using #{Blacklight.solr.inspect}")
86
89
  end
87
90
 
88
91
 
@@ -314,7 +317,7 @@ module Blacklight::SolrHelper
314
317
  # better for us.
315
318
  bench_start = Time.now
316
319
 
317
- solr_response = find(self.solr_search_params(user_params).merge(extra_controller_params))
320
+ solr_response = find(blacklight_config.solr_request_handler, self.solr_search_params(user_params).merge(extra_controller_params))
318
321
  document_list = solr_response.docs.collect {|doc| SolrDocument.new(doc, solr_response)}
319
322
  Rails.logger.debug("Solr fetch: #{self.class}#get_search_results (#{'%.1f' % ((Time.now.to_f - bench_start.to_f)*1000)}ms)")
320
323
 
@@ -326,17 +329,20 @@ module Blacklight::SolrHelper
326
329
  # This method is primary called by the get_solr_response_for_doc_id method.
327
330
  def solr_doc_params(id=nil)
328
331
  id ||= params[:id]
329
- # just to be consistent with the other solr param methods:
330
- {
331
- :qt => :document,
332
+
333
+ p = blacklight_config.default_document_solr_params.merge({
332
334
  :id => id # this assumes the document request handler will map the 'id' param to the unique key field
333
- }
335
+ })
336
+
337
+ p[:qt] ||= 'document'
338
+
339
+ p
334
340
  end
335
341
 
336
342
  # a solr query method
337
343
  # retrieve a solr document, given the doc id
338
344
  def get_solr_response_for_doc_id(id=nil, extra_controller_params={})
339
- solr_response = find solr_doc_params(id).merge(extra_controller_params)
345
+ solr_response = find((blacklight_config.document_solr_request_handler || blacklight_config.solr_request_handler), solr_doc_params(id).merge(extra_controller_params))
340
346
  raise Blacklight::Exceptions::InvalidSolrID.new if solr_response.docs.empty?
341
347
  document = SolrDocument.new(solr_response.docs.first, solr_response)
342
348
  [solr_response, document]
@@ -367,7 +373,7 @@ module Blacklight::SolrHelper
367
373
  :spellcheck => 'false'
368
374
  }.merge(extra_solr_params)
369
375
 
370
- solr_response = find( self.solr_search_params().merge(solr_params) )
376
+ solr_response = find(blacklight_config.solr_request_handler, self.solr_search_params().merge(solr_params) )
371
377
  document_list = solr_response.docs.collect{|doc| SolrDocument.new(doc, solr_response) }
372
378
  [solr_response,document_list]
373
379
  end
@@ -413,7 +419,7 @@ module Blacklight::SolrHelper
413
419
  solr_params = solr_facet_params(facet_field, params, extra_controller_params)
414
420
 
415
421
  # Make the solr call
416
- response =find(solr_params)
422
+ response =find(blacklight_config.solr_request_handler, solr_params)
417
423
 
418
424
  limit =
419
425
  if respond_to?(:facet_list_limit)
@@ -447,7 +453,7 @@ module Blacklight::SolrHelper
447
453
  solr_params[:start] = (index - 1) # start at 0 to get 1st doc, 1 to get 2nd.
448
454
  solr_params[:rows] = 1
449
455
  solr_params[:fl] = '*'
450
- solr_response = find(solr_params)
456
+ solr_response = find(blacklight_config.solr_request_handler, solr_params)
451
457
  SolrDocument.new(solr_response.docs.first, solr_response) unless solr_response.docs.empty?
452
458
  end
453
459
 
@@ -470,7 +476,7 @@ module Blacklight::SolrHelper
470
476
  # where the field is the "field" argument passed in.
471
477
  def get_opensearch_response(field=nil, extra_controller_params={})
472
478
  solr_params = solr_opensearch_params().merge(extra_controller_params)
473
- response = find(solr_params)
479
+ response = find(blacklight_config.solr_request_handler, solr_params)
474
480
  a = [solr_params[:q]]
475
481
  a << response.docs.map {|doc| doc[solr_params[:fl]].to_s }
476
482
  end
@@ -6,11 +6,23 @@ class CatalogController < ApplicationController
6
6
  include Blacklight::Catalog
7
7
 
8
8
  configure_blacklight do |config|
9
+ ## Default parameters to send to solr for all search-like requests. See also SolrHelper#solr_search_params
9
10
  config.default_solr_params = {
10
11
  :qt => 'search',
11
12
  :rows => 10
12
13
  }
13
14
 
15
+ ## Default parameters to send on single-document requests to Solr. These settings are the Blackligt defaults (see SolrHelper#solr_doc_params) or
16
+ ## parameters included in the Blacklight-jetty document requestHandler.
17
+ #
18
+ #config.default_document_solr_params = {
19
+ # :qt => 'document',
20
+ # ## These are hard-coded in the blacklight 'document' requestHandler
21
+ # # :fl => '*',
22
+ # # :rows => 1
23
+ # # :q => '{!raw f=id v=$id}'
24
+ #}
25
+
14
26
  # solr field configuration for search results/index views
15
27
  config.index.show_link = 'title_display'
16
28
  config.index.record_display_type = 'format'
@@ -13,6 +13,6 @@
13
13
  development:
14
14
  url: http://127.0.0.1:8983/solr
15
15
  test: &test
16
- url: http://127.0.0.1:8888/solr
16
+ url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8888}/solr" %>
17
17
  cucumber:
18
- <<: *test
18
+ <<: *test
@@ -10,7 +10,7 @@ class AddUserTypesToBookmarksSearches < ActiveRecord::Migration
10
10
  end
11
11
 
12
12
  def self.down
13
- remove_column :searches, :user_type, :string
14
- remove_column :bookmarks, :user_type, :string
13
+ remove_column :searches, :user_type
14
+ remove_column :bookmarks, :user_type
15
15
  end
16
16
  end
@@ -9,14 +9,16 @@ namespace :blacklight do
9
9
 
10
10
  desc "Run Blacklight cucumber and rspec, with test solr"
11
11
  task :hudson do
12
- solr_yml_path = Blacklight.locate_path("config", "solr.yml")
13
- jetty_path = if ( File.exists?( solr_yml_path ))
14
- solr_config = YAML::load(File.open(solr_yml_path))
15
- solr_config["test"]["jetty_path"] if solr_config["test"]
16
- end
17
- raise Exception.new("Can't find jetty path to start test jetty. Expect a jetty_path key in config/solr.yml for test environment.") unless jetty_path
12
+ solr_config = Blacklight.solr_yml["test"]
13
+ if solr_config
14
+ jetty_path = solr_config["jetty_path"]
15
+ uri = URI(solr_config["url"])
16
+ jetty_port = uri.port if ['127.0.0.1', 'localhost'].include? uri.host
17
+ end
18
+ raise Exception.new("Can't find jetty path to start test jetty. Expect a jetty_path key in config/solr.yml for test environment.") unless jetty_path
18
19
 
19
20
  error = Jettywrapper.wrap(
21
+ :jetty_port => jetty_port,
20
22
  :jetty_home => File.expand_path(jetty_path, Rails.root),
21
23
  :sleep_after_start => 2) do
22
24
  Rake::Task["blacklight:spec"].invoke
@@ -29,15 +31,17 @@ namespace :blacklight do
29
31
  namespace :all_tests do
30
32
  task :rcov do
31
33
  desc "Run Blacklight rspec and cucumber tests with rcov"
32
- solr_yml_path = Blacklight.locate_path("config", "solr.yml")
33
- jetty_path = if ( File.exists?( solr_yml_path ))
34
- solr_config = YAML::load(File.open(solr_yml_path))
35
- solr_config["test"]["jetty_path"] if solr_config["test"]
36
- end
37
- raise Exception.new("Can't find jetty path to start test jetty. Expect a jetty_path key in config/solr.yml for test environment.") unless jetty_path
34
+ solr_config = Blacklight.solr_yml["test"]
35
+ if solr_config
36
+ jetty_path = solr_config["jetty_path"]
37
+ uri = URI(solr_config["url"])
38
+ jetty_port = uri.port if ['127.0.0.1', 'localhost'].include? uri.host
39
+ end
40
+ raise Exception.new("Can't find jetty path to start test jetty. Expect a jetty_path key in config/solr.yml for test environment.") unless jetty_path
38
41
 
39
42
  rm "blacklight-coverage.data" if File.exist?("blacklight-coverage.data")
40
43
  error = Jettywrapper.wrap(
44
+ :jetty_port => jetty_port,
41
45
  :jetty_home => File.expand_path(jetty_path, Rails.root),
42
46
  :sleep_after_start => 2) do
43
47
  Rake::Task["blacklight:spec:rcov"].invoke
@@ -81,20 +81,18 @@ begin
81
81
  desc "blacklight:cucumber with jetty/solr launch"
82
82
  task :with_solr do
83
83
  require 'jettywrapper'
84
- # wrap tests with a test-specific Solr server
85
- # Need to look up where the test jetty is located
86
- # from solr.yml, we don't hardcode it anymore.
87
-
88
- solr_yml_path = Blacklight.locate_path("config", "solr.yml")
89
- jetty_path = if ( File.exists?( solr_yml_path ))
90
- solr_config = YAML::load(File.open(solr_yml_path))
91
- solr_config["test"]["jetty_path"] if solr_config["test"]
84
+ solr_config = Blacklight.solr_yml["test"]
85
+ if solr_config
86
+ jetty_path = solr_config["jetty_path"]
87
+ uri = URI(solr_config["url"])
88
+ jetty_port = uri.port if ['127.0.0.1', 'localhost'].include? uri.host
92
89
  end
93
90
  raise Exception.new("Can't find jetty path to start test jetty. Expect a jetty_path key in config/solr.yml for test environment.") unless jetty_path
94
-
91
+
95
92
  error = Jettywrapper.wrap(
93
+ :jetty_port => jetty_port,
96
94
  :jetty_home => File.expand_path(jetty_path, Rails.root),
97
- :sleep_after_start => 2) do
95
+ :sleep_after_start => 2) do
98
96
  Rake::Task["blacklight:cucumber"].invoke
99
97
  end
100
98
 
@@ -79,18 +79,18 @@ begin
79
79
  # Need to look up where the test jetty is located
80
80
  # from solr.yml, we don't hardcode it anymore.
81
81
 
82
- solr_yml_path = Blacklight.locate_path("config", "solr.yml")
83
- jetty_path = if ( File.exists?( solr_yml_path ))
84
- solr_config = YAML::load(File.open(solr_yml_path))
85
- solr_config["test"]["jetty_path"] if solr_config["test"]
82
+ solr_config = Blacklight.solr_yml["test"]
83
+ if solr_config
84
+ jetty_path = solr_config["jetty_path"]
85
+ uri = URI(solr_config["url"])
86
+ jetty_port = uri.port if ['127.0.0.1', 'localhost'].include? uri.host
86
87
  end
87
88
  raise Exception.new("Can't find jetty path to start test jetty. Expect a jetty_path key in config/solr.yml for test environment.") unless jetty_path
88
89
 
89
-
90
- # wrap tests with a test-specific Solr server
91
90
  error = Jettywrapper.wrap(
91
+ :jetty_port => jetty_port,
92
92
  :jetty_home => File.expand_path(jetty_path, Rails.root),
93
- :sleep_after_start => 2) do
93
+ :sleep_after_start => 2) do
94
94
  Rake::Task["blacklight:spec"].invoke
95
95
  end
96
96
  raise "test failures: #{error}" if error
@@ -88,13 +88,14 @@ def compute_arguments
88
88
  arguments["MARC_FILE"] = ENV["MARC_FILE"]
89
89
 
90
90
 
91
- app_site_path = File.expand_path(File.join(Rails.root, "config", "SolrMarc"))
92
- plugin_site_path = File.expand_path(File.join(Rails.root, "vendor", "plugins", "blacklight", "config", "SolrMarc"))
91
+ arguments[:config_properties_path] = ENV['CONFIG_PATH']
93
92
 
94
93
 
95
94
  # Find config in local app or plugin, possibly based on our RAILS_ENV (::Rails.env)
96
- arguments[:config_properties_path] = ENV['CONFIG_PATH']
97
95
  unless arguments[:config_properties_path]
96
+ app_site_path = File.expand_path(File.join(Rails.root, "config", "SolrMarc"))
97
+ plugin_site_path = File.expand_path(File.join(Rails.root, "vendor", "plugins", "blacklight", "config", "SolrMarc"))
98
+
98
99
  [ File.join(app_site_path, "config-#{::Rails.env}.properties" ),
99
100
  File.join( app_site_path, "config.properties"),
100
101
  File.join( plugin_site_path, "config-#{::Rails.env}.properties"),
@@ -117,29 +118,23 @@ def compute_arguments
117
118
 
118
119
 
119
120
 
121
+ # solrmarc.solr.war.path and solr.path, for now pull out of ENV
122
+ # if present. In progress. jrochkind 25 Apr 2011.
123
+ arguments[:solr_war_path] = ENV["SOLR_WAR_PATH"] if ENV["SOLR_WAR_PATH"]
124
+ arguments[:solr_path] = ENV['SOLR_PATH'] if ENV['SOLR_PATH']
120
125
 
121
126
  # Solr URL, find from solr.yml, app or plugin
122
127
  # use :replicate_master_url for current env if present, otherwise :url
123
128
  # for current env.
124
129
  # Also take jetty_path from there if present.
125
- solr_yml_path = locate_path("config", "solr.yml")
126
- if ( File.exists?( solr_yml_path ))
127
- solr_config = YAML::load(File.open(solr_yml_path))
128
- if c = solr_config[::Rails.env]
129
- arguments[:solr_url] = c['url']
130
- if c['jetty_path']
131
- arguments[:solr_path] = File.expand_path(File.join(c['jetty_path'], "solr"), Rails.root)
132
- arguments[:solr_war_path] = File.expand_path(File.join(c['jetty_path'], "webapps", "solr.war"), Rails.root)
130
+ if c = Blacklight.solr_config
131
+ arguments[:solr_url] = c[:url]
132
+ if c[:jetty_path]
133
+ arguments[:solr_path] ||= File.expand_path(File.join(c[:jetty_path], "solr"), Rails.root)
134
+ arguments[:solr_war_path] ||= File.expand_path(File.join(c[:jetty_path], "webapps", "solr.war"), Rails.root)
133
135
  end
134
- end
135
136
  end
136
137
 
137
- # solrmarc.solr.war.path and solr.path, for now pull out of ENV
138
- # if present. In progress. jrochkind 25 Apr 2011.
139
- arguments[:solr_war_path] = ENV["SOLR_WAR_PATH"] if ENV["SOLR_WAR_PATH"]
140
- arguments[:solr_path] = ENV['SOLR_PATH'] if ENV['SOLR_PATH']
141
-
142
-
143
138
  return arguments
144
139
  end
145
140
 
@@ -38,7 +38,7 @@ rm -rf tmp/test_app
38
38
  mkdir -p tmp/test_app
39
39
  cd tmp
40
40
 
41
- # Make certain rvn will work correctly.
41
+ # Make certain rvm will work correctly.
42
42
  # Load RVM into a shell session *as a function*
43
43
  if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
44
44
  # First try to load from a user install
@@ -32,3 +32,9 @@ Feature: Record View
32
32
  Then I should see /次按驟變/
33
33
  And I should see /林行止/
34
34
  And I should see /臺北縣板橋市/
35
+
36
+ Scenario: a document is requested doesn't exist in solr
37
+ Given I am on the document page for id this_id_does_not_exist
38
+ Then I should get a status code 404
39
+ And I should see "Sorry, you have requested a record that doesn't exist."
40
+
@@ -210,3 +210,8 @@ end
210
210
  Then /^show me the page$/ do
211
211
  save_and_open_page
212
212
  end
213
+
214
+ Then /^I should get a status code (\d+)/ do |http_status|
215
+ page.driver.status_code.should == http_status.to_i
216
+ end
217
+
@@ -442,18 +442,22 @@ describe CatalogController do
442
442
  controller.stub(:find => @mock_response,
443
443
  :get_single_doc_via_search => @mock_document)
444
444
  get :show, :id=>"987654321"
445
- response.redirect_url.should == root_url
446
445
  request.flash[:notice].should == "Sorry, you have requested a record that doesn't exist."
447
446
  response.should_not be_success
448
447
  response.status.should == 404
449
448
  end
450
449
  it "should return a status 500 for a bad search" do
451
- controller.stub(:get_search_results) { |*args| raise RSolr::Error::Http.new(nil, nil) }
450
+ req = {}
451
+ res = {}
452
+ fake_error = RSolr::Error::Http.new(req, res)
453
+ controller.stub(:get_search_results) { |*args| raise fake_error }
454
+ controller.logger.should_receive(:error).with(fake_error)
452
455
  get :index, :q=>"+"
453
456
  response.redirect_url.should == root_url
454
457
  request.flash[:notice].should == "Sorry, I don't understand your search."
455
458
  response.should_not be_success
456
459
  response.status.should == 500
460
+ response.should render_template(:file=>"#{Rails.root}/public/500.html")
457
461
  end
458
462
 
459
463
  end
@@ -266,12 +266,15 @@ describe BlacklightHelper do
266
266
  @document = SolrDocument.new(data)
267
267
  link_to_document(@document, { :label => :title_display, :counter => 5 }).should =~ /data-counter="5"/
268
268
  end
269
+
269
270
  it "passes on the title attribute to the link_to_with_data method" do
270
- link_to_document(@mock_doc,:label=>"Some crazy long label...",:title=>"Some crazy longer label").should match(/title=\"Some crazy longer label\"/)
271
+ @document = SolrDocument.new('id'=>'123456')
272
+ link_to_document(@document,:label=>"Some crazy long label...",:title=>"Some crazy longer label").should match(/title=\"Some crazy longer label\"/)
271
273
  end
272
274
 
273
275
  it "doesn't add an erroneous title attribute if one isn't provided" do
274
- link_to_document(@mock_doc,:label=>"Some crazy long label...").should_not match(/title=/)
276
+ @document = SolrDocument.new('id'=>'123456')
277
+ link_to_document(@document,:label=>"Some crazy long label...").should_not match(/title=/)
275
278
  end
276
279
  end
277
280
 
@@ -359,5 +362,70 @@ describe BlacklightHelper do
359
362
  end
360
363
  end
361
364
 
365
+ describe "render_index_field_value" do
366
+ before do
367
+ @config = Blacklight::Configuration.new.configure do |config|
368
+ config.add_index_field 'qwer'
369
+ config.add_index_field 'asdf', :helper_method => :render_asdf_index_field
370
+ end
371
+ helper.stub(:blacklight_config).and_return(@config)
372
+ end
373
+
374
+ it "should check for an explicit value" do
375
+ doc = mock()
376
+ doc.should_not_receive(:get).with('asdf', :sep => nil)
377
+ value = helper.render_index_field_value :value => 'asdf', :document => doc, :field => 'asdf'
378
+ value.should == 'asdf'
379
+ end
380
+
381
+ it "should check for a helper method to call" do
382
+ doc = mock()
383
+ doc.should_not_receive(:get).with('asdf', :sep => nil)
384
+ helper.stub(:render_asdf_index_field).and_return('custom asdf value')
385
+ value = helper.render_index_field_value :document => doc, :field => 'asdf'
386
+ value.should == 'custom asdf value'
387
+ end
388
+
389
+ it "should check the document field value" do
390
+ doc = mock()
391
+ doc.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
392
+ value = helper.render_index_field_value :document => doc, :field => 'qwer'
393
+ value.should == 'document qwer value'
394
+ end
395
+ end
396
+
397
+
398
+ describe "render_document_show_field_value" do
399
+ before do
400
+ @config = Blacklight::Configuration.new.configure do |config|
401
+ config.add_show_field 'qwer'
402
+ config.add_show_field 'asdf', :helper_method => :render_asdf_document_show_field
403
+ end
404
+ helper.stub(:blacklight_config).and_return(@config)
405
+ end
406
+
407
+ it "should check for an explicit value" do
408
+ doc = mock()
409
+ doc.should_not_receive(:get).with('asdf', :sep => nil)
410
+ helper.should_not_receive(:render_asdf_document_show_field)
411
+ value = helper.render_document_show_field_value :value => 'asdf', :document => doc, :field => 'asdf'
412
+ value.should == 'asdf'
413
+ end
414
+
415
+ it "should check for a helper method to call" do
416
+ doc = mock()
417
+ doc.should_not_receive(:get).with('asdf', :sep => nil)
418
+ helper.stub(:render_asdf_document_show_field).and_return('custom asdf value')
419
+ value = helper.render_document_show_field_value :document => doc, :field => 'asdf'
420
+ value.should == 'custom asdf value'
421
+ end
422
+
423
+ it "should check the document field value" do
424
+ doc = mock()
425
+ doc.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
426
+ value = helper.render_document_show_field_value :document => doc, :field => 'qwer'
427
+ value.should == 'document qwer value'
428
+ end
429
+ end
362
430
 
363
431
  end
@@ -3,12 +3,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe RenderConstraintsHelper do
4
4
 
5
5
  before do
6
- ## Pretend that we're in a controller at /advanced_search
7
- Journey::Route.any_instance.stub(:format).and_return('/advanced_search')
6
+ # the helper methods below infer paths from the current route
7
+ controller.request.path_parameters["controller"] = 'catalog'
8
8
  end
9
+
9
10
  describe '#render_constraints_query' do
10
11
  it "should have a link relative to the current url" do
11
- helper.render_constraints_query(:q=>'foobar', :f=>{:type=>'journal'}).should have_selector "a[href='/advanced_search?f%5Btype%5D=journal']"
12
+ helper.render_constraints_query(:q=>'foobar', :f=>{:type=>'journal'}).should have_selector "a[href='/catalog?f%5Btype%5D=journal']"
12
13
  end
13
14
  end
14
15
 
@@ -23,7 +24,7 @@ describe RenderConstraintsHelper do
23
24
  result = helper.render_filter_element('type', ['journal'], {:q=>'biz'})
24
25
  result.size.should == 1
25
26
  # I'm not certain how the ampersand gets in there. It's not important.
26
- result.first.should have_selector "a[href='/advanced_search?&q=biz']"
27
+ result.first.should have_selector "a[href='/catalog?&q=biz']"
27
28
  end
28
29
  end
29
30
 
@@ -35,11 +35,18 @@ describe "Blacklight::Configuration" do
35
35
  it "should have a hash of default rsolr query parameters" do
36
36
  @config.default_solr_params.should be_a_kind_of Hash
37
37
  end
38
+
38
39
  it "should have openstruct values for show and index parameters" do
39
40
  @config.show.should be_a_kind_of OpenStruct
40
41
  @config.index.should be_a_kind_of OpenStruct
41
42
  end
42
43
 
44
+ it "should introspect SolrDocument for sensible defaults for show + index" do
45
+ @config.show.html_title.should == 'id'
46
+ @config.show.heading.should == 'id'
47
+ @config.index.show_link.should == 'id'
48
+ end
49
+
43
50
  it "should have ordered hashes for field configuration" do
44
51
  @config.facet_fields.should be_a_kind_of ActiveSupport::OrderedHash
45
52
  @config.index_fields.should be_a_kind_of ActiveSupport::OrderedHash
@@ -472,6 +472,13 @@ describe 'Blacklight::SolrHelper' do
472
472
  (@solr_response, @document_list) = get_search_results(:q => @all_docs_query)
473
473
  end
474
474
 
475
+ it "should use the configured request handler " do
476
+ require 'ostruct'
477
+ blacklight_config.stub(:solr_request_handler => 'custom_request_handler')
478
+ self.should_receive(:find).with('custom_request_handler', anything).and_return(OpenStruct.new( :docs => [{}] ))
479
+ get_search_results(:q => @all_docs_query)
480
+ end
481
+
475
482
  it 'should have a @response.docs list of the same size as @document_list' do
476
483
  @solr_response.docs.length.should == @document_list.length
477
484
  end
@@ -700,6 +707,13 @@ describe 'Blacklight::SolrHelper' do
700
707
  }.should raise_error(Blacklight::Exceptions::InvalidSolrID)
701
708
  end
702
709
 
710
+ it "should use a provided document request handler " do
711
+ require 'ostruct'
712
+ blacklight_config.stub(:document_solr_request_handler => 'document')
713
+ self.should_receive(:find).with('document', anything).and_return(OpenStruct.new( :docs => [{}] ))
714
+ get_solr_response_for_doc_id(@doc_id)
715
+ end
716
+
703
717
  it "should have a non-nil result for a known id" do
704
718
  @document.should_not == nil
705
719
  end
@@ -716,6 +730,29 @@ describe 'Blacklight::SolrHelper' do
716
730
  end
717
731
  end
718
732
 
733
+ describe "solr_doc_params" do
734
+ it "should default to using the 'document' requestHandler" do
735
+ doc_params = solr_doc_params('asdfg')
736
+ doc_params[:qt].should == 'document'
737
+ end
738
+
739
+
740
+ describe "blacklight config's default_document_solr_parameters" do
741
+ def blacklight_config
742
+ config = Blacklight::Configuration.new
743
+ config.default_document_solr_params = { :qt => 'my_custom_handler', :asdf => '1234' }
744
+ config
745
+ end
746
+
747
+ it "should use parameters from the controller's default_document_solr_parameters" do
748
+ doc_params = solr_doc_params('asdfg')
749
+ doc_params[:qt].should == 'my_custom_handler'
750
+ doc_params[:asdf].should == '1234'
751
+ end
752
+ end
753
+
754
+ end
755
+
719
756
  describe "Get Document by custom unique id" do
720
757
  =begin
721
758
  # Can't test this properly without updating the "document" request handler in solr
@@ -880,17 +917,17 @@ describe 'Blacklight::SolrHelper' do
880
917
  @mock_response.stub(:docs => [])
881
918
  end
882
919
  it "should contruct a solr query based on the field and value pair" do
883
- self.should_receive(:find).with(hash_including(:q => "field_name:(value)")).and_return(@mock_response)
920
+ self.should_receive(:find).with(an_instance_of(String), hash_including(:q => "field_name:(value)")).and_return(@mock_response)
884
921
  get_solr_response_for_field_values('field_name', 'value')
885
922
  end
886
923
 
887
924
  it "should OR multiple values together" do
888
- self.should_receive(:find).with(hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
925
+ self.should_receive(:find).with(an_instance_of(String), hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
889
926
  get_solr_response_for_field_values('field_name', ['a', 'b'])
890
927
  end
891
928
 
892
929
  it "should escape crazy identifiers" do
893
- self.should_receive(:find).with(hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
930
+ self.should_receive(:find).with(an_instance_of(String), hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
894
931
  get_solr_response_for_field_values('field_name', 'h://"\'')
895
932
  end
896
933
  end
@@ -902,6 +939,9 @@ describe 'Blacklight::SolrHelper' do
902
939
  # TODO: maybe eventually check other types of solr requests
903
940
  # more like this
904
941
  # nearby on shelf
905
-
942
+ it "should raise a Blacklight exception if RSolr can't connect to the Solr instance" do
943
+ Blacklight.solr.stub!(:find).and_raise(Errno::ECONNREFUSED)
944
+ expect { find(:a => 123) }.to raise_exception(/Unable to connect to Solr instance/)
945
+ end
906
946
  end
907
947
 
@@ -52,7 +52,7 @@ describe "solr:marc:*" do
52
52
  java_cmd.should match "java -Xmx512m"
53
53
  java_cmd.should match /-jar .*\/SolrMarc\.jar/
54
54
  java_cmd.should match "#{Rails.root}/config/SolrMarc/config-test.properties dummy.mrc"
55
- java_cmd.should match "-Dsolr.hosturl=http://127.0.0.1:[0-9]{4}/solr"
55
+ java_cmd.should match "-Dsolr.hosturl=http://127.0.0.1:[0-9]{2,5}/solr"
56
56
  end
57
57
 
58
58
  end
@@ -4,48 +4,25 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
4
  describe "catalog/index" do
5
5
 
6
6
  before(:all) do
7
- @config ||= Blacklight::Configuration.from_legacy_configuration({
8
- :show => {
9
- :display_type => 'asdf'
10
- },
11
- :index_fields => {
12
- :field_names => [],
13
- :labels => {}
7
+ @config = Blacklight::Configuration.new.configure do |config|
8
+ config.default_solr_params = {
9
+ :fl => '*',
10
+ :rows => 10
14
11
  }
15
- })
16
-
17
- @mock_configuration_module = Module.new do
18
- # Just test against our default config for now.
19
- def blacklight_config
20
- @config ||= Blacklight::Config.new
21
- end
22
12
  end
23
13
 
24
- class AtomMockDocument
25
- include Blacklight::Solr::Document
26
- end
14
+ @params = { 'content_format' => 'marc', :f => { :format => ['Book'] }, :page => 2 }
27
15
 
28
- AtomMockDocument.field_semantics.merge!(
29
- :title => "title_display",
30
- :author => "author_display"
31
- )
32
- AtomMockDocument.extension_parameters[:marc_format_type] = :marc21
33
- AtomMockDocument.extension_parameters[:marc_source_field] = :marc_display
34
- AtomMockDocument.use_extension( Blacklight::Solr::Document::Marc) do |document|
35
- document.key?( :marc_display )
36
- end
37
-
38
- # Load sample responses from Solr to a sample request, to test against
39
- @data = YAML.load(File.open(File.dirname(__FILE__) +
40
- "/../../data/sample_docs.yml", "r:UTF-8"))
41
- @rsolr_response = RSolr::Ext::Response::Base.new(@data["solr_response"], nil, @data["params"])
42
- @params = @data["params"]
43
- @document_list = @data["document_list_mash"].collect do |d|
44
- AtomMockDocument.new(d)
45
- end
16
+ # run a solr query to get our data
17
+ c = CatalogController.new
18
+ c.blacklight_config = @config
19
+ @response, @document_list = c.get_search_results(@params)
20
+
21
+ # munge the solr response to match test expectations
22
+ @document_list[1] = SolrDocument.new(@document_list[1].to_mash.reject! { |k,v| k == "author_display" })
23
+ @document_list[5] = SolrDocument.new(@document_list[1].to_mash.reject! { |k,v| k == "marc_display" })
46
24
  end
47
25
  before(:each) do
48
-
49
26
  # Not sure what Assigns was doing here ... dhf
50
27
  # assigns[:response] = @rsolr_response
51
28
  # assigns[:document_list] = @document_list
@@ -53,8 +30,6 @@ describe "catalog/index" do
53
30
  # but okay.
54
31
 
55
32
  params.merge!( @params )
56
- @response = @rsolr_response
57
-
58
33
  view.stub!(:blacklight_config).and_return(@config)
59
34
  view.stub!(:search_field_options_for_select).and_return([])
60
35
 
@@ -64,7 +39,6 @@ describe "catalog/index" do
64
39
  render :template => 'catalog/index.atom'
65
40
  end
66
41
 
67
-
68
42
  # We need to use rexml to test certain things that have_tag wont' test
69
43
  # note that response is depricated rails 3, use "redered" instead.
70
44
  @response_xml = REXML::Document.new(rendered)
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: 3.3.2
4
+ version: 3.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,10 +13,11 @@ authors:
13
13
  - Vernon Chapman
14
14
  - Mark A. Matienzo
15
15
  - Dan Funk
16
+ - Naomi Dushay
16
17
  autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
- date: 2012-04-17 00:00:00.000000000 Z
20
+ date: 2012-04-24 00:00:00.000000000 Z
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: rails
@@ -194,11 +195,9 @@ dependencies:
194
195
  - - ! '>='
195
196
  - !ruby/object:Gem::Version
196
197
  version: 0.9.0
197
- description: Blacklight is a free and open source ruby-on-rails based discovery interface
198
- (a.k.a. “next-generation catalog”) especially optimized for heterogeneous collections.
199
- You can use it as a library catalog, as a front end for a digital repository, or
200
- as a single-search interface to aggregate digital content that would otherwise be
201
- siloed.
198
+ description: Blacklight is an open source Solr user interface discovery platform.
199
+ You can use Blacklight to enable searching and browsing of your collections. Blacklight
200
+ uses the Apache Solr search engine to search full text and/or metadata.
202
201
  email:
203
202
  - blacklight-development@googlegroups.com
204
203
  executables: []
@@ -477,7 +476,6 @@ files:
477
476
  - test_support/spec/rcov.opts
478
477
  - test_support/spec/spec.opts
479
478
  - test_support/spec/spec_helper.rb
480
- - test_support/spec/support/action_controller.rb
481
479
  - test_support/spec/support/assert_difference.rb
482
480
  - test_support/spec/support/include_text.rb
483
481
  - test_support/spec/views/catalog/_constraints_element.html.erb_spec.rb
@@ -501,7 +499,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
501
499
  version: '0'
502
500
  segments:
503
501
  - 0
504
- hash: 1253427252595743180
502
+ hash: 3883419086442595673
505
503
  required_rubygems_version: !ruby/object:Gem::Requirement
506
504
  none: false
507
505
  requirements:
@@ -510,11 +508,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
510
508
  version: '0'
511
509
  segments:
512
510
  - 0
513
- hash: 1253427252595743180
511
+ hash: 3883419086442595673
514
512
  requirements: []
515
513
  rubyforge_project: blacklight
516
514
  rubygems_version: 1.8.21
517
515
  signing_key:
518
516
  specification_version: 3
519
- summary: A next-generation Library Catalag for Universities
517
+ summary: Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr)
518
+ index.
520
519
  test_files: []
@@ -1,43 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- # Added based on http://www.arctickiwi.com/blog/upgrading-to-rspec-2-with-ruby-on-rails-3
3
- # God bless you Jonathon Horsman
4
- module ActionController
5
- class TestCase < ActiveSupport::TestCase
6
- module Behavior
7
- def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
8
- # Sanity check for required instance variables so we can give an
9
- # understandable error message.
10
- %w(@routes @controller @request @response).each do |iv_name|
11
- if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
12
- raise "#{iv_name} is nil: make sure you set it in your test's setup method."
13
- end
14
- end
15
-
16
- @request.recycle!
17
- @response.recycle!
18
- @controller.response_body = nil
19
- @controller.formats = nil
20
- @controller.params = nil
21
-
22
- @html_document = nil
23
- @request.env['REQUEST_METHOD'] = http_method
24
-
25
- parameters ||= {}
26
- @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters)
27
-
28
- @request.session = ActionController::TestSession.new(session) unless session.nil?
29
- @request.session["flash"] = @request.flash.update(flash || {})
30
- @request.session["flash"].sweep
31
-
32
- @controller.request = @request
33
- #@controller.params.merge!(parameters) # this is the offending line, which I removed
34
- build_request_uri(action, parameters)
35
- Base.class_eval { include Testing }
36
- @controller.process_with_new_base_test(@request, @response)
37
- @request.session.delete('flash') if @request.session['flash'].blank?
38
- @response
39
- end
40
- end
41
- end
42
- end
43
-