Skip to content
Browse files

Ensure NoMethodError propogates correctly.

When a delegated method calls a non-existant method the correct
NoMethodError should be called. If the NoMethodError is swallowed by
the decorator it can cause problems with BDD workflow.
  • Loading branch information...
1 parent 51b0309 commit 7168e2ca7419a6138543be34107de6f15bd6bbbb @tooky tooky committed Jan 31, 2012
Showing with 19 additions and 2 deletions.
  1. +3 −2 lib/draper/base.rb
  2. +12 −0 spec/draper/base_spec.rb
  3. +4 −0 spec/support/samples/product.rb
View
5 lib/draper/base.rb
@@ -197,8 +197,9 @@ def method_missing(method, *args, &block)
model.send(method, *args, &block)
end
self.send(method, *args, &block)
- rescue NoMethodError
- super
+ rescue NoMethodError => no_method_error
+ super if no_method_error.name == method
+ raise no_method_error
end
else
super
View
12 spec/draper/base_spec.rb
@@ -551,6 +551,18 @@ class DecoratorWithDeniesAndAllows < Draper::Base
subject.hello_world
end
end
+
+ context "when the delegated method calls a non-existant method" do
+ it "raises the correct NoMethodError" do
+ begin
+ subject.some_action
+ rescue NoMethodError => e
+ e.name.should_not == :some_action
+ else
+ fail("No exception raised")
+ end
+ end
+ end
end
describe "#kind_of?" do
View
4 spec/support/samples/product.rb
@@ -45,6 +45,10 @@ def title
"Sample Title"
end
+ def some_action
+ self.nonexistant_method
+ end
+
def block
yield
end

0 comments on commit 7168e2c

Please sign in to comment.
Something went wrong with that request. Please try again.