Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 7168e2ca7419a6138543be34107de6f15bd6bbbb 1 parent 51b0309
@tooky tooky authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.