Permalink
Browse files

Avoid leak into controller's action_methods

  • Loading branch information...
1 parent dba6a07 commit 14c196e5a3f78ea4672b691a09ba60524b31fb73 @printercu printercu committed with Max Melentiev Apr 18, 2013
Showing with 7 additions and 0 deletions.
  1. +1 −0 actionpack/lib/abstract_controller/layouts.rb
  2. +6 −0 actionpack/test/abstract/layouts_test.rb
@@ -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)

0 comments on commit 14c196e

Please sign in to comment.