blacklight 3.1.2 → 3.2.0pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -6,6 +6,12 @@ describe FolderController do
6
6
  end
7
7
 
8
8
  it "should add items to list" do
9
+ @mock_response = mock()
10
+ @mock_document = mock()
11
+ @mock_document2 = mock()
12
+ @mock_document.stub(:export_formats => {})
13
+ controller.stub(:get_solr_response_for_field_values => [@mock_response, [@mock_document, @mock_document2]])
14
+
9
15
  get :update, :id =>"77826928"
10
16
  session[:folder_document_ids].length.should == 1
11
17
  get :update, :id => "94120425"
@@ -13,7 +19,7 @@ describe FolderController do
13
19
  session[:folder_document_ids].should include("77826928")
14
20
  get :index
15
21
  assigns[:documents].length.should == 2
16
- assigns[:documents].first.should be_instance_of(SolrDocument)
22
+ assigns[:documents].first.should == @mock_document
17
23
  end
18
24
  it "should delete an item from list" do
19
25
  get :update, :id =>"77826928"
@@ -62,10 +62,35 @@ def exportable_record
62
62
  </datafield>
63
63
  </record>"
64
64
  end
65
+
65
66
  describe BlacklightHelper do
66
67
  include ERB::Util
67
68
  include BlacklightHelper
68
-
69
+ def blacklight_config
70
+ @config ||= Blacklight::Configuration.new.configure do |config|
71
+ config.show.html_title = "title_display"
72
+ config.show.heading = "title_display"
73
+ config.show.display_type = 'format'
74
+
75
+ config.index.show_link = 'title_display'
76
+ config.index.record_display_type = 'format'
77
+ end
78
+
79
+ #CatalogController.blacklight_config
80
+ #@config ||= {:show => {:html_title => 'title_display', :heading => 'title_display', :display_type => 'format'}, :index => { :show_link => 'title_display', :record_display_type => 'format' } }
81
+ end
82
+
83
+ describe "#application_name", :test => true do
84
+ it "should use the Rails application config application_name if available" do
85
+ Rails.application.config.stub(:application_name => 'asdf')
86
+ Rails.application.config.should_receive(:respond_to?).with(:application_name).and_return(true)
87
+ application_name.should == 'asdf'
88
+ end
89
+ it "should default to 'Blacklight'" do
90
+ application_name.should == "Blacklight"
91
+ end
92
+ end
93
+
69
94
  describe "link_back_to_catalog" do
70
95
  before(:all) do
71
96
  @query_params = {:q => "query", :f => "facets", :per_page => "10", :page => "2"}
@@ -80,18 +105,6 @@ describe BlacklightHelper do
80
105
  end
81
106
  end
82
107
 
83
- describe "link_to_with_data" do
84
- it "should generate proper tag for :put and with single :data key and value" do
85
- assert_dom_equal(
86
- "<a href='http://www.example.com' onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;if(event.metaKey || event.ctrlKey){f.target = '_blank';};var d = document.createElement('input'); d.setAttribute('type', 'hidden'); d.setAttribute('name', 'key'); d.setAttribute('value', 'value'); f.appendChild(d);var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'put'); f.appendChild(m);f.submit();return false;\">Foo</a>",
87
- link_to_with_data("Foo", "http://www.example.com", :method => :put, :data => {:key => "value"})
88
- )
89
- end
90
- it "should be html_safe" do
91
- link_to_with_data("Foo", "http://www.example.com", :method => :put, :data => {:key => "value"}).html_safe?.should == true
92
- end
93
- end
94
-
95
108
  describe "link_to_query" do
96
109
  it "should build a link tag to catalog using query string (no other params)" do
97
110
  query = "brilliant"
@@ -122,13 +135,13 @@ describe BlacklightHelper do
122
135
  end
123
136
  end
124
137
 
125
- describe "search_as_hidden_fields" do
138
+ describe "search_as_hidden_fields", :asdf => true do
126
139
  def params
