blacklight 3.1.2 → 3.2.0pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +5 -2
  2. data/README.md +7 -2
  3. data/VERSION +1 -1
  4. data/app/assets/images/favicon.ico +0 -0
  5. data/app/assets/javascripts/blacklight/blacklight.js +23 -1
  6. data/app/assets/stylesheets/blacklight/_catalog.css.scss +369 -0
  7. data/app/assets/stylesheets/blacklight/_facets.css.scss +117 -0
  8. data/app/assets/stylesheets/blacklight/_folder.css.scss +38 -0
  9. data/app/assets/stylesheets/blacklight/_formatting.css.scss +164 -0
  10. data/app/assets/stylesheets/blacklight/_header.css.scss +36 -0
  11. data/app/assets/stylesheets/blacklight/_layout.css.scss +79 -0
  12. data/app/assets/stylesheets/blacklight/_print.css.scss +54 -0
  13. data/app/assets/stylesheets/blacklight/_search_history.css.scss +44 -0
  14. data/app/assets/stylesheets/blacklight/_susy_framework.css.scss +228 -0
  15. data/app/assets/stylesheets/blacklight/blacklight.css.scss +27 -0
  16. data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +48 -0
  17. data/app/controllers/bookmarks_controller.rb +2 -1
  18. data/app/controllers/folder_controller.rb +4 -0
  19. data/app/controllers/saved_searches_controller.rb +4 -0
  20. data/app/controllers/search_history_controller.rb +4 -0
  21. data/app/helpers/blacklight/blacklight_helper_behavior.rb +64 -104
  22. data/app/helpers/blacklight/catalog_helper_behavior.rb +4 -4
  23. data/app/helpers/blacklight/facets_helper_behavior.rb +52 -5
  24. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +14 -59
  25. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +56 -0
  26. data/app/helpers/search_history_constraints_helper.rb +3 -0
  27. data/app/models/record_mailer.rb +1 -2
  28. data/app/views/_flash_msg.html.erb +4 -5
  29. data/app/views/_user_util_links.html.erb +3 -1
  30. data/app/views/bookmarks/index.html.erb +2 -2
  31. data/app/views/catalog/_bookmark_control.html.erb +6 -6
  32. data/app/views/catalog/_facet_layout.html.erb +4 -0
  33. data/app/views/catalog/_facet_limit.html.erb +20 -33
  34. data/app/views/catalog/_facets.html.erb +1 -5
  35. data/app/views/catalog/_folder_control.html.erb +5 -5
  36. data/app/views/catalog/_index_default.html.erb +1 -1
  37. data/app/views/catalog/_search_form.html.erb +4 -3
  38. data/app/views/catalog/_show_default.html.erb +1 -1
  39. data/app/views/catalog/_show_tools.html.erb +6 -6
  40. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  41. data/app/views/catalog/index.atom.builder +2 -2
  42. data/app/views/catalog/index.rss.builder +1 -1
  43. data/app/views/catalog/opensearch.xml.builder +10 -0
  44. data/app/views/catalog/show.html.erb +1 -1
  45. data/app/views/folder/_tools.html.erb +4 -4
  46. data/app/views/layouts/blacklight.html.erb +25 -37
  47. data/app/views/record_mailer/email_record.text.erb +1 -1
  48. data/app/views/record_mailer/sms_record.text.erb +2 -2
  49. data/app/views/search_history/index.html.erb +1 -1
  50. data/blacklight.gemspec +11 -9
  51. data/lib/{generators/blacklight/templates/SolrMarc.jar → SolrMarc.jar} +0 -0
  52. data/lib/blacklight.rb +5 -3
  53. data/lib/blacklight/catalog.rb +3 -4
  54. data/lib/blacklight/configurable.rb +54 -39
  55. data/lib/blacklight/configuration.rb +126 -0
  56. data/lib/blacklight/configuration/fields.rb +142 -0
  57. data/lib/blacklight/configuration/search_field.rb +12 -0
  58. data/lib/blacklight/configuration/solr_field.rb +12 -0
  59. data/lib/blacklight/configuration/sort_field.rb +17 -0
  60. data/lib/blacklight/controller.rb +16 -14
  61. data/lib/blacklight/engine.rb +1 -1
  62. data/lib/blacklight/global_configurable.rb +46 -0
  63. data/lib/blacklight/search_fields.rb +21 -54
  64. data/lib/blacklight/solr/document.rb +13 -3
  65. data/lib/blacklight/solr_helper.rb +88 -52
  66. data/lib/blacklight/utils.rb +18 -0
  67. data/lib/generators/blacklight/assets_generator.rb +14 -20
  68. data/lib/generators/blacklight/blacklight_generator.rb +14 -6
  69. data/lib/generators/blacklight/jetty_generator.rb +1 -1
  70. data/lib/generators/blacklight/templates/assets/standard.css.scss +51 -0
  71. data/lib/generators/blacklight/templates/catalog_controller.rb +148 -0
  72. data/lib/generators/blacklight/templates/config/blacklight_config.rb +2 -239
  73. data/lib/generators/blacklight/templates/config/sass.rb +5 -0
  74. data/lib/generators/blacklight/templates/solr_conf/schema.xml +514 -164
  75. data/lib/generators/blacklight/templates/solr_conf/solrconfig.xml +1591 -323
  76. data/lib/generators/blacklight/templates/solr_document.rb +2 -0
  77. data/lib/railties/all_tests.rake +36 -3
  78. data/lib/railties/blacklight_cucumber.rake +6 -4
  79. data/lib/railties/blacklight_rspec.rake +5 -4
  80. data/test_support/bin/run-tests.sh +2 -13
  81. data/test_support/bin/test.sh +30 -23
  82. data/test_support/features/did_you_mean.feature +14 -13
  83. data/test_support/features/step_definitions/saved_searches_steps.rb +1 -1
  84. data/test_support/features/step_definitions/search_steps.rb +4 -4
  85. data/test_support/spec/controllers/application_controller_spec.rb +3 -13
  86. data/test_support/spec/controllers/catalog_controller_spec.rb +102 -24
  87. data/test_support/spec/controllers/folder_controller_spec.rb +7 -1
  88. data/test_support/spec/helpers/blacklight_helper_spec.rb +45 -34
  89. data/test_support/spec/helpers/facets_helper_spec.rb +68 -0
  90. data/test_support/spec/helpers/html_head_helper_spec.rb +37 -0
  91. data/test_support/spec/helpers/{render_constraints_helper_spec.rb → search_history_constraints_helper_spec.rb} +26 -7
  92. data/test_support/spec/lib/blacklight_configurable_spec.rb +92 -0
  93. data/test_support/spec/lib/blacklight_configuration_spec.rb +295 -0
  94. data/test_support/spec/lib/{configurable_spec.rb → global_configurable_spec.rb} +2 -2
  95. data/test_support/spec/lib/search_fields_spec.rb +26 -29
  96. data/test_support/spec/{helpers → lib}/solr_helper_spec.rb +268 -287
  97. data/test_support/spec/lib/tasks/solr_marc_task_spec.rb +1 -1
  98. data/test_support/spec/lib/utils_spec.rb +58 -0
  99. data/test_support/spec/models/solr_docment_spec.rb +4 -8
  100. data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +27 -170
  101. data/test_support/spec/views/catalog/_index_default.erb_spec.rb +38 -20
  102. data/test_support/spec/views/catalog/_show_default.erb_spec.rb +38 -19
  103. data/test_support/spec/views/catalog/index.atom.builder_spec.rb +19 -1
  104. metadata +148 -145
  105. data/app/assets/stylesheets/blacklight/blacklight.css +0 -493
  106. data/app/assets/stylesheets/yui.css +0 -31
  107. data/app/views/catalog/opensearch.xml.erb +0 -11
  108. data/doc/Atom-Responses.md +0 -90
  109. data/doc/CUSTOMIZING.md +0 -121
  110. data/doc/Extending-blacklight-with-the-document-extension-framework.md +0 -1
  111. data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -131
  112. data/doc/Features.md +0 -147
  113. data/doc/Integration-with-Rails-Footnotes.md +0 -20
  114. data/doc/Pagination.md +0 -38
  115. data/doc/Quickstart.md +0 -97
  116. data/doc/Upgrading-Guide.md +0 -98
  117. data/doc/User-Authentication.md +0 -54
  118. data/doc/Using-a-custom-solr-uniquekey-field.md +0 -36
  119. data/lib/blacklight/comma_link_renderer.rb +0 -28
  120. data/lib/railties/jetty_solr_server.rb +0 -108
  121. data/test_support/spec/views/catalog/show.html.erb_spec.rb +0 -101
