Skip to content

Commit 8d25420

Browse files
committed
use facet_display_value in render_facet_value
1 parent 0ff5a49 commit 8d25420

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

app/helpers/blacklight/facets_helper_behavior.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def facet_partial_name(display_facet = nil)
103103
# options consist of:
104104
# :suppress_link => true # do not make it a link, used for an already selected value for instance
105105
def render_facet_value(facet_solr_field, item, options ={})
106-
(link_to_unless(options[:suppress_link], item.label, add_facet_params_and_redirect(facet_solr_field, item), :class=>"facet_select") + " " + render_facet_count(item.hits)).html_safe
106+
(link_to_unless(options[:suppress_link], facet_display_value(facet_solr_field, item), add_facet_params_and_redirect(facet_solr_field, item), :class=>"facet_select") + " " + render_facet_count(item.hits)).html_safe
107107
end
108108

109109
# Standard display of a SELECTED facet value, no link, special span
@@ -217,7 +217,11 @@ def facet_in_params?(field, item)
217217
def facet_display_value field, item
218218
facet_config = facet_configuration_for_field(field)
219219

220-
value = facet_value_for_facet_item(item)
220+
value = if item.respond_to? :label
221+
value = item.label
222+
else
223+
facet_value_for_facet_item(item)
224+
end
221225

222226
display_label = case
223227
when facet_config.helper_method

spec/helpers/facets_helper_spec.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,25 @@
364364

365365
end
366366

367+
describe "render_facet_value" do
368+
it "should use facet_display_value" do
369+
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(mock(:query => nil, :date => nil, :helper_method => nil, :single => false))
370+
371+
helper.should_receive(:facet_display_value).and_return('Z')
372+
helper.should_receive(:add_facet_params_and_redirect).and_return('link')
373+
helper.render_facet_value('simple_field', mock(:value => 'A', :hits => 10)).should == "<a href=\"link\" class=\"facet_select\">Z</a> <span class=\"count\">10</span>"
374+
end
375+
376+
377+
it "should suppress the link" do
378+
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(mock(:query => nil, :date => nil, :helper_method => nil, :single => false))
379+
380+
helper.should_receive(:facet_display_value).and_return('Z')
381+
helper.should_receive(:add_facet_params_and_redirect).and_return('link')
382+
helper.render_facet_value('simple_field', mock(:value => 'A', :hits => 10), :suppress_link => true).should == "Z <span class=\"count\">10</span>"
383+
end
384+
end
385+
367386
describe "#facet_display_value" do
368387
it "should just be the facet value for an ordinary facet" do
369388
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(mock(:query => nil, :date => nil, :helper_method => nil))
@@ -374,7 +393,7 @@
374393
helper.stub(:facet_configuration_for_field).with('helper_field').and_return(mock(:query => nil, :date => nil, :helper_method => :my_facet_value_renderer))
375394

376395
helper.should_receive(:my_facet_value_renderer).with('qwerty').and_return('abc')
377-
396+
378397
helper.facet_display_value('helper_field', 'qwerty').should == 'abc'
379398
end
380399

0 commit comments

Comments
 (0)