Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #145 from avdgaag/fix-for-kernel-array

Bugfix: do not confuse Kernel#Array
  • Loading branch information...
commit 89126e48d64a3211526187021802264a0eb069c4 2 parents 279ea02 + f1beada
@steveklabnik steveklabnik authored
Showing with 12 additions and 4 deletions.
  1. +8 −4 lib/draper/base.rb
  2. +4 −0 spec/draper/base_spec.rb
View
12 lib/draper/base.rb
@@ -204,11 +204,15 @@ def respond_to?(method, include_private = false)
def method_missing(method, *args, &block)
super unless allow?(method)
- self.class.send :define_method, method do |*args, &block|
- model.send method, *args, &block
- end
+ if model.respond_to?(method)
+ self.class.send :define_method, method do |*args, &block|
+ model.send method, *args, &block
+ end
- send method, *args, &block
+ send method, *args, &block
+ else
+ super
+ end
rescue NoMethodError => no_method_error
super if no_method_error.name == method
View
4 spec/draper/base_spec.rb
@@ -622,6 +622,10 @@ class DecoratorWithDeniesAndAllows < Draper::Base
end
context "when the delegated method calls a non-existant method" do
+ it 'should not try to delegate to non-existant methods to not confuse Kernel#Array' do
+ Array(subject).should be_kind_of(Array)
+ end
+
it "raises the correct NoMethodError" do
begin
subject.some_action
Please sign in to comment.
Something went wrong with that request. Please try again.