@@ -1,10 +1,10 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
- describe Blacklight::Configurable do
4
+ describe Blacklight::GlobalConfigurable do
5
5
 
6
6
  class TestConfig
7
- extend Blacklight::Configurable
7
+ extend Blacklight::GlobalConfigurable
8
8
  end
9
9
 
10
10
  before(:each) do
@@ -5,46 +5,45 @@ describe Blacklight::SearchFields do
5
5
 
6
6
  class MockConfig
7
7
  include Blacklight::SearchFields
8
+ end
8
9
 
9
- # add in a #config method that includes search field config
10
- # that will be used by SearchFields
11
- def config
12
- @config ||= {:search_fields => [ {:display_label => 'All Fields', :key => "all_fields"},
10
+ before(:all) do
11
+ @config = Blacklight::Configuration.from_legacy_configuration({:search_fields => [ {:label => 'All Fields', :key => "all_fields"},
13
12
  {:key => 'title', :qt => 'title_search'},
14
13
  {:key => 'author', :qt => 'author_search'},
15
14
  {:key => 'subject', :qt=> 'subject_search'},
16
15
  ['Legacy Config', 'legacy_qt'],
17
16
  {:key => "no_display", :qt=>"something", :include_in_simple_select => false}
18
17
  ],
19
- :default_qt => "search"
20
- }
21
- end
22
-
18
+ :default_solr_params => { :qt => "search" }
19
+ })
23
20
  end
24
21
 
25
- before(:all) do
22
+ before(:each) do
26
23
  @search_field_obj = MockConfig.new
24
+ @search_field_obj.stub!(:blacklight_config).and_return(@config)
27
25
  end
28
26
 
29
27
  it 'should convert legacy Array config to Hash properly' do
30
28
  hash = @search_field_obj.search_field_def_for_key('legacy_qt')
31
29
 
32
- hash.should be_kind_of(Hash)
33
- hash[:key].should == hash[:qt]
34
- hash[:display_label].should == 'Legacy Config'
30
+ hash.should be_kind_of(Blacklight::Configuration::SearchField)
31
+ hash.key.should == hash.qt
32
+ hash.label.should == 'Legacy Config'
35
33
  end
36
34
 
37
- it "should return search field list with calculated :display_label when needed" do
35
+ it "should return search field list with calculated :label when needed" do
38
36
  @search_field_obj.search_field_list.each do |hash|
39
- hash[:display_label].should_not be_blank
37
+ hash.label.should_not be_blank
40
38
  end
41
39
  end
42
40
 
43
41
  it "should fill in default qt where needed" do
44
- @search_field_obj.search_field_def_for_key("all_fields")[:qt].should == Blacklight.config[:default_qt]
42
+ @search_field_obj.search_field_def_for_key("all_fields").qt == @config.default_solr_params[:qt]
45
43
  end
46
44
 
47
45
  it "should return proper options_for_select arguments" do
46
+
48
47
  select_arguments = @search_field_obj.search_field_options_for_select
49
48
 
50
49
  select_arguments.each_index do |index|
@@ -52,8 +51,8 @@ describe Blacklight::SearchFields do
52
51
  config_hash = @search_field_obj.search_field_list[index]
53
52
 
54
53
  argument.length.should == 2
55
- argument[0].should == config_hash[:display_label]
56
- argument[1].should == config_hash[:key]
54
+ argument[0].should == config_hash.label
55
+ argument[1].should == config_hash.key
57
56
  end
58
57
  end
59
58
 
@@ -66,10 +65,10 @@ describe Blacklight::SearchFields do
66
65
 
67
66
 
68
67
  it "should lookup field definitions by key" do
69
- @search_field_obj.search_field_def_for_key("title")[:key].should == "title"
68
+ @search_field_obj.search_field_def_for_key("title").key.should == "title"
70
69
  end
71
70
 
72
- it "should find display_label by key" do
71
+ it "should find label by key" do
73
72
  @search_field_obj.label_for_search_field("title").should == "Title"
74
73
  end
75
74
 
@@ -80,26 +79,24 @@ describe Blacklight::SearchFields do
80
79
  describe "for unspecified :key" do
81
80
  before do
82
81
  @bad_config = MockConfig.new
83
- @bad_config.config[:search_fields] = [
84
- {:display_label => 'All Fields', :qt => "all_fields"},
85
- {:key => 'title', :qt => 'title_search'}
86
- ]
87
82
  end
88
83
  it "should raise exception on #search_field_list" do
89
- lambda {@bad_config.search_field_list}.should raise_error
84
+ lambda { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.from_legacy_configuration({:search_fields => [
85
+ {:label => 'All Fields', :qt => "all_fields"},
86
+ {:key => 'title', :qt => 'title_search'}
87
+ ]})) }.should raise_error
90
88
  end
91
89
  end
92
90
 
93
91
  describe "for duplicate keys" do
94
92
  before do
95
93
  @bad_config = MockConfig.new
96
- @bad_config.config[:search_fields] = [
97
- {:display_label => 'All Fields', :key => "my_key"},
98
- {:key => 'title', :key => 'my_key'}
99
- ]
100
94
  end
101
95
  it "should raise on #search_field_list" do
102
- lambda {@bad_config.search_field_list}.should raise_error
96
+ lambda { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.from_legacy_configuration({:search_fields => [
97
+ {:label => 'All Fields', :qt => "my_key"},
98
+ {:key => 'title', :qt => 'my_key'}
99
+ ]})) }.should raise_error
103
100
  end
104
101
  end
105
102
 
@@ -2,22 +2,7 @@
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  require 'marc'
4
4
 
5
- # Because SolrHelper is a controller layer mixin,
6
- # it depends on the methods provided by AtionController::Base
7
- # currently, the only method that is used is #params
8
- class MockSolrHelperContainer
9
5
 
10
- include Blacklight::SolrHelper
11
- attr_accessor :params
12
- attr_accessor :response
13
-
14
- # SolrHelper expects a method called #params,
15
- # within the class that's mixing it in
16
- def params
17
- @params ||= {}
18
- end
19
-
20
- end
21
6
 
22
7
 
23
8
  =begin
@@ -31,11 +16,23 @@ end
31
16
  =end
32
17
  describe 'Blacklight::SolrHelper' do
33
18
 
34
- before(:all) do
35
- @solr_helper = MockSolrHelperContainer.new
36
- @solr_url = Blacklight.solr_config[:url]
19
+ # SolrHelper is a controller layer mixin, which depends
20
+ # on being mixed into a class which has #params (from Rails)
21
+ # and #blacklight_config
22
+ def params
23
+ {}
37
24
  end
38
25
 
26
+ def blacklight_config
27
+ @config ||= CatalogController.blacklight_config
28
+ end
29
+
30
+ def blacklight_config=(config)
31
+ @config = config
32
+ end
33
+
34
+ include Blacklight::SolrHelper
35
+
39
36
  before(:each) do
40
37
  @all_docs_query = ''
41
38
  @no_docs_query = 'zzzzzzzzzzzz'
@@ -45,62 +42,46 @@ describe 'Blacklight::SolrHelper' do
45
42
  @single_facet = {:format=>'Book'}
46
43
  @multi_facets = {:format=>'Book', :language_facet=>'Tibetan'}
47
44
  @bad_facet = {:format=>'666'}
48
- @subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"per_page"=>"10", :"q"=>"wome"}
45
+ @subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
49
46
  end
50
47
 
51
- # SPECS FOR blacklight.rb contents
52
- describe "blacklight.rb" do
53
- describe "solr.yml and/or initializers" do
54
-
55
- it "should contain a solr_url" do
56
- Blacklight.solr_config[:url].should_not == nil
57
- end
58
-
59
- it "should contain some display fields" do
60
- Blacklight.config[:show].should_not == nil
61
- end
62
-
63
- end
64
- end
48
+
65
49
 
66
50
  # SPECS for actual search parameter generation
67
51
  describe "solr_search_params" do
68
52
  it "allows customization of solr_search_params_logic" do
69
53
  # Normally you'd include a new module into (eg) your CatalogController
70
- # but a sub-class defininig it directly is simpler for test.
71
- class CustomizableHelper < MockSolrHelperContainer
72
- def add_foo_to_solr_params(solr_params, user_params)
73
- solr_params[:foo] = "TESTING"
74
- end
75
- end
54
+ # but a sub-class defininig it directly is simpler for test.
55
+ def add_foo_to_solr_params(solr_params, user_params)
56
+ solr_params[:foo] = "TESTING"
57
+ end
58
+
76
59
 
77
- CustomizableHelper.solr_search_params_logic += [:add_foo_to_solr_params]
78
-
60
+ self.solr_search_params_logic += [:add_foo_to_solr_params]
79
61
 
80
- obj = CustomizableHelper.new
81
- params = obj.solr_search_params
82
62
 
83
- params[:foo].should == "TESTING"
63
+ self.solr_search_params[:foo].should == "TESTING"
84
64
  end
85
65
 
86
66
 
87
67
  describe 'for an entirely empty search' do
68
+ def params
69
+ {}
70
+ end
88
71
  before do
89
- @produced_params = @solr_helper.solr_search_params
72
+ @produced_params = self.solr_search_params
90
73
  end
91
74
  it 'should not have a q param' do
92
75
  @produced_params[:q].should be_nil
93
76
  @produced_params["spellcheck.q"].should be_nil
94
77
  end
95
- it 'should have default per_page' do
96
- @produced_params[:per_page].should == 10
78
+ it 'should have default rows' do
79
+ @produced_params[:rows].should == 10
97
80
  end
98
81
  it 'should have default facet fields' do
99
- @produced_params[:"facet.field"].should == Blacklight.config[:default_solr_params][:"facet.field"]
100
- end
101
- it 'should not use the exact facet array from config defaults' do
102
- @produced_params[:"facet.field"].should_not be_equal(Blacklight.config[:facet][:field_names])
82
+ @produced_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
103
83
  end
84
+
104
85
  it "should have default qt" do
105
86
  @produced_params[:qt].should == "search"
106
87
  end
@@ -111,21 +92,17 @@ describe 'Blacklight::SolrHelper' do
111
92
  end
112
93
 
113
94
 
114
- describe "for an empty string search" do
115
- it "should return empty string q in solr parameters" do
116
- params = @solr_helper.solr_search_params(:q => "")
117
- params[:q].should == ""
118
- params["spellcheck.q"].should == ""
95
+ describe "for an empty string search" do
96
+ it "should return empty string q in solr parameters" do
97
+ solr_params = solr_search_params(:q => "")
98
+ solr_params[:q].should == ""
99
+ solr_params["spellcheck.q"].should == ""
119
100
  end
120
101
  end
121
102
 
122
- describe "for request params also passed in as argument" do
123
- before do
124
- @req_params = HashWithIndifferentAccess.new({:q => "some query"})
125
- params = @req_params
126
- end
127
- it "should only have one 'q' key, as symbol" do
128
- solr_params = @solr_helper.solr_search_params( @req_params )
103
+ describe "for request params also passed in as argument" do
104
+ it "should only have one 'q' key, as symbol" do
105
+ solr_params = solr_search_params( :q => "some query" )
129
106
  solr_params.keys.should include(:q)
130
107
  solr_params.keys.should_not include("q")
131
108
  end
@@ -135,27 +112,27 @@ describe 'Blacklight::SolrHelper' do
135
112
  describe "for one facet, no query" do
136
113
  it "should have proper solr parameters" do
137
114
 
138
- params = @solr_helper.solr_search_params(:f => @single_facet)
115
+ solr_params = solr_search_params(:f => @single_facet)
139
116
 
140
- params[:q].should be_blank
141
- params["spellcheck.q"].should be_blank
142
- params[:"facet.field"].should == Blacklight.config[:default_solr_params][:"facet.field"]
117
+ solr_params[:q].should be_blank
118
+ solr_params["spellcheck.q"].should be_blank
119
+ solr_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
143
120
 
144
121
  @single_facet.each_value do |value|
145
- params[:fq].should include("{!raw f=#{@single_facet.keys[0]}}#{value}")
122
+ solr_params[:fq].should include("{!raw f=#{@single_facet.keys[0]}}#{value}")
146
123
  end
147
124
  end
148
125
  end
149
126
 
150
127
  describe "with Multi Facets, No Query" do
151
128
  it 'should have fq set properly' do
152
- params = @solr_helper.solr_search_params(:f => @multi_facets)
129
+ solr_params = solr_search_params(:f => @multi_facets)
153
130
 
154
131
  @multi_facets.each_pair do |facet_field, value_list|
155
132
  value_list ||= []
156
133
  value_list = [value_list] unless value_list.respond_to? :each
157
134
  value_list.each do |value|
158
- params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
135
+ solr_params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
159
136
  end
160
137
  end
161
138
 
@@ -164,22 +141,48 @@ describe 'Blacklight::SolrHelper' do
164
141
 
165
142
  describe "with Multi Facets, Multi Word Query" do
166
143
  it 'should have fq and q set properly' do
167
- params = @solr_helper.solr_search_params(:q => @mult_word_query, :f => @multi_facets)
144
+ solr_params = solr_search_params(:q => @mult_word_query, :f => @multi_facets)
168
145
 
169
146
  @multi_facets.each_pair do |facet_field, value_list|
170
147
  value_list ||= []
171
148
  value_list = [value_list] unless value_list.respond_to? :each
172
149
  value_list.each do |value|
173
- params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
150
+ solr_params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
174
151
  end
175
152
  end
176
- params[:q].should == @mult_word_query
153
+ solr_params[:q].should == @mult_word_query
154
+ end
155
+ end
156
+
157
+ describe "facet_value_to_fq_string", :focus => true do
158
+ it "should use the raw handler for strings" do
159
+ facet_value_to_fq_string("facet_name", "my value").should == "{!raw f=facet_name}my value"
160
+ end
161
+
162
+ it "should pass integers through" do
163
+ facet_value_to_fq_string("facet_name", 1).should == "facet_name:1"
164
+ end
165
+
166
+ it "should pass integer-like strings through" do
167
+ facet_value_to_fq_string("facet_name", "1").should == "facet_name:1"
168
+ end
169
+
170
+ it "should pass floats through" do
171
+ facet_value_to_fq_string("facet_name", 1.11).should == "facet_name:1.11"
172
+ end
173
+
174
+ it "should pass floats through" do
175
+ facet_value_to_fq_string("facet_name", "1.11").should == "facet_name:1.11"
176
+ end
177
+
178
+ it "should handle range requests" do
179
+ facet_value_to_fq_string("facet_name", 1..5).should == "facet_name:[1 TO 5]"
177
180
  end
178
181
  end
179
182
 
180
183
  describe "solr parameters for a field search from config (subject)" do
181
184
  before do
182
- @solr_params = @solr_helper.solr_search_params( @subject_search_params )
185
+ @solr_params = solr_search_params( @subject_search_params )
183
186
  end
184
187
  it "should look up qt from field definition" do
185
188
  @solr_params[:qt].should == "search"
@@ -203,13 +206,13 @@ describe 'Blacklight::SolrHelper' do
203
206
  @solr_params["spellcheck.q"].should == "wome"
204
207
  end
205
208
  it "should include facet.field from default_solr_params" do
206
- @solr_params[:"facet.field"].should == Blacklight.config[:default_solr_params][:"facet.field"]
209
+ @solr_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
207
210
  end
208
211
  it "should include spellcheck.dictionary from field def solr_parameters" do
209
212
  @solr_params[:"spellcheck.dictionary"].should == "subject"
210
213
  end
211
214
  it "should add on :solr_local_parameters using Solr LocalParams style" do
212
- params = @solr_helper.solr_search_params( @subject_search_params )
215
+ params = solr_search_params( @subject_search_params )
213
216
 
214
217
  #q == "{!pf=$subject_pf $qf=subject_qf} wome", make sure
215
218
  #the LocalParams are really there
@@ -222,45 +225,41 @@ describe 'Blacklight::SolrHelper' do
222
225
 
223
226
  describe "overriding of qt parameter" do
224
227
  it "should return the correct overriden parameter" do
225
- @solr_helper.params[:qt] = "overriden"
226
- @solr_helper.solr_search_params[:qt].should == "overriden"
227
- @solr_helper.params[:qt] = nil
228
+ def params
229
+ super.merge(:qt => "overridden")
230
+ end
231
+
232
+ solr_search_params[:qt].should == "overridden"
228
233
  end
229
234
  end
230
235
 
231
236
  describe "with a complex parameter environment" do
232
- before do
233
- # Add a custom search field def in so we can test it
234
- Blacklight.config[:search_fields] << {:display_label => "Test", :key=>"test_field", :solr_parameters => {:qf => "fieldOne^2.3 fieldTwo fieldThree^0.4", :pf => "", :spellcheck => 'false', :per_page => "55", :sort => "request_params_sort"}}
235
- #re-memoize
236
- Blacklight.search_field_list(:reload)
237
-
238
- # Add some params
239
- @solr_helper_with_params = MockSolrHelperContainer.new
240
- @solr_helper_with_params.params = {:search_field => "test_field", :q => "test query", "facet.field" => "extra_facet"}
241
- end
242
- after do
243
- # restore search field list to how it was.
244
- Blacklight.config[:search_fields].delete_if {|hash| hash[:key] == "test_field"}
245
- #re-memoize
246
- Blacklight.search_field_list(:reload)
247
- end
248
-
237
+ def blacklight_config
238
+ config = Blacklight::Configuration.new
239
+ config.add_search_field("test_field",
240
+ :display_label => "Test",
241
+ :key=>"test_field",
242
+ :solr_parameters => {:qf => "fieldOne^2.3 fieldTwo fieldThree^0.4", :pf => "", :spellcheck => 'false', :rows => "55", :sort => "request_params_sort" }
243
+ )
244
+ return config
245
+ end
246
+ def params
247
+ {:search_field => "test_field", :q => "test query", "facet.field" => "extra_facet"}
248
+ end
249
+
249
250
  it "should merge parameters from search_field definition" do
250
- params = @solr_helper_with_params.solr_search_params
251
-
252
- params[:qf].should == "fieldOne^2.3 fieldTwo fieldThree^0.4"
253
- params[:spellcheck].should == 'false'
251
+ solr_params = solr_search_params
252
+
253
+ solr_params[:qf].should == "fieldOne^2.3 fieldTwo fieldThree^0.4"
254
+ solr_params[:spellcheck].should == 'false'
254
255
  end
255
256
  it "should merge empty string parameters from search_field definition" do
256
- params = @solr_helper_with_params.solr_search_params
257
- params[:pf].should == ""
257
+ solr_search_params[:pf].should == ""
258
258
  end
259
259
 
260
260
  describe "should respect proper precedence of settings, " do
261
261
  before do
262
- @produced_params = @solr_helper_with_params.solr_search_params().merge(:sort => "extra_params_sort")
263
- 1+1
262
+ @produced_params = solr_search_params
264
263
  end
265
264
 
266
265
 
@@ -269,11 +268,11 @@ describe 'Blacklight::SolrHelper' do
269
268
  end
270
269
 
271
270
  it "should fall through to BL general defaults for qt not otherwise specified " do
272
- @produced_params[:qt].should == Blacklight.config[:default_solr_params][:qt]
271
+ @produced_params[:qt].should == blacklight_config[:default_solr_params][:qt]
273
272
  end
274
273
 
275
- it "should take per_page from search field definition where specified" do
276
- @produced_params[:per_page].should == "55"
274
+ it "should take rows from search field definition where specified" do
275
+ @produced_params[:rows].should == "55"
277
276
  end
278
277
 
279
278
  it "should take q from request params" do
@@ -284,67 +283,58 @@ describe 'Blacklight::SolrHelper' do
284
283
  @produced_params[:"facet.field"].should include("extra_facet")
285
284
  end
286
285
 
287
- it "should Overwrite request params sort with extra_params sort" do
288
- @produced_params[:sort].should == "extra_params_sort"
289
- end
290
-
291
286
  end
292
287
  end
293
288
 
294
289
  describe "sorting" do
295
- it "should send the default sort parameter to solr" do
296
- test_sort_field = ['test', 'solr_test_field asc']
297
- Blacklight.config[:sort_fields].unshift(test_sort_field)
298
-
299
- produced_params = @solr_helper.solr_search_params
300
- produced_params[:sort].should == 'solr_test_field asc'
301
-
302
- Blacklight.config[:sort_fields].delete(test_sort_field)
290
+
291
+ it "should send the default sort parameter to solr" do
292
+ solr_search_params[:sort].should == 'score desc, pub_date_sort desc, title_sort asc'
303
293
  end
304
294
 
305
295
  it "should not send a sort parameter to solr if the sort value is blank" do
306
- test_sort_field = ['test', nil]
307
- Blacklight.config[:sort_fields].unshift(test_sort_field)
296
+ def blacklight_config
297
+ config = Blacklight::Configuration.new
298
+ config.add_sort_field('', :label => 'test')
299
+ return config
300
+ end
308
301
 
309
- produced_params = @solr_helper.solr_search_params
302
+ produced_params = solr_search_params
310
303
  produced_params.should_not have_key(:sort)
311
-
312
- Blacklight.config[:sort_fields].delete(test_sort_field)
313
304
  end
314
305
 
315
306
  it "should pass through user sort parameters" do
316
- produced_params = @solr_helper.solr_search_params :sort => 'solr_test_field desc'
307
+ produced_params = solr_search_params( :sort => 'solr_test_field desc' )
317
308
  produced_params[:sort].should == 'solr_test_field desc'
318
309
  end
319
310
  end
320
311
 
321
312
  describe "for :solr_local_parameters config" do
