Skip to content

Commit

Permalink
Merge pull request rails#6649 from route/logger_in_metal_3_2
Browse files Browse the repository at this point in the history
Logger in metal backport for 3.2
  • Loading branch information
carlosantoniodasilva committed Jun 19, 2012
2 parents ffcecf2 + 4717c2f commit 2363aaf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions actionpack/lib/action_view/helpers/controller_helper.rb
Expand Up @@ -10,14 +10,16 @@ module ControllerHelper #:nodoc:
delegate :request_forgery_protection_token, :params, :session, :cookies, :response, :headers,
:flash, :action_name, :controller_name, :controller_path, :to => :controller

delegate :logger, :to => :controller, :allow_nil => true

def assign_controller(controller)
if @_controller = controller
@_request = controller.request if controller.respond_to?(:request)
@_config = controller.config.inheritable_copy if controller.respond_to?(:config)
end
end

def logger
controller.logger if controller.respond_to?(:logger)
end
end
end
end
17 changes: 17 additions & 0 deletions actionpack/test/controller/render_test.rb
Expand Up @@ -718,6 +718,14 @@ def determine_layout
end
end

class MetalTestController < ActionController::Metal
include ActionController::Rendering

def accessing_logger_in_template
render :inline => "<%= logger.class %>"
end
end

class RenderTest < ActionController::TestCase
tests TestController

Expand Down Expand Up @@ -1583,3 +1591,12 @@ def test_last_modified_works_with_less_than_too
assert_response :success
end
end

class MetalRenderTest < ActionController::TestCase
tests MetalTestController

def test_access_to_logger_in_view
get :accessing_logger_in_template
assert_equal "NilClass", @response.body
end
end

0 comments on commit 2363aaf

Please sign in to comment.