Skip to content

Commit f0be592

Browse files
committed
Merge pull request #835 from projectblacklight/arity-check
check the arity of #document_partial_name before calling the new 2-arg form
2 parents a65fb7d + 616a6e3 commit f0be592

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

app/helpers/blacklight/blacklight_helper_behavior.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,12 @@ def render_document_partials(doc, partials = [], locals ={})
472472
# @param [String] base name for the partial
473473
# @param [Hash] locales to pass through to the partials
474474
def render_document_partial(doc, base_name, locals = {})
475-
format = document_partial_name(doc, base_name)
475+
format = if method(:document_partial_name).arity == 1
476+
Deprecation.warn self, "The #document_partial_name with a single argument is deprecated. Update your override to include a second argument for the 'base name'"
477+
document_partial_name(doc)
478+
else
479+
document_partial_name(doc, base_name)
480+
end
476481

477482
document_partial_path_templates.each do |str|
478483
# XXX rather than handling this logic through exceptions, maybe there's a Rails internals method

spec/helpers/blacklight_helper_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,27 @@ def mock_document_app_helper_url *args
445445
expect(helper.should_show_spellcheck_suggestions? response).to be_false
446446
end
447447
end
448+
449+
describe "#render_document_partials" do
450+
let(:doc) { double }
451+
before do
452+
helper.stub(document_partial_path_templates: [])
453+
end
454+
455+
it "should get the document format from document_partial_name" do
456+
helper.should_receive(:document_partial_name).with(doc, :xyz)
457+
helper.render_document_partial(doc, :xyz)
458+
end
459+
460+
context "with a 1-arg form of document_partial_name" do
461+
it "should only call the 1-arg form of the document_partial_name" do
462+
helper.should_receive(:method).with(:document_partial_name).and_return(double(arity: 1))
463+
helper.should_receive(:document_partial_name).with(doc)
464+
Deprecation.should_receive(:warn)
465+
helper.render_document_partial(doc, nil)
466+
end
467+
end
468+
end
448469

449470
describe "#document_partial_name" do
450471
let(:blacklight_config) { Blacklight::Configuration.new }

0 commit comments

Comments
 (0)