Avoid leak into controller's action_methods

This commit is contained in:
printercu 2013-04-18 17:56:21 +04:00 committed by Max Melentiev
parent dba6a078ee
commit 14c196e5a3
2 changed files with 7 additions and 0 deletions

@ -309,6 +309,7 @@ def _write_layout_method # :nodoc:
RUBY
when Proc
define_method :_layout_from_proc, &_layout
protected :_layout_from_proc
<<-RUBY
result = _layout_from_proc(#{_layout.arity == 0 ? '' : 'self'})
return #{default_behavior} if result.nil?

@ -8,6 +8,8 @@ class Base < AbstractController::Base
include AbstractController::Rendering
include AbstractController::Layouts
abstract!
self.view_paths = [ActionView::FixtureResolver.new(
"layouts/hello.erb" => "With String <%= yield %>",
"layouts/hello_override.erb" => "With Override <%= yield %>",
@ -251,6 +253,10 @@ class TestBase < ActiveSupport::TestCase
assert_equal "Hello nil!", controller.response_body
end
test "when layout is specified as a proc, do not leak any methods into controller's action_methods" do
assert_equal Set.new(['index']), WithProc.action_methods
end
test "when layout is specified as a proc, call it and use the layout returned" do
controller = WithProc.new
controller.process(:index)