127
- {:q => "query", :sort => "sort", :per_page => "20", :search_field => "search_field", :page => 100, :arbitrary_key => "arbitrary_value", :f => {"field" => ["value1", "value2"]}, :controller => "catalog", :action => "index", :commit => "search"}
140
+ {: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"}
128
141
  end
129
142
  describe "for default arguments" do
130
143
  it "should default to omitting :page" do
131
- search_as_hidden_fields.should have_selector("input[type='hidden']", :count =>7)
144
+ search_as_hidden_fields.should have_selector("input[type='hidden']", :count =>8)
132
145
  search_as_hidden_fields.should_not have_selector("input[name='page']")
133
146
  end
134
147
  it "should not return blacklisted elements" do
@@ -145,6 +158,12 @@ describe BlacklightHelper do
145
158
 
146
159
  generated.should have_selector("input[name=page]")
147
160
  end
161
+
162
+ it "should support hash-based deleting" do
163
+ generated = search_as_hidden_fields(:omit_keys => [{:f => 'field' }])
164
+ generated.should have_selector("input[name='f[other_field][]']")
165
+ generated.should_not have_selector("input[name='f[field][]']")
166
+ end
148
167
  end
149
168
  end
150
169
  end
@@ -169,8 +188,9 @@ describe BlacklightHelper do
169
188
  end
170
189
 
171
190
  describe "document_heading" do
191
+
172
192
  it "should consist of the show heading field when available" do
173
- @document = SolrDocument.new(Blacklight.config[:show][:heading] => "A Fake Document")
193
+ @document = SolrDocument.new('title_display' => "A Fake Document")
174
194
 
175
195
  document_heading.should == "A Fake Document"
176
196
  end
@@ -183,7 +203,7 @@ describe BlacklightHelper do
183
203
 
184
204
  describe "render_document_heading" do
185
205
  it "should consist of #document_heading wrapped in a <h1>" do
186
- @document = SolrDocument.new(Blacklight.config[:show][:heading] => "A Fake Document")
206
+ @document = SolrDocument.new('title_display' => "A Fake Document")
187
207
 
188
208
  render_document_heading.should have_selector("h1", :content => document_heading, :count => 1)
189
209
  render_document_heading.html_safe?.should == true
@@ -223,13 +243,7 @@ describe BlacklightHelper do
223
243
  @document = SolrDocument.new(data)
224
244
  link_to_document(@document, { :label => "title_display" }).should have_selector("a", :content => 'title_display', :count => 1)
225
245
  end
226
- it "should properly javascript escape the label value" do
227
- data = {'id'=>'123456','title_display'=>['654321'] }
228
- @document = SolrDocument.new(data)
229
- link = link_to_document(@document, { :label => "Apple's Oranges" })
230
- link.should match(/'Apple\\'s Oranges'/)
231
- link.should_not match(/'Apple's Oranges'/)
232
- end
246
+
233
247
  it "should accept and return a Proc" do
234
248
  data = {'id'=>'123456','title_display'=>['654321'] }
235
249
  @document = SolrDocument.new(data)
@@ -246,6 +260,12 @@ describe BlacklightHelper do
246
260
  @document = SolrDocument.new(data)
247
261
  link_to_document(@document, { :label => :title_display }).html_safe?.should == true
248
262
  end
263
+
264
+ it "should convert the counter parameter into a data- attribute" do
265
+ data = {'id'=>'123456','title_display'=>['654321']}
266
+ @document = SolrDocument.new(data)
267
+ link_to_document(@document, { :label => :title_display, :counter => 5 }).should =~ /data-counter="5"/
268
+ end
249
269
  end
250
270
 
251
271
 
@@ -301,13 +321,4 @@ describe BlacklightHelper do
301
321
 
302
322
  end
303
323
 
304
- describe "convenience methods" do
305
- it "should handle the case where we don't have a spellmax set in the config" do
306
- spell_check_max.should == 5
307
- sm = Blacklight.config[:spell_max]
308
- Blacklight.config[:spell_max] = nil
309
- spell_check_max.should == 0
310
- Blacklight.config[:spell_max] = sm
311
- end
312
- end
313
324
  end
@@ -1,6 +1,74 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  describe FacetsHelper do
3
3
 
4
+ describe "render_facet_partials" do
5
+ it "should only render facets with items" do
6
+ a = mock(:items => [1,2])
7
+ b = mock(:items => ['b','c'])
8
+ empty = mock(:items => [])
9
+
10
+ fields = [a,b,empty]
11
+
12
+ helper.should_receive(:render_facet_limit).with(a, {})
13
+ helper.should_receive(:render_facet_limit).with(b, {})
14
+ helper.should_not_receive(:render_facet_limit).with(empty, {})
15
+ helper.render_facet_partials fields
16
+ end
17
+
18
+ it "should look up facet fields in the response when given strings or symbols" do
19
+
20
+ a = mock(:name => 'a', :items => [1,2])
21
+
22
+ @response = mock()
23
+ @response.should_receive(:facet_by_field_name).with('a') { a }
24
+ helper.should_receive(:render_facet_limit).with(a, {})
25
+
26
+ helper.render_facet_partials ['a']
27
+ end
28
+ end
29
+
30
+ describe "render_facet_limit" do
31
+ before do
32
+
33
+ @config = Blacklight::Configuration.new do |config|
34
+ config.add_facet_field 'basic_field'
35
+ config.add_facet_field 'my_facet_field_with_custom_partial', :partial => 'custom_facet_partial'
36
+ end
37
+
38
+ helper.stub(:blacklight_config => @config)
39
+ @response = mock()
40
+ end
41
+
42
+ it "should set basic local variables" do
43
+ @mock_facet = mock(:name => 'basic_field')
44
+ helper.should_receive(:render).with(hash_including(:partial => 'facet_limit',
45
+ :locals => {
46
+ :solr_field => 'basic_field',
47
+ :facet_field => helper.blacklight_config.facet_fields['basic_field'],
48
+ :display_facet => @mock_facet }
49
+ ))
50
+ helper.render_facet_limit(@mock_facet)
51
+ end
52
+
53
+ it "should send a deprecation warning if the method is called using the old-style signature" do
54
+ helper.should_receive(:render_facet_partials).with(['asdf'])
55
+ $stderr.should_receive(:puts)
56
+ helper.render_facet_limit('asdf')
57
+ end
58
+
59
+ it "should render a facet _not_ declared in the configuration" do
60
+ @mock_facet = mock(:name => 'asdf')
61
+ helper.should_receive(:render).with(hash_including(:partial => 'facet_limit'))
62
+ helper.render_facet_limit(@mock_facet)
63
+ end
64
+
65
+ it "should get the partial name from the configuration" do
66
+ @mock_facet = mock(:name => 'my_facet_field_with_custom_partial')
67
+ helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
68
+ helper.render_facet_limit(@mock_facet)
69
+ end
70
+ end
71
+
4
72
  describe "add_facet_params" do
5
73
  before do
6
74
  @params_no_existing_facet = {:q => "query", :search_field => "search_field", :per_page => "50"}
@@ -12,6 +12,7 @@ describe HtmlHeadHelper do
12
12
  end
13
13
  it "should include script tags specified in controller#javascript_includes" do
14
14
  html = helper.render_js_includes
15
+
15
16
  if use_asset_pipeline?
16
17
  html.should have_selector("script[src='/assets/some_js.js'][type='text/javascript']")
17
18
  html.should have_selector("script[src='/assets/other_js.js'][type='text/javascript']")
@@ -35,6 +36,7 @@ describe HtmlHeadHelper do
35
36
  end
36
37
  it "should render stylesheets specified in controller #stylesheet_links" do
37
38
  html = helper.render_stylesheet_includes
39
+
38
40
  if use_asset_pipeline?
39
41
  html.should have_selector("link[href='/assets/my_stylesheet.css'][rel='stylesheet'][type='text/css']")
40
42
  html.should have_selector("link[href='/assets/other_stylesheet.css'][rel='stylesheet'][type='text/css']")
@@ -42,6 +44,7 @@ describe HtmlHeadHelper do
42
44
  html.should have_selector("link[href='/stylesheets/my_stylesheet.css'][rel='stylesheet'][type='text/css']")
43
45
  html.should have_selector("link[href='/stylesheets/other_stylesheet.css'][rel='stylesheet'][type='text/css']")
44
46
  end
47
+
45
48
  html.html_safe?.should == true
46
49
  end
47
50
  end
@@ -72,6 +75,40 @@ describe HtmlHeadHelper do
72
75
  end
73
76
  end
74
77
  describe "with methods defined" do
78
+ helper do
79
+ def javascript_includes
80
+ [["my_js"]]
81
+ end
82
+ def stylesheet_links
83
+ [["my_css"]]
84
+ end
85
+ def extra_head_content
86
+ [
87
+ "<madeup_tag></madeup_tag>",
88
+ '<link rel="rel" type="type" href="href">'
89
+ ]
90
+ end
91
+ end
92
+ before(:each) do
93
+ helper.should_receive(:content_for).with(:head).and_return("<meta keywords=\"foo bar\"/>".html_safe)
94
+ @output = helper.render_head_content
95
+ end
96
+ it "should include extra_head_content" do
97
+ @output.should have_selector("madeup_tag")
98
+ @output.should have_selector("link[rel=rel][type=type][href=href]")
99
+ end
100
+ it "should include render_javascript_includes" do
101
+ @output.should have_selector("script[src='/assets/my_js.js'][type='text/javascript']")
102
+ #@output.index( render_js_includes ).should_not be_nil
103
+ end
104
+ it "should include render_stylesheet_links" do
105
+ @output.should have_selector("link[href='/assets/my_css.css'][type='text/css']")
106
+ #@output.index( render_stylesheet_includes ).should_not be_nil
107
+ end
108
+ it "should include content_for :head" do
109
+ @output.should have_selector("meta[keywords]")
110
+ end
111
+
75
112
  it "should include all head content" do
76
113
  helper.should_receive(:render_extra_head_content).and_return("".html_safe)
77
114
  helper.should_receive(:render_js_includes).and_return("".html_safe)
@@ -1,13 +1,29 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
- # This is NOT currently spec'ing render_constraints_* methods, becuase
5
- # inflexibility in rspec makes it really hard to do so effectively. It would be
6
- # nice, the specs that are there for render_search_to_s could be a model.
7
- #
8
- # We ARE spec'ing render_search_to_s* versions, which is feasible since they
9
- # don't call any template partials.
10
- describe RenderConstraintsHelper do
4
+ describe SearchHistoryConstraintsHelper do
5
+
6
+ before(:all) do
7
+ @config = Blacklight::Configuration.from_legacy_configuration({
8
+ :default_search_field => {
9
+ :key => 'default_search_field',
10
+ :display_label => "Default"
11
+ },
12
+ :facet => {
13
+ :field_names => [
14
+ 'some_facet',
15
+ 'other_facet'
16
+ ],
17
+ :labels => {
18
+ 'some_facet' => 'Some',
19
+ 'other_facet' => 'Other'
20
+ },
21
+ :limits => {
22
+ }
23
+ }
24
+ })
25
+ end
26
+
11
27
 
12
28
  describe "render_search_to_s_*" do
13
29
  describe "render_search_to_s_element" do
@@ -49,6 +65,9 @@ describe RenderConstraintsHelper do
49
65
  @params = {:q => "history", :f => {"some_facet" => ["value1", "value1"], "other_facet" => ["other1"]}}
50
66
  end
51
67
  it "should call lesser methods" do
68
+ helper.stub!(:blacklight_config).and_return(@config)
69
+ helper.stub!(:default_search_field).and_return(Blacklight::Configuration::SearchField.new(:key => 'default_search_field', :display_label => 'Default'))
70
+ helper.should_receive(:label_for_search_field).with(nil).any_number_of_times.and_return('')
52
71
  # API hooks expect this to be so
53
72
  response = helper.render_search_to_s(@params)
54
73
 
@@ -0,0 +1,92 @@
1
+ #ste -*- encoding : utf-8 -*-
2
+ # -*- coding: UTF-8 -*-
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe "Blacklight::Configurable" do
6
+
7
+ describe "inheritence" do
8
+ before(:all) do
9
+ module TestCaseInheritence
10
+ class Parent
11
+ include Blacklight::Configurable
12
+
13
+ blacklight_config.configure do |config|
14
+ config.list = [1,2,3]
15
+ end
16
+ end
17
+
18
+ class Child < Parent
19
+ end
20
+ end
21
+ end
22
+ it "should inherit the configuration when subclassed" do
23
+ TestCaseInheritence::Child.blacklight_config.list.should include(1,2,3)
24
+ end
25
+
26
+ it "inherited version should be a deep copy, not original" do
27
+ TestCaseInheritence::Child.blacklight_config.should_not be(TestCaseInheritence::Parent.blacklight_config)
28
+
29
+ TestCaseInheritence::Child.blacklight_config.list << "child_only"
30
+
31
+
32
+ TestCaseInheritence::Child.blacklight_config.list.should include("child_only")
33
+ TestCaseInheritence::Parent.blacklight_config.list.should_not include("child_only")
34
+ end
35
+ end
36
+
37
+ describe "default configuration" do
38
+ before(:each) do
39
+ Blacklight::Configurable.default_configuration = nil
40
+ end
41
+
42
+ after do
43
+ Blacklight::Configurable.default_configuration = nil
44
+ end
45
+
46
+ it "should load an empty configuration" do
47
+ a = Class.new
48
+ a.send(:include, Blacklight::Configurable)
49
+
50
+ a.blacklight_config.default_solr_params.should be_empty
51
+ end
52
+
53
+ it "should allow the user to provide a default configuration" do
54
+ a = Class.new
55
+
56
+ Blacklight::Configurable.default_configuration = Blacklight::Configuration.new :a => 1
57
+
58
+ a.send(:include, Blacklight::Configurable)
59
+ a.blacklight_config.a.should == 1
60
+ end
61
+
62
+ it "has configure_blacklight convenience method" do
63
+ klass = Class.new
64
+ klass.send(:include, Blacklight::Configurable)
65
+
66
+ klass.configure_blacklight do |config|
67
+ config.my_key = 'value'
68
+ end
69
+
70
+ klass.blacklight_config.my_key.should == 'value'
71
+ end
72
+
73
+ it "allows instance to set it's own config seperate from class" do
74
+ # this is built into class_attribute; we spec it both to document it,
75
+ # and to ensure we preserve this feature if we change implementation
76
+ # to not use class_attribute
77
+ klass = Class.new
78
+ klass.send(:include, Blacklight::Configurable)
79
+ klass.blacklight_config.foo = "bar"
80
+
81
+ instance = klass.new
82
+
83
+ instance.blacklight_config = Blacklight::Configuration.new
84
+
85
+ instance.blacklight_config.should_not == klass.blacklight_config
86
+ instance.blacklight_config.foo.should be_nil
87
+ klass.blacklight_config.foo.should == "bar"
88
+ end
89
+
90
+ end
91
+ end
92
+
@@ -0,0 +1,295 @@
1
+ #ste -*- encoding : utf-8 -*-
2
+ # -*- coding: UTF-8 -*-
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe "Blacklight::Configuration" do
6
+
7
+ before(:each) do
8
+ @config = Blacklight::Configuration.new
9
+ end
10
+
11
+ it "should support arbitrary configuration values" do
12
+ @config.a = 1
13
+
14
+ @config.a.should == 1
15
+ @config[:a].should == 1
16
+ end
17
+
18
+ describe "initialization" do
19
+ it "should be an OpenStructWithHashAccess" do
20
+ @config.should be_a_kind_of Blacklight::OpenStructWithHashAccess
21
+ end
22
+
23
+ it "should accept a block for configuration" do
24
+ config = Blacklight::Configuration.new(:a => 1) { |c| c.a = 2 }
25
+
26
+ config.a.should == 2
27
+
28
+ config.configure { |c| c.a = 3 }
29
+
30
+ config.a.should == 3
31
+ end
32
+ end
33
+
34
+ describe "defaults" do
35
+ it "should have a hash of default rsolr query parameters" do
36
+ @config.default_solr_params.should be_a_kind_of Hash
37
+ end
38
+ it "should have openstruct values for show and index parameters" do
39
+ @config.show.should be_a_kind_of OpenStruct
40
+ @config.index.should be_a_kind_of OpenStruct
41
+ end
42
+
43
+ it "should have ordered hashes for field configuration" do
44
+ @config.facet_fields.should be_a_kind_of ActiveSupport::OrderedHash
45
+ @config.index_fields.should be_a_kind_of ActiveSupport::OrderedHash
46
+ @config.show_fields.should be_a_kind_of ActiveSupport::OrderedHash
47
+ @config.search_fields.should be_a_kind_of ActiveSupport::OrderedHash
48
+ @config.show_fields.should be_a_kind_of ActiveSupport::OrderedHash
49
+ @config.search_fields.should be_a_kind_of ActiveSupport::OrderedHash
50
+ @config.sort_fields.should be_a_kind_of ActiveSupport::OrderedHash
51
+ end
52
+ end
53
+
54
+ describe "spell_max" do
55
+ it "should default to 5" do
56
+ Blacklight::Configuration.new.spell_max.should == 5
57
+ end
58
+
59
+ it "should accept config'd value" do
60
+ Blacklight::Configuration.new(:spell_max => 10).spell_max.should == 10
61
+ end
62
+ end
63
+
64
+ describe "inheritable_copy" do
65
+ it "should provide a deep copy of the configuration" do
66
+ config_copy = @config.inheritable_copy
67
+ config_copy.a = 1
68
+
69
+ @mock_facet = Blacklight::Configuration::FacetField.new
70
+ config_copy.add_facet_field "dummy_field", @mock_facet
71
+
72
+ @config.a.should be_nil
73
+ @config.facet_fields.should_not include(@mock_facet)
74
+ end
75
+ end
76
+
77
+ describe "add_facet_field" do
78
+ it "should accept field name and hash form arg" do
79
+ @config.add_facet_field('format', :label => "Format", :limit => true)
80
+
81
+ @config.facet_fields["format"].should_not be_nil
82
+ @config.facet_fields["format"]["label"].should == "Format"
83
+ @config.facet_fields["format"]["limit"].should == true
84
+ end
85
+
86
+ it "should accept FacetField obj arg" do
87
+ @config.add_facet_field("format", Blacklight::Configuration::FacetField.new( :label => "Format"))
88
+
89
+ @config.facet_fields["format"].should_not be_nil
90
+ @config.facet_fields["format"]["label"].should == "Format"
91
+ end
92
+
93
+ it "should accept field name and block form" do
94
+ @config.add_facet_field("format") do |facet|
95
+ facet.label = "Format"
96
+ facet.limit = true
97
+ end
98
+
99
+ @config.facet_fields["format"].should_not be_nil
100
+ @config.facet_fields["format"].limit.should == true
101
+ end
102
+
103
+ it "should accept block form" do
104
+ @config.add_facet_field do |facet|
105
+ facet.field = "format"
106
+ facet.label = "Format"
107
+ end
108
+
109
+ @config.facet_fields['format'].should_not be_nil
110
+ end
111
+
112
+ it "should accept a configuration hash" do
113
+ @config.add_facet_field :field => 'format', :label => 'Format'
114
+ @config.facet_fields['format'].should_not be_nil
115
+ end
116
+
117
+ it "should accept array form" do
118
+ @config.add_facet_field([{ :field => 'format', :label => 'Format'}, { :field => 'publication_date', :label => 'Publication Date' }])
119
+
120
+ @config.facet_fields.length.should == 2
121
+ end
122
+
123
+ it "should create default label from titleized solr field" do
124
+ @config.add_facet_field("publication_date")
125
+
126
+ @config.facet_fields["publication_date"].label.should == "Publication Date"
127
+ end
128
+
129
+ it "should raise on nil solr field name" do
130
+ lambda { @config.add_facet_field(nil) }.should raise_error ArgumentError
131
+ end
132
+
133
+ end
134
+
135
+ describe "add_index_field" do
136
+ it "takes hash form" do
137
+ @config.add_index_field("title_display", :label => "Title")
138
+
139
+ @config.index_fields["title_display"].should_not be_nil
140
+ @config.index_fields["title_display"].label.should == "Title"
141
+ end
142
+ it "takes IndexField param" do
143
+ @config.add_index_field("title_display", Blacklight::Configuration::IndexField.new(:field => "title_display", :label => "Title"))
144
+
145
+ @config.index_fields["title_display"].should_not be_nil
146
+ @config.index_fields["title_display"].label.should == "Title"
147
+ end
148
+ it "takes block form" do
149
+ @config.add_index_field("title_display") do |field|
150
+ field.label = "Title"
151
+ end
152
+ @config.index_fields["title_display"].should_not be_nil
153
+ @config.index_fields["title_display"].label.should == "Title"
154
+ end
155
+
156
+ it "creates default label from titleized field" do
157
+ @config.add_index_field("title_display")
158
+
159
+ @config.index_fields["title_display"].label.should == "Title Display"
160
+ end
161
+
162
+ it "should raise on nil solr field name" do
163
+ lambda { @config.add_index_field(nil) }.should raise_error ArgumentError
164
+ end
165
+
166
+ end
167
+
168
+ describe "add_show_field" do
169
+ it "takes hash form" do
170
+ @config.add_show_field("title_display", :label => "Title")
171
+
172
+ @config.show_fields["title_display"].should_not be_nil
173
+ @config.show_fields["title_display"].label.should == "Title"
174
+ end
175
+ it "takes ShowField argument" do
176
+ @config.add_show_field("title_display", Blacklight::Configuration::ShowField.new(:field => "title_display", :label => "Title"))
177
+
178
+ @config.show_fields["title_display"].should_not be_nil
179
+ @config.show_fields["title_display"].label.should == "Title"
180
+ end
181
+ it "takes block form" do
182
+ @config.add_show_field("title_display") do |f|
183
+ f.label = "Title"
184
+ end
185
+
186
+ @config.show_fields["title_display"].should_not be_nil
187
+ @config.show_fields["title_display"].label.should == "Title"
188
+ end
189
+
190
+ it "creates default label humanized from field" do
191
+ @config.add_show_field("my_custom_field")
192
+
193
+ @config.show_fields["my_custom_field"].label.should == "My Custom Field"
194
+ end
195
+
196
+ it "should raise on nil solr field name" do
197
+ lambda { @config.add_show_field(nil) }.should raise_error ArgumentError
198
+ end
199
+
200
+ end
201
+
202
+
203
+ describe "add_search_field" do
204
+ it "should accept hash form" do
205
+ c = Blacklight::Configuration.new
206
+
207
+ c.add_search_field("my_search_type",
208
+ :key => "my_search_type",
209
+ :solr_parameters => { :qf => "my_field_qf^10" },
210
+ :solr_local_parameters => { :pf=>"$my_field_pf"})
211
+
212
+ field = c.search_fields["my_search_type"]
213
+
214
+ field.should_not be_nil
215
+
216
+
217
+ field.solr_parameters.should_not be_nil
218
+ field.solr_local_parameters.should_not be_nil
219
+
220
+
221
+ end
222
+
223
+ it "should accept block form" do
224
+ c = Blacklight::Configuration.new
225
+
226
+ c.add_search_field("some_field") do |field|
227
+ field.solr_parameters = {:qf => "solr_field^10"}
228
+ field.solr_local_parameters = {:pf => "$some_field_pf"}
229
+ end
230
+
231
+ f = c.search_fields["some_field"]
232
+
233
+ f.should_not be_nil
234
+ f.solr_parameters.should_not be_nil
235
+ f.solr_local_parameters.should_not be_nil
236
+ end
237
+
238
+ it "should accept SearchField object" do
239
+ c = Blacklight::Configuration.new
240
+
241
+ f = Blacklight::Configuration::SearchField.new( :foo => "bar")
242
+
243
+ c.add_search_field("foo", f)
244
+
245
+ c.search_fields["foo"].should_not be_nil
246
+ end
247
+
248
+ it "should raise on nil key" do
249
+ lambda {@config.add_search_field(nil, :foo => "bar")}.should raise_error ArgumentError
250
+ end
251
+
252
+ it "creates default label from titleized field key" do
253
+ @config.add_search_field("author_name")
254
+
255
+ @config.search_fields["author_name"].label.should == "Author Name"
256
+ end
257
+
258
+
259
+ end
260
+
261
+ describe "add_sort_field" do
262
+ it "should take a hash" do
263
+ @config.add_sort_field("score desc, pub_date_sort desc, title_sort asc", :label => "relevance")
264
+
265
+
266
+ @config.sort_fields.values.find{|f| f.label == "relevance"}.should_not be_nil
267
+ end
268
+
269
+ it "should take a SortField object" do
270
+ @config.add_sort_field(Blacklight::Configuration::SortField.new(:label => "relevance", :sort => "score desc, pub_date_sort desc, title_sort asc"
271
+ ))
272
+ @config.sort_fields.values.find{|f| f.label == "relevance"}.should_not be_nil
273
+ end
274
+
275
+ it "should take block form" do
276
+ @config.add_sort_field do |field|
277
+ field.label = "relevance"
278
+ field.sort = "score desc, pub_date_sort desc, title_sort asc"
279
+ end
280
+
281
+ @config.sort_fields.values.find{|f| f.label == "relevance"}.should_not be_nil
282
+
283
+ end
284
+ end
285
+
286
+ describe "#default_search_field" do
287
+ it "should use the field with a :default key" do
288
+ @config.add_search_field('search_field_1')
289
+ @config.add_search_field('search_field_2', :default => true)
290
+
291
+ @config.default_search_field.key.should == 'search_field_2'
292
+ end
293
+ end
294
+
295
+ end