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.
This commit is contained in:
parent
51b03097f2
commit
7168e2ca74
|
@ -197,8 +197,9 @@ module Draper
|
|||
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
|
||||
|
|
|
@ -551,6 +551,18 @@ describe Draper::Base do
|
|||
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
|
||||
|
|
|
@ -45,6 +45,10 @@ class Product < ActiveRecord::Base
|
|||
"Sample Title"
|
||||
end
|
||||
|
||||
def some_action
|
||||
self.nonexistant_method
|
||||
end
|
||||
|
||||
def block
|
||||
yield
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue