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)
|
model.send(method, *args, &block)
|
||||||
end
|
end
|
||||||
self.send(method, *args, &block)
|
self.send(method, *args, &block)
|
||||||
rescue NoMethodError
|
rescue NoMethodError => no_method_error
|
||||||
super
|
super if no_method_error.name == method
|
||||||
|
raise no_method_error
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
|
|
@ -551,6 +551,18 @@ describe Draper::Base do
|
||||||
subject.hello_world
|
subject.hello_world
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe "#kind_of?" do
|
describe "#kind_of?" do
|
||||||
|
|
|
@ -45,6 +45,10 @@ class Product < ActiveRecord::Base
|
||||||
"Sample Title"
|
"Sample Title"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def some_action
|
||||||
|
self.nonexistant_method
|
||||||
|
end
|
||||||
|
|
||||||
def block
|
def block
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue