Skip to content

Commit a6b11b9

Browse files
committed
#add_show_tools_partial should not overwrite an existing method
1 parent 7921f87 commit a6b11b9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/blacklight/catalog/component_configuration.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ module ClassMethods
3434
# The proc will receive the action configuration and the document or documents for the action.
3535
def add_show_tools_partial name, opts = {}
3636
blacklight_config.add_show_tools_partial(name, opts)
37+
3738
define_method name do
3839
@response, @documents = action_documents
40+
3941
if request.post? and
4042
opts[:callback] and
4143
(opts[:validator].blank? || self.send(opts[:validator]))
@@ -54,7 +56,7 @@ def add_show_tools_partial name, opts = {}
5456
format.js { render :layout => false }
5557
end
5658
end
57-
end
59+
end unless method_defined? name
5860
end
5961

6062
##
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Blacklight::Catalog::ComponentConfiguration do
4+
subject do
5+
Class.new do
6+
include Blacklight::Configurable
7+
include Blacklight::Catalog::ComponentConfiguration
8+
9+
def some_existing_action
10+
1
11+
end
12+
end
13+
end
14+
15+
describe ".add_show_tools_partial" do
16+
it "should define an action method" do
17+
subject.add_show_tools_partial :xyz
18+
expect(subject.new).to respond_to :xyz
19+
end
20+
21+
it "should not replace an existing method" do
22+
subject.add_show_tools_partial :some_existing_action
23+
expect(subject.new.some_existing_action).to eq 1
24+
end
25+
end
26+
27+
28+
29+
end

0 commit comments

Comments
 (0)