Skip to content

Commit 7ee2f79

Browse files
committed
Merge pull request #936 from projectblacklight/use_facet_field_label
render_filter_element should use facet_field_label for i18n. Fixes #935
2 parents 4af89a1 + ed1ba8a commit 7ee2f79

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

app/helpers/blacklight/render_constraints_helper_behavior.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def render_filter_element(facet, values, localized_params)
6868

6969
safe_join(values.map do |val|
7070
next if val.blank? # skip empty string
71-
render_constraint_element( blacklight_config.facet_fields[facet].label,
72-
facet_display_value(facet, val),
71+
render_constraint_element( facet_field_label(facet), facet_display_value(facet, val),
7372
:remove => search_action_path(remove_facet_params(facet, val, localized_params)),
7473
:classes => ["filter", "filter-" + facet.parameterize]
7574
)

spec/helpers/render_constraints_helper_spec.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
describe RenderConstraintsHelper do
44

5+
let(:config) do
6+
Blacklight::Configuration.new do |config|
7+
config.add_facet_field 'type'
8+
end
9+
end
10+
511
before do
612
# the helper methods below infer paths from the current route
713
controller.request.path_parameters["controller"] = 'catalog'
@@ -18,29 +24,25 @@
1824

1925
describe '#render_filter_element' do
2026
before do
21-
@config = Blacklight::Configuration.new do |config|
22-
config.add_facet_field 'type'
23-
end
24-
helper.stub(:blacklight_config => @config)
27+
allow(helper).to receive(:blacklight_config).and_return(config)
28+
expect(helper).to receive(:facet_field_label).with('type').and_return("Item Type")
2529
end
30+
subject { helper.render_filter_element('type', ['journal'], {:q=>'biz'}) }
31+
2632
it "should have a link relative to the current url" do
27-
result = helper.render_filter_element('type', ['journal'], {:q=>'biz'})
28-
expect(result).to have_link "Remove constraint Type: journal", href: "/catalog?q=biz"
33+
expect(subject).to have_link "Remove constraint Item Type: journal", href: "/catalog?q=biz"
34+
expect(subject).to have_selector ".filterName", text: 'Item Type'
2935
end
3036
end
3137

3238
describe "#render_constraints_filters" do
3339
before do
34-
@config = Blacklight::Configuration.new do |config|
35-
config.add_facet_field 'type'
36-
end
37-
helper.stub(:blacklight_config => @config)
40+
allow(helper).to receive(:blacklight_config).and_return(config)
3841
end
42+
subject { helper.render_constraints_filters(:f=>{'type'=>['']}) }
3943

4044
it "should render nothing for empty facet limit param" do
41-
rendered = helper.render_constraints_filters(:f=>{'type'=>['']})
42-
expect(rendered).to be_blank
45+
expect(subject).to be_blank
4346
end
4447
end
45-
4648
end

0 commit comments

Comments
 (0)