From 85baf07be82b7e4313c6eeeebdd365a6f45fd405 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 8 Nov 2005 08:23:13 +0000 Subject: [PATCH] Controllers with acronyms in their names (e.g. PDFController) require the correct default helper (PDFHelper in file pdf_helper.rb). Closes #2262. Do not raise an exception when default helper is missing; log a debug message instead. It's nice to delete empty helpers. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2938 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 7 +++++ actionpack/lib/action_controller/helpers.rb | 13 +++++++++- actionpack/test/controller/helper_test.rb | 26 +++++++++++++++---- .../test/fixtures/helpers/fun/pdf_helper.rb | 3 +++ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 actionpack/test/fixtures/helpers/fun/pdf_helper.rb diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 8335e6e074..54b414a30e 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,3 +1,10 @@ +*SVN* + +* Do not raise an exception when default helper is missing; log a debug message instead. It's nice to delete empty helpers. [Jeremy Kemper] + +* Controllers with acronyms in their names (e.g. PDFController) require the correct default helper (PDFHelper in file pdf_helper.rb). #2262 [jeff@opendbms.com] + + *1.11.0* (November 7th, 2005) * Added request as instance method to views, so you can do <%= request.env["HTTP_REFERER"] %>, just like you can already access response, session, and the likes [DHH] diff --git a/actionpack/lib/action_controller/helpers.rb b/actionpack/lib/action_controller/helpers.rb index 674c28e6c7..19675605d4 100644 --- a/actionpack/lib/action_controller/helpers.rb +++ b/actionpack/lib/action_controller/helpers.rb @@ -108,12 +108,23 @@ def helper_attr(*attrs) end private + def default_helper_module! + module_name = name.sub(/^Controllers::/, '').sub(/Controller$|$/, 'Helper') + module_path = module_name.split('::').map { |m| m.underscore }.join('/') + require_dependency module_path + helper module_name.constantize + rescue LoadError + logger.debug("#{name}: missing default helper path #{module_path}") if logger + rescue NameError + logger.debug("#{name}: missing default helper module #{module_name}") if logger + end + def inherited_with_helper(child) inherited_without_helper(child) begin child.master_helper_module = Module.new child.master_helper_module.send :include, master_helper_module - child.helper child.controller_path + child.send :default_helper_module! rescue MissingSourceFile => e raise unless e.is_missing?("helpers/#{child.controller_path}_helper") end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index cd48704e3a..6fb67ee38e 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -14,6 +14,14 @@ def render_hello_world def rescue_action(e) raise end end + + class PDFController < ActionController::Base + def test + render :inline => "test: <%= foobar %>" + end + + def rescue_action(e) raise end + end end module LocalAbcHelper @@ -100,11 +108,19 @@ def test_helper_attr end def test_helper_for_nested_controller - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @request.action = "render_hello_world" - - assert_equal "hello: Iz guuut!", Fun::GamesController.process(@request, @response).body + request = ActionController::TestRequest.new + response = ActionController::TestResponse.new + request.action = 'render_hello_world' + + assert_equal 'hello: Iz guuut!', Fun::GamesController.process(request, response).body + end + + def test_helper_for_acronym_controller + request = ActionController::TestRequest.new + response = ActionController::TestResponse.new + request.action = 'test' + + assert_equal 'test: baz', Fun::PDFController.process(request, response).body end private diff --git a/actionpack/test/fixtures/helpers/fun/pdf_helper.rb b/actionpack/test/fixtures/helpers/fun/pdf_helper.rb new file mode 100644 index 0000000000..1890f6c9ec --- /dev/null +++ b/actionpack/test/fixtures/helpers/fun/pdf_helper.rb @@ -0,0 +1,3 @@ +module Fun::PDFHelper + def foobar() 'baz' end +end -- GitLab