322
- before do
323
- # Hack to test with our own custom config specified here
324
- @orig_blacklight = Blacklight
325
- Object.instance_eval{ remove_const :Blacklight }
326
- Blacklight = @orig_blacklight.clone
327
- Blacklight.unmemoize_all
328
- Blacklight.instance_variable_set("@config", {}.deep_merge(@orig_blacklight.config))
329
-
330
- Blacklight.config[:search_fields] = [
331
- { :display_label => "Author",
332
- :qt => "author_qt",
333
- :key => "author_key",
334
- :solr_local_parameters => {
335
- :qf => "$author_qf",
336
- :pf => "you'll have \" to escape this"
337
- },
338
- :solr_parameters => {
339
- :qf => "someField^1000",
340
- :ps => "2"
341
- }
313
+ def blacklight_config
314
+ config = Blacklight::Configuration.new
315
+ config.add_search_field(
316
+ "custom_author_key",
317
+ :display_label => "Author",
318
+ :qt => "author_qt",
319
+ :key => "custom_author_key",
320
+ :solr_local_parameters => {
321
+ :qf => "$author_qf",
322
+ :pf => "you'll have \" to escape this"
323
+ },
324
+ :solr_parameters => {
325
+ :qf => "someField^1000",
326
+ :ps => "2"
342
327
  }
343
- ]
344
-
345
- @solr_helper = MockSolrHelperContainer.new
346
- @solr_helper.params = {:search_field => "author_key", :q => "query"}
347
- @result = @solr_helper.solr_search_params
328
+ )
329
+ return config
330
+ end
331
+
332
+ def params
333
+ {:search_field => "custom_author_key", :q => "query"}
334
+ end
335
+
336
+ before do
337
+ @result = solr_search_params
348
338
  end
349
339
 
350
340
  it "should pass through ordinary params" do
@@ -357,27 +347,22 @@ describe 'Blacklight::SolrHelper' do
357
347
  @result[:q].should include('qf=$author_qf')
358
348
  @result[:q].should include('pf=\'you\\\'ll have \\" to escape this\'')
359
349
  end
360
-
361
- after do
362
- Object.instance_eval{ remove_const :Blacklight }
363
- Blacklight = @orig_blacklight
364
- end
365
350
  end
366
351
 
367
352
  describe "mapping facet.field" do
368
353
  it "should add single additional facet.field from app" do
369
- solr_params = @solr_helper.solr_search_params( "facet.field" => "additional_facet" )
354
+ solr_params = solr_search_params( "facet.field" => "additional_facet" )
370
355
  solr_params[:"facet.field"].should include("additional_facet")
371
356
  solr_params[:"facet.field"].length.should > 1
372
357
  end
373
358
  it "should map multiple facet.field to additional facet.field" do
374
- solr_params = @solr_helper.solr_search_params( "facet.field" => ["add_facet1", "add_facet2"] )
359
+ solr_params = solr_search_params( "facet.field" => ["add_facet1", "add_facet2"] )
375
360
  solr_params[:"facet.field"].should include("add_facet1")
376
361
  solr_params[:"facet.field"].should include("add_facet2")
377
362
  solr_params[:"facet.field"].length.should > 2
378
363
  end
379
364
  it "should map facets[fields][] to additional facet.field" do
380
- solr_params = @solr_helper.solr_search_params( "facets" => ["add_facet1", "add_facet2"] )
365
+ solr_params = solr_search_params( "facets" => ["add_facet1", "add_facet2"] )
381
366
  solr_params[:"facet.field"].should include("add_facet1")
382
367
  solr_params[:"facet.field"].should include("add_facet2")
383
368
  solr_params[:"facet.field"].length.should > 2
@@ -389,7 +374,7 @@ describe 'Blacklight::SolrHelper' do
389
374
  describe "solr_facet_params" do
390
375
  before do
391
376
  @facet_field = 'format'
392
- @generated_solr_facet_params = @solr_helper.solr_facet_params(@facet_field)
377
+ @generated_solr_facet_params = solr_facet_params(@facet_field)
393
378
 
394
379
  @sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
395
380
  @offset_key = Blacklight::Solr::FacetPaginator.request_keys[:offset]
@@ -404,30 +389,30 @@ describe 'Blacklight::SolrHelper' do
404
389
  @generated_solr_facet_params['facet.offset'].should == 0
405
390
  end
406
391
  it 'uses offset manually set, and converts it to an integer' do
407
- solr_params = @solr_helper.solr_facet_params(@facet_field, @offset_key => "100")
392
+ solr_params = solr_facet_params(@facet_field, @offset_key => "100")
408
393
  solr_params['facet.offset'].should == 100
409
394
  end
410
395
  it 'defaults limit to 20' do
411
- solr_params = @solr_helper.solr_facet_params(@facet_field)
396
+ solr_params = solr_facet_params(@facet_field)
412
397
  solr_params[:"f.#{@facet_field}.facet.limit"].should == 21
413
398
  end
414
399
  describe 'if facet_list_limit is defined in controller' do
415
- before(:each) do
416
- @solr_helper.stub!("facet_list_limit").and_return("1000")
400
+ def facet_list_limit
401
+ 1000
417
402
  end
418
403
  it 'uses controller method for limit' do
419
- solr_params = @solr_helper.solr_facet_params(@facet_field)
404
+ solr_params = solr_facet_params(@facet_field)
420
405
  solr_params[:"f.#{@facet_field}.facet.limit"].should == 1001
421
406
  end
422
407
  end
423
408
  it 'uses sort set manually' do
424
- solr_params = @solr_helper.solr_facet_params(@facet_field, @sort_key => "index")
409
+ solr_params = solr_facet_params(@facet_field, @sort_key => "index")
425
410
  solr_params['facet.sort'].should == 'index'
426
411
  end
427
412
  it "comes up with the same params as #solr_search_params to constrain context for facet list" do
428
413
  search_params = {:q => 'tibetan history', :f=> {:format=>'Book', :language_facet=>'Tibetan'}}
429
- solr_search_params = @solr_helper.solr_search_params( search_params )
430
- solr_facet_params = @solr_helper.solr_facet_params('format', search_params)
414
+ solr_search_params = solr_search_params( search_params )
415
+ solr_facet_params = solr_facet_params('format', search_params)
431
416
 
432
417
  solr_search_params.each_pair do |key, value|
433
418
  # The specific params used for fetching the facet list we
@@ -439,25 +424,28 @@ describe 'Blacklight::SolrHelper' do
439
424
 
440
425
  end
441
426
  end
442
- describe "for facet limit parameters config ed" do
443
- before(:each) do
444
- @solr_helper_facet = MockSolrHelperContainer.new
445
- @solr_helper_facet.params = {:search_field => "test_field", :q => "test query"}
446
- @solr_helper_facet.stub!("facet_limit_hash").and_return({:some_facet => nil, :subject_facet => 10})
447
- @generated_params = @solr_helper_facet.solr_search_params
427
+ describe "for facet limit parameters config ed" do
428
+ def params
429
+ {:search_field => "test_field", :q => "test query"}
430
+ end
431
+
432
+
433
+ before do
434
+ @generated_params = solr_search_params
448
435
  end
449
436
 
450
437
  it "should include specifically configged facet limits +1" do
451
- @generated_params[:"f.subject_facet.facet.limit"].should == 11
438
+ @generated_params[:"f.subject_topic_facet.facet.limit"].should == 21
452
439
  end
453
440
  it "should not include a facet limit for a nil key in hash" do
454
- @generated_params.should_not have_key(:"f.some_facet.facet.limit")
441
+ @generated_params.should_not have_key(:"f.format.facet.limit")
455
442
  @generated_params.should_not have_key(:"facet.limit")
456
443
  end
457
444
  end
458
- describe "get_facet_pagination" do
445
+
446
+ describe "get_facet_pagination", :integration => true do
459
447
  before(:each) do
460
- @facet_paginator = @solr_helper.get_facet_pagination(@facet_field)
448
+ @facet_paginator = get_facet_pagination(@facet_field)
461
449
  end
462
450
  it 'should return a facet paginator' do
463
451
  @facet_paginator.should be_a_kind_of(Blacklight::Solr::FacetPaginator)
@@ -468,12 +456,12 @@ describe 'Blacklight::SolrHelper' do
468
456
  end
469
457
 
470
458
  # SPECS FOR SEARCH RESULTS FOR QUERY
471
- describe 'Search Results' do
459
+ describe 'Search Results', :integration => true do
472
460
 
473
461
  describe 'for a sample query returning results' do
474
462
 
475
463
  before(:all) do
476
- (@solr_response, @document_list) = @solr_helper.get_search_results(:q => @all_docs_query)
464
+ (@solr_response, @document_list) = get_search_results(:q => @all_docs_query)
477
465
  end
478
466
 
479
467
  it 'should have a @response.docs list of the same size as @document_list' do
@@ -496,11 +484,11 @@ describe 'Blacklight::SolrHelper' do
496
484
 
497
485
  describe 'for All Docs Query, No Facets' do
498
486
  it 'should have non-nil values for required doc fields set in initializer' do
499
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @all_docs_query)
487
+ (solr_response, document_list) = get_search_results(:q => @all_docs_query)
500
488
  result_docs = document_list
501
489
  document = result_docs.first
502
- document.get(Blacklight.config[:index][:show_link]).should_not == nil
503
- document.get(Blacklight.config[:index][:record_display_type]).should_not == nil
490
+ document.get(blacklight_config.index.show_link).should_not == nil
491
+ document.get(blacklight_config.index.record_display_type).should_not == nil
504
492
  end
505
493
  end
506
494
 
@@ -508,7 +496,7 @@ describe 'Blacklight::SolrHelper' do
508
496
 
509
497
  describe "Single Word Query with no Facets" do
510
498
  it 'should have results' do
511
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @single_word_query)
499
+ (solr_response, document_list) = get_search_results(:q => @single_word_query)
512
500
  solr_response.docs.size.should == document_list.size
513
501
  solr_response.docs.size.should > 0
514
502
  end
@@ -517,7 +505,7 @@ describe 'Blacklight::SolrHelper' do
517
505
  describe "Multiple Words Query with No Facets" do
518
506
  it 'should have results' do
519
507
 
520
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @mult_word_query)
508
+ (solr_response, document_list) = get_search_results(:q => @mult_word_query)
521
509
  solr_response.docs.size.should == document_list.size
522
510
  solr_response.docs.size.should > 0
523
511
  end
@@ -525,7 +513,7 @@ describe 'Blacklight::SolrHelper' do
525
513
 
526
514
  describe "One Facet, No Query" do
527
515
  it 'should have results' do
528
- (solr_response, document_list) = @solr_helper.get_search_results(:f => @single_facet)
516
+ (solr_response, document_list) = get_search_results(:f => @single_facet)
529
517
  solr_response.docs.size.should == document_list.size
530
518
  solr_response.docs.size.should > 0
531
519
  end
@@ -533,7 +521,7 @@ describe 'Blacklight::SolrHelper' do
533
521
 
534
522
  describe "Mult Facets, No Query" do
535
523
  it 'should have results' do
536
- (solr_response, document_list) = @solr_helper.get_search_results(:f => @multi_facets)
524
+ (solr_response, document_list) = get_search_results(:f => @multi_facets)
537
525
  solr_response.docs.size.should == document_list.size
538
526
  solr_response.docs.size.should > 0
539
527
  end
@@ -541,7 +529,7 @@ describe 'Blacklight::SolrHelper' do
541
529
 
542
530
  describe "Single Word Query with One Facet" do
543
531
  it 'should have results' do
544
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @single_word_query, :f => @single_facet)
532
+ (solr_response, document_list) = get_search_results(:q => @single_word_query, :f => @single_facet)
545
533
  solr_response.docs.size.should == document_list.size
546
534
  solr_response.docs.size.should > 0
547
535
  end
@@ -549,7 +537,7 @@ describe 'Blacklight::SolrHelper' do
549
537
 
550
538
  describe "Multiple Words Query with Multiple Facets" do
551
539
  it 'should have results' do
552
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @mult_word_query, :f => @multi_facets)
540
+ (solr_response, document_list) = get_search_results(:q => @mult_word_query, :f => @multi_facets)
553
541
  solr_response.docs.size.should == document_list.size
554
542
  solr_response.docs.size.should > 0
555
543
  end
@@ -557,7 +545,7 @@ describe 'Blacklight::SolrHelper' do
557
545
 
558
546
  describe "for All Docs Query and One Facet" do
559
547
  it 'should have results' do
560
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @all_docs_query, :f => @single_facet)
548
+ (solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @single_facet)
561
549
  solr_response.docs.size.should == document_list.size
562
550
  solr_response.docs.size.should > 0
563
551
  end
@@ -567,7 +555,7 @@ describe 'Blacklight::SolrHelper' do
567
555
 
568
556
  describe "for Query Without Results and No Facet" do
569
557
  it 'should have no results and not raise error' do
570
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @no_docs_query)
558
+ (solr_response, document_list) = get_search_results(:q => @no_docs_query)
571
559
  solr_response.docs.size.should == document_list.size
572
560
  solr_response.docs.size.should == 0
573
561
  end
@@ -575,7 +563,7 @@ describe 'Blacklight::SolrHelper' do
575
563
 
576
564
  describe "for Query Without Results and One Facet" do
577
565
  it 'should have no results and not raise error' do
578
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @no_docs_query, :f => @single_facet)
566
+ (solr_response, document_list) = get_search_results(:q => @no_docs_query, :f => @single_facet)
579
567
  solr_response.docs.size.should == document_list.size
580
568
  solr_response.docs.size.should == 0
581
569
  end
@@ -583,30 +571,23 @@ describe 'Blacklight::SolrHelper' do
583
571
 
584
572
  describe "for All Docs Query and Bad Facet" do
585
573
  it 'should have no results and not raise error' do
586
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @all_docs_query, :f => @bad_facet)
574
+ (solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @bad_facet)
587
575
  solr_response.docs.size.should == document_list.size
588
576
  solr_response.docs.size.should == 0
589
577
  end
590
578
  end
591
579
 
592
- describe "for default display fields" do
593
- it "should have a list of field names for index_view_fields" do
594
- Blacklight.config[:index_fields].should_not be_nil
595
- Blacklight.config[:index_fields][:field_names].should be_instance_of(Array)
596
- Blacklight.config[:index_fields][:field_names].length.should > 0
597
- Blacklight.config[:index_fields][:field_names][0].should_not == nil
598
- end
599
- end
580
+
600
581
 
601
582
 
602
583
  end # Search Results
603
584
 
604
585
 
605
586
  # SPECS FOR SEARCH RESULTS FOR FACETS
606
- describe 'Facets in Search Results for All Docs Query' do
587
+ describe 'Facets in Search Results for All Docs Query', :integration => true do
607
588
 
608
589
  before(:all) do
609
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @all_docs_query)
590
+ (solr_response, document_list) = get_search_results(:q => @all_docs_query)
610
591
  @facets = solr_response.facets
611
592
  end
612
593
 
@@ -614,7 +595,7 @@ describe 'Blacklight::SolrHelper' do
614
595
  @facets.size.should > 1
615
596
  end
616
597
  it 'should have all facets specified in initializer' do
617
- Blacklight.config[:default_solr_params][:"facet.field"].each do |field|
598
+ blacklight_config[:default_solr_params][:"facet.field"].each do |field|
618
599
  @facets.find {|f| f.name == field}.should_not be_nil
619
600
  end
620
601
  end
@@ -644,40 +625,40 @@ describe 'Blacklight::SolrHelper' do
644
625
 
645
626
 
646
627
  # SPECS FOR SEARCH RESULTS FOR PAGING
647
- describe 'Paging' do
628
+ describe 'Paging', :integration => true do
648
629
 
649
630
  it 'should start with first results by default' do
650
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @all_docs_query)
631
+ (solr_response, document_list) = get_search_results(:q => @all_docs_query)
651
632
  solr_response.params[:start].to_i.should == 0
652
633
  end
653
634
  it 'should have number of results (per page) set in initializer, by default' do
654
- (solr_response, document_list) = @solr_helper.get_search_results(:q => @all_docs_query)
635
+ (solr_response, document_list) = get_search_results(:q => @all_docs_query)
655
636
  solr_response.docs.size.should == document_list.size
656
- solr_response.docs.size.should == Blacklight.config[:default_solr_params][:per_page]
637
+ solr_response.docs.size.should == blacklight_config[:default_solr_params][:rows]
657
638
  end
658
639
 
659
640
  it 'should get number of results per page requested' do
660
641
  num_results = 3 # non-default value
661
- (solr_response1, document_list1) = @solr_helper.get_search_results(:q => @all_docs_query, :per_page => num_results)
642
+ (solr_response1, document_list1) = get_search_results(:q => @all_docs_query, :per_page => num_results)
662
643
  solr_response1.docs.size.should == document_list1.size
663
644
  solr_response1.docs.size.should == num_results
664
645
  end
665
646
 
666
647
  it 'should skip appropriate number of results when requested - default per page' do
667
648
  page = 3
668
- (solr_response2, document_list2) = @solr_helper.get_search_results(:q => @all_docs_query, :page => page)
669
- solr_response2.params[:start].to_i.should == Blacklight.config[:default_solr_params][:per_page] * (page-1)
649
+ (solr_response2, document_list2) = get_search_results(:q => @all_docs_query, :page => page)
650
+ solr_response2.params[:start].to_i.should == blacklight_config[:default_solr_params][:rows] * (page-1)
670
651
  end
671
652
  it 'should skip appropriate number of results when requested - non-default per page' do
672
653
  page = 3
673
654
  num_results = 3
674
- (solr_response2a, document_list2a) = @solr_helper.get_search_results(:q => @all_docs_query, :per_page => num_results, :page => page)
655
+ (solr_response2a, document_list2a) = get_search_results(:q => @all_docs_query, :per_page => num_results, :page => page)
675
656
  solr_response2a.params[:start].to_i.should == num_results * (page-1)
676
657
  end
677
658
 
678
659
  it 'should have no results when prompted for page after last result' do
679
660
  big = 5000
680
- (solr_response3, document_list3) = @solr_helper.get_search_results(:q => @all_docs_query, :per_page => big, :page => big)
661
+ (solr_response3, document_list3) = get_search_results(:q => @all_docs_query, :rows => big, :page => big)
681
662
  solr_response3.docs.size.should == document_list3.size
682
663
  solr_response3.docs.size.should == 0
683
664
  end
@@ -685,12 +666,12 @@ describe 'Blacklight::SolrHelper' do
685
666
  it 'should show first results when prompted for page before first result' do
686
667
  # FIXME: should it show first results, or should it throw an error for view to deal w?
687
668
  # Solr throws an error for a negative start value
688
- (solr_response4, document_list4) = @solr_helper.get_search_results(:q => @all_docs_query, :page => '-1')
669
+ (solr_response4, document_list4) = get_search_results(:q => @all_docs_query, :page => '-1')
689
670
  solr_response4.params[:start].to_i.should == 0
690
671
  end
691
672
  it 'should have results available when asked for more than are in response' do
692
673
  big = 5000
693
- (solr_response5, document_list5) = @solr_helper.get_search_results(:q => @all_docs_query, :per_page => big, :page => 1)
674
+ (solr_response5, document_list5) = get_search_results(:q => @all_docs_query, :rows => big, :page => 1)
694
675
  solr_response5.docs.size.should == document_list5.size
695
676
  solr_response5.docs.size.should > 0
696
677
  end
@@ -698,16 +679,16 @@ describe 'Blacklight::SolrHelper' do
698
679
  end # page specs
699
680
 
700
681
  # SPECS FOR SINGLE DOCUMENT REQUESTS
701
- describe 'Get Document By Id' do
682
+ describe 'Get Document By Id', :integration => true do
702
683
  before(:all) do
703
684
  @doc_id = '2007020969'
704
685
  @bad_id = "redrum"
705
- @response2, @document = @solr_helper.get_solr_response_for_doc_id(@doc_id)
686
+ @response2, @document = get_solr_response_for_doc_id(@doc_id)
706
687
  end
707
688
 
708
689
  it "should raise Blacklight::InvalidSolrID for an unknown id" do
709
690
  lambda {
710
- @solr_helper.get_solr_response_for_doc_id(@bad_id)
691
+ get_solr_response_for_doc_id(@bad_id)
711
692
  }.should raise_error(Blacklight::Exceptions::InvalidSolrID)
712
693
  end
713
694
 
@@ -721,15 +702,9 @@ describe 'Blacklight::SolrHelper' do
721
702
  @document.id.should == @doc_id
722
703
  end
723
704
  it 'should have non-nil values for required fields set in initializer' do
724
- @document.get(Blacklight.config[:show][:html_title]).should_not == nil
725
- @document.get(Blacklight.config[:show][:heading]).should_not == nil
726
- @document.get(Blacklight.config[:show][:display_type]).should_not == nil
727
- end
728
- it "should have a list of field names for show_view_fields" do
729
- Blacklight.config[:show_fields].should_not be_nil
730
- Blacklight.config[:show_fields][:field_names].should be_instance_of(Array)
731
- Blacklight.config[:show_fields][:field_names].length.should > 0
732
- Blacklight.config[:show_fields][:field_names][0].should_not == nil
705
+ @document.get(blacklight_config[:show][:html_title]).should_not == nil
706
+ @document.get(blacklight_config[:show][:heading]).should_not == nil
707
+ @document.get(blacklight_config[:show][:display_type]).should_not == nil
733
708
  end
734
709
  end
735
710
 
@@ -744,20 +719,18 @@ describe 'Blacklight::SolrHelper' do
744
719
  end
745
720
  =end
746
721
  it "should respect the configuration-supplied unique id" do
747
- doc_params = @solr_helper.solr_doc_params('"Strong Medicine speaks"')
722
+ doc_params = solr_doc_params('"Strong Medicine speaks"')
748
723
  doc_params[:id].should == '"Strong Medicine speaks"'
749
724
  end
750
725
  end
751
726
 
752
- # NOTE: some of these repeated fields could be in a shared behavior, but the
753
- # flow of control is such that the variables can't be instance variables
754
- # (or at least not for me - Naomi)
727
+
755
728
 
756
729
  # SPECS FOR SINGLE DOCUMENT VIA SEARCH
757
- describe "Get Document Via Search" do
730
+ describe "Get Document Via Search", :integration => true do
758
731
  before(:all) do
759
732
  @doc_row = 3
760
- @doc = @solr_helper.get_single_doc_via_search(@doc_row, :q => @all_docs_query)
733
+ @doc = get_single_doc_via_search(@doc_row, :q => @all_docs_query)
761
734
  end
762
735
  =begin
763
736
  # can't test these here, because the method only returns the document
@@ -780,28 +753,28 @@ describe 'Blacklight::SolrHelper' do
780
753
  end
781
754
 
782
755
  it 'should have non-nil values for required fields set in initializer' do
783
- @doc[Blacklight.config[:show][:html_title]].should_not == nil
784
- @doc[Blacklight.config[:show][:heading]].should_not == nil
785
- @doc[Blacklight.config[:show][:display_type]].should_not == nil
756
+ @doc[blacklight_config.show.html_title].should_not == nil
757
+ @doc[blacklight_config.show.heading].should_not == nil
758
+ @doc[blacklight_config.show.display_type].should_not == nil
786
759
  end
787
760
 
788
761
  it "should limit search result by facets when supplied" do
789
- doc2 = @solr_helper.get_single_doc_via_search(@doc_row , :q => @all_docs_query, :f => @multi_facets)
762
+ doc2 = get_single_doc_via_search(@doc_row , :q => @all_docs_query, :f => @multi_facets)
790
763
  doc2[:id].should_not == nil
791
764
  end
792
765
 
793
766
  end
794
767
 
795
768
  # SPECS FOR SPELLING SUGGESTIONS VIA SEARCH
796
- describe "Searches should return spelling suggestions" do
769
+ describe "Searches should return spelling suggestions", :integration => true do
797
770
  it 'search results for just-poor-enough-query term should have (multiple) spelling suggestions' do
798
- (solr_response, document_list) = @solr_helper.get_search_results({:q => 'boo'})
771
+ (solr_response, document_list) = get_search_results({:q => 'boo'})
799
772
  solr_response.spelling.words.should include('bon')
800
773
  solr_response.spelling.words.should include('bod') #for multiple suggestions
801
774
  end
802
775
 
803
776
  it 'search results for just-poor-enough-query term should have multiple spelling suggestions' do
804
- (solr_response, document_list) = @solr_helper.get_search_results({:q => 'politica'})
777
+ (solr_response, document_list) = get_search_results({:q => 'politica'})
805
778
  solr_response.spelling.words.should include('policy') # less freq
806
779
  solr_response.spelling.words.should include('politics') # more freq
807
780
  solr_response.spelling.words.should include('political') # more freq
@@ -814,17 +787,17 @@ describe 'Blacklight::SolrHelper' do
814
787
  end
815
788
 
816
789
  it "title search results for just-poor-enough query term should have spelling suggestions" do
817
- (solr_response, document_list) = @solr_helper.get_search_results({:q => 'yehudiyam', :qt => 'search', :"spellcheck.dictionary" => "title"})
790
+ (solr_response, document_list) = get_search_results({:q => 'yehudiyam', :qt => 'search', :"spellcheck.dictionary" => "title"})
818
791
  solr_response.spelling.words.should include('yehudiyim')
819
792
  end
820
793
 
821
794
  it "author search results for just-poor-enough-query term should have spelling suggestions" do
822
- (solr_response, document_list) = @solr_helper.get_search_results({:q => 'shirma', :qt => 'search', :"spellcheck.dictionary" => "author"})
795
+ (solr_response, document_list) = get_search_results({:q => 'shirma', :qt => 'search', :"spellcheck.dictionary" => "author"})
823
796
  solr_response.spelling.words.should include('sharma')
824
797
  end
825
798
 
826
799
  it "subject search results for just-poor-enough-query term should have spelling suggestions" do
827
- (solr_response, document_list) = @solr_helper.get_search_results({:q => 'wome', :qt => 'search', :"spellcheck.dictionary" => "subject"})
800
+ (solr_response, document_list) = get_search_results({:q => 'wome', :qt => 'search', :"spellcheck.dictionary" => "subject"})
828
801
  solr_response.spelling.words.should include('women')
829
802
  end
830
803
 
@@ -838,71 +811,79 @@ describe 'Blacklight::SolrHelper' do
838
811
  describe "facet_limit_for" do
839
812
 
840
813
  it "should return specified value for facet_field specified" do
841
- @solr_helper.facet_limit_for("subject_topic_facet").should == Blacklight.config[:facet][:limits]["subject_topic_facet"]
814
+ facet_limit_for("subject_topic_facet").should == blacklight_config.facet_fields["subject_topic_facet"].limit
815
+ end
816
+ it "should generate proper solr param" do
817
+ solr_search_params[:"f.subject_topic_facet.facet.limit"].should == 21
842
818
  end
843
- it "@solr_helper.facet_limit_hash should return hash with key being facet_field and value being configured limit" do
844
- @solr_helper.facet_limit_hash.should == Blacklight.config[:facet][:limits]
819
+
820
+ it "facet_limit_hash should return hash with key being facet_field and value being configured limit" do
821
+ # facet_limit_hash has been removed from solrhelper in refactor. should it go back?
822
+ pending "facet_limit_hash has been removed from solrhelper in refactor. should it go back?"
823
+ facet_limit_hash.should == blacklight_config[:facet][:limits]
845
824
  end
846
825
  it "should handle no facet_limits in config" do
847
- Blacklight.config[:facet][:field_names].include?("subject_topic_facet").should be_true
848
- Blacklight.config[:facet][:limits].has_key?("subject_topic_facet").should be_true
849
- @solr_helper.facet_limit_for("subject_topic_facet").should == 20
850
- fl = Blacklight.config[:facet][:limits]
851
- Blacklight.config[:facet][:limits] = nil
852
- @solr_helper.facet_limit_for("subject_topic_facet").should be_nil
853
- Blacklight.config[:facet][:limits] = fl
854
- end
855
- it "solr_search_params should handle no facet_limits in config" do
856
- Blacklight.config[:facet][:field_names].include?("subject_topic_facet").should be_true
857
- Blacklight.config[:facet][:limits].has_key?("subject_topic_facet").should be_true
858
- @solr_helper.solr_search_params[:"f.subject_topic_facet.facet.limit"].should == 21
859
- fl = Blacklight.config[:facet][:limits]
860
- Blacklight.config[:facet][:limits] = nil
861
- @solr_helper.solr_search_params.has_key?(:"f.subject_topic_facet.facet.limit").should be_false
862
- Blacklight.config[:facet][:limits] = fl
826
+ def blacklight_config
827
+ config = super.inheritable_copy
828
+ config.facet_fields = {}
829
+ return config
830
+ end
831
+
832
+ facet_limit_for("subject_topic_facet").should be_nil
833
+
834
+ solr_search_params.should_not have_key(:"f.subject_topic_facet.facet.limit")
835
+
863
836
  end
837
+
864
838
  describe "for 'true' configured values" do
865
839
  it "should return nil if no @response available" do
866
- @solr_helper.facet_limit_for("some_field").should be_nil
840
+ facet_limit_for("some_unknown_field").should be_nil
867
841
  end
868
- it "should get from @response facet.limit if available" do
869
- @solr_helper.response = {"responseHeader" => {"params" => {"facet.limit" => 11}}}
870
- @solr_helper.facet_limit_for("language_facet").should == 10
842
+ it "should get from @response facet.limit if available" do
843
+ # Okay, this is cheesy, since we included SolrHelper directly
844
+ # into our example groups, we need to set an iVar here, so it will
845
+ # use it.
846
+ @response = {"responseHeader" => {"params" => {"facet.limit" => 11}}}
847
+ facet_limit_for("language_facet").should == 10
871
848
  end
872
849
  it "should get from specific field in @response if available" do
873
- @solr_helper.response = {"responseHeader" => {"params" => {"facet.limit" => 11,"f.language_facet.facet.limit" => 16}}}
874
- @solr_helper.facet_limit_for("language_facet").should == 15
850
+ @response = {"responseHeader" => {"params" => {"facet.limit" => 11,"f.language_facet.facet.limit" => 16}}}
851
+ facet_limit_for("language_facet").should == 15
875
852
  end
876
853
  end
877
854
  end
878
855
 
879
856
  describe "with max per page enforced" do
857
+ def blacklight_config
858
+ config = Blacklight::Configuration.new
859
+ config.max_per_page = 123
860
+ return config
861
+ end
862
+
863
+ it "should enforce max_per_page against all parameters" do
864
+ blacklight_config.max_per_page.should == 123
865
+ solr_search_params(:per_page => 98765)[:rows].should == 123
866
+ end
867
+ end
868
+
869
+ describe "#get_solr_response_for_field_values" do
880
870
  before do
881
- # Add some params
882
- @solr_helper_with_params = MockSolrHelperContainer.new
883
- @solr_helper_with_params.params = {:search_field => "test_field", :per_page => 12345, :q => "test query", "facet.field" => "extra_facet"}
871
+ @mock_response = mock()
872
+ @mock_response.stub(:docs => [])
884
873
  end
885
- after do
874
+ it "should contruct a solr query based on the field and value pair" do
875
+ self.should_receive(:find).with(hash_including(:q => "field_name:(value)")).and_return(@mock_response)
876
+ get_solr_response_for_field_values('field_name', 'value')
886
877
  end
887
878
 
888
- describe "should enforce MaxPerPage against user supplied parameters" do
889
- before do
890
- @produced_params = @solr_helper_with_params.solr_search_params
891
- 1+1
892
- end
893
- it "should take per_page from search field definition where specified" do
894
- @produced_params[:per_page].should == "100"
895
- end
879
+ it "should OR multiple values together" do
880
+ self.should_receive(:find).with(hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
881
+ get_solr_response_for_field_values('field_name', ['a', 'b'])
896
882
  end
897
883
 
898
- describe "should enforce MaxPerPage against extra controller parameters" do
899
- before do
900
- @produced_params = @solr_helper_with_params.solr_search_params(:per_page => 98765)
901
- 1+1
902
- end
903
- it "should take per_page from search field definition where specified" do
904
- @produced_params[:per_page].should == "100"
905
- end
884
+ it "should escape crazy identifiers" do
885
+ self.should_receive(:find).with(hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
886
+ get_solr_response_for_field_values('field_name', 'h://"\'')
906
887
  end
907
888
  end
908
889