Skip to content

Commit

Permalink
check the arity of #document_partial_name before calling the new 2-ar…
Browse files Browse the repository at this point in the history
…g form
  • Loading branch information
cbeer committed Mar 12, 2014
1 parent 0954083 commit 616a6e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions spec/helpers/blacklight_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 616a6e3

Please sign in to comment.