From 616a6e318d5b878b4feb27b265f2ef21c27d8fb1 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 12 Mar 2014 10:04:18 -0700 Subject: [PATCH] check the arity of #document_partial_name before calling the new 2-arg form --- .../blacklight/blacklight_helper_behavior.rb | 7 ++++++- spec/helpers/blacklight_helper_spec.rb | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/helpers/blacklight/blacklight_helper_behavior.rb b/app/helpers/blacklight/blacklight_helper_behavior.rb index c55e6b6b36..e24359a7c3 100644 --- a/app/helpers/blacklight/blacklight_helper_behavior.rb +++ b/app/helpers/blacklight/blacklight_helper_behavior.rb @@ -472,7 +472,12 @@ def render_document_partials(doc, partials = [], locals ={}) # @param [String] base name for the partial # @param [Hash] locales to pass through to the partials def render_document_partial(doc, base_name, locals = {}) - format = document_partial_name(doc, base_name) + format = if method(:document_partial_name).arity == 1 + 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'" + document_partial_name(doc) + else + document_partial_name(doc, base_name) + end document_partial_path_templates.each do |str| # XXX rather than handling this logic through exceptions, maybe there's a Rails internals method diff --git a/spec/helpers/blacklight_helper_spec.rb b/spec/helpers/blacklight_helper_spec.rb index ce9edf930a..124a3588ed 100644 --- a/spec/helpers/blacklight_helper_spec.rb +++ b/spec/helpers/blacklight_helper_spec.rb @@ -445,6 +445,27 @@ def mock_document_app_helper_url *args expect(helper.should_show_spellcheck_suggestions? response).to be_false end end + + describe "#render_document_partials" do + let(:doc) { double } + before do + helper.stub(document_partial_path_templates: []) + end + + it "should get the document format from document_partial_name" do + helper.should_receive(:document_partial_name).with(doc, :xyz) + helper.render_document_partial(doc, :xyz) + end + + context "with a 1-arg form of document_partial_name" do + it "should only call the 1-arg form of the document_partial_name" do + helper.should_receive(:method).with(:document_partial_name).and_return(double(arity: 1)) + helper.should_receive(:document_partial_name).with(doc) + Deprecation.should_receive(:warn) + helper.render_document_partial(doc, nil) + end + end + end describe "#document_partial_name" do let(:blacklight_config) { Blacklight::Configuration.new }