Skip to content

Commit

Permalink
Ensure NoMethodError propogates correctly.
Browse files Browse the repository at this point in the history
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
tooky committed Jan 31, 2012
1 parent 51b0309 commit 7168e2c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/draper/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/draper/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/support/samples/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def title
"Sample Title"
end

def some_action
self.nonexistant_method
end

def block
yield
end
Expand Down

0 comments on commit 7168e2c

Please sign in to comment.