#ste -*- encoding : utf-8 -*-
# -*- coding: UTF-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'marc'
def exportable_record
"
01828cjm a2200409 a 4500
a4768316
SIRSI
sd fungnnmmned
020117p20011990xxuzz h d
Music for horn
[sound recording] /
Brahms, Beethoven, von Krufft.
[United States] :
Harmonia Mundi USA,
p2001.
Greer, Lowell.
Lubin, Steven.
Chase, Stephanie,
1957-
Brahms, Johannes,
1833-1897.
Trios,
piano, violin, horn,
op. 40,
E? major.
Beethoven, Ludwig van,
1770-1827.
Sonatas,
horn, piano,
op. 17,
F major.
Krufft, Nikolaus von,
1779-1818.
Sonata,
horn, piano,
F major.
"
end
describe BlacklightHelper do
include ERB::Util
include BlacklightHelper
include Devise::TestHelpers
def blacklight_config
@config ||= Blacklight::Configuration.new.configure do |config|
config.show.html_title = "title_display"
config.show.heading = "title_display"
config.show.display_type = 'format'
config.index.show_link = 'title_display'
config.index.record_display_type = 'format'
end
#CatalogController.blacklight_config
#@config ||= {:show => {:html_title => 'title_display', :heading => 'title_display', :display_type => 'format'}, :index => { :show_link => 'title_display', :record_display_type => 'format' } }
end
describe "#application_name", :test => true do
it "should use the Rails application config application_name if available" do
Rails.application.config.stub(:application_name => 'asdf')
Rails.application.config.should_receive(:respond_to?).with(:application_name).and_return(true)
application_name.should == 'asdf'
end
it "should default to 'Blacklight'" do
application_name.should == "Blacklight"
end
end
describe "link_back_to_catalog" do
before(:all) do
@query_params = {:q => "query", :f => "facets", :per_page => "10", :page => "2", :controller=>'catalog'}
@bookmarks_query_params = { :page => "2", :controller=>'bookmarks'}
end
it "should build a link tag to catalog using session[:search] for query params" do
session[:search] = @query_params
tag = link_back_to_catalog
tag.should =~ /q=query/
tag.should =~ /f=facets/
tag.should =~ /per_page=10/
tag.should =~ /page=2/
end
it "should build a link tag to bookmarks using session[:search] for query params" do
session[:search] = @bookmarks_query_params
tag = link_back_to_catalog
tag.should =~ /Back to Bookmarks/
tag.should =~ /\/bookmarks/
tag.should =~ /page=2/
end
end
describe "link_to_query" do
it "should build a link tag to catalog using query string (no other params)" do
query = "brilliant"
self.should_receive(:params).and_return({})
tag = link_to_query(query)
tag.should =~ /q=#{query}/
tag.should =~ />#{query}<\/a>/
end
it "should build a link tag to catalog using query string and other existing params" do
query = "wonderful"
self.should_receive(:params).and_return({:qt => "title_search", :per_page => "50"})
tag = link_to_query(query)
tag.should =~ /qt=title_search/
tag.should =~ /per_page=50/
end
it "should ignore existing :page param" do
query = "yes"
self.should_receive(:params).and_return({:page => "2", :qt => "author_search"})
tag = link_to_query(query)
tag.should =~ /qt=author_search/
tag.should_not =~ /page/
end
it "should be html_safe" do
query = "brilliant"
self.should_receive(:params).and_return({:page => "2", :qt => "author_search"})
tag = link_to_query(query)
tag.html_safe?.should == true
end
end
describe "params_for_search" do
def params
{ 'default' => 'params'}
end
it "should default to using the controller's params" do
result = params_for_search
result.should == params
params.object_id.should_not == result.object_id
end
it "should let you pass in params to use" do
source_params = { :q => 'query'}
result = params_for_search(:params => source_params )
source_params.should == result
source_params.object_id.should_not == result.object_id
end
it "should not return blacklisted elements" do
source_params = { :action => 'action', :controller => 'controller', :commit => 'commit'}
result = params_for_search(:params => source_params )
result.keys.should_not include(:action, :controller, :commit)
end
it "should adjust the current page if the per_page changes" do
source_params = { :per_page => 20, :page => 5}
result = params_for_search(:params => source_params, :per_page => 100)
result[:page].should == 1
end
it "should not adjust the current page if the per_page is the same as it always was" do
source_params = { :per_page => 20, :page => 5}
result = params_for_search(:params => source_params, :per_page => 20)
result[:page].should == 5
end
it "should adjust the current page if the sort changes" do
source_params = { :sort => 'field_a', :page => 5}
result = params_for_search(:params => source_params, :sort => 'field_b')
result[:page].should == 1
end
it "should not adjust the current page if the sort is the same as it always was" do
source_params = { :sort => 'field_a', :page => 5}
result = params_for_search(:params => source_params, :sort => 'field_a')
result[:page].should == 5
end
describe "omit keys parameter" do
it "should omit keys by key name" do
source_params = { :a => 1, :b => 2, :c => 3}
result = params_for_search(:params => source_params, :omit_keys => [:a, :b] )
result.keys.should_not include(:a, :b)
result[:c].should == 3
end
it "should remove keys if a key/value pair was passed and no values are left for that key" do
source_params = { :f => ['a']}
result = params_for_search(:params => source_params, :omit_keys => [{:f => 'a' }])
result.keys.should_not include(:f)
end
it "should only remove keys when a key/value pair is based that are in that pair" do
source_params = { :f => ['a', 'b']}
result = params_for_search(:params => source_params, :omit_keys => [{:f => 'a' }])
result[:f].should_not include('a')
result[:f].should include('b')
end
end
end
describe "search_as_hidden_fields" do
def params
{: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"}
end
describe "for default arguments" do
it "should default to omitting :page" do
search_as_hidden_fields.should_not have_selector("input[name='page']")
end
end
end
describe "render body class" do
it "should include a serialization of the current controller name" do
@controller = mock("controller")
@controller.should_receive(:controller_name).any_number_of_times.and_return("123456")
@controller.should_receive(:action_name).any_number_of_times.and_return("abcdef")
render_body_class.split(' ').should include('blacklight-123456')
end
it "should include a serialization of the current action name" do
@controller = mock("controller")
@controller.should_receive(:controller_name).any_number_of_times.and_return("123456")
@controller.should_receive(:action_name).any_number_of_times.and_return("abcdef")
render_body_class.split(' ').should include('blacklight-123456-abcdef')
end
end
describe "document_heading" do
it "should consist of the show heading field when available" do
@document = SolrDocument.new('title_display' => "A Fake Document")
document_heading.should == "A Fake Document"
end
it "should fallback on the document id if no title is available" do
@document = SolrDocument.new(:id => '123456')
document_heading.should == '123456'
end
end
describe "render_document_heading" do
it "should consist of #document_heading wrapped in a