Permalink
Browse files

Add config.action_controller.include_all_helpers, by default it is se…

…t to true.

In older rails versions there was a way to use only helpers from
helper file corresponding to current controller and you could also
include all helpers by saying 'helper :all' in controller. This config
allows to return to older behavior by setting it to false.
  • Loading branch information...
1 parent 87bbf48 commit ffcd3039138004c142849150445836811e02bc80 @drogus drogus committed with Nov 17, 2010
@@ -225,7 +225,7 @@ def self.without_modules(*modules)
def self.inherited(klass)
super
- klass.helper :all if klass.superclass == ActionController::Base
+ klass.helper :all if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
end
require "action_controller/deprecated/base"
@@ -53,8 +53,9 @@ module Helpers
include AbstractController::Helpers
included do
- config_accessor :helpers_path
+ config_accessor :helpers_path, :include_all_helpers
self.helpers_path ||= []
+ self.include_all_helpers = true
end
module ClassMethods
@@ -10,6 +10,10 @@ def setup
FileUtils.rm_rf "#{app_path}/config/environments"
end
+ def app
+ @app ||= Rails.application
+ end
+
def teardown
teardown_app
end
@@ -68,6 +72,67 @@ def notify
assert_equal ["notify"], Foo.action_methods
end
+ test "allows to not load all helpers for controllers" do
+ add_to_config "config.action_controller.include_all_helpers = false"
+
+ app_file "app/controllers/application_controller.rb", <<-RUBY
+ class ApplicationController < ActionController::Base
+ end
+ RUBY
+
+ app_file "app/controllers/foo_controller.rb", <<-RUBY
+ class FooController < ApplicationController
+ def included_helpers
+ render :inline => "<%= from_app_helper -%> <%= from_foo_helper %>"
+ end
+
+ def not_included_helper
+ render :inline => "<%= respond_to?(:from_bar_helper) -%>"
+ end
+ end
+ RUBY
+
+ app_file "app/helpers/application_helper.rb", <<-RUBY
+ module ApplicationHelper
+ def from_app_helper
+ "from_app_helper"
+ end
+ end
+ RUBY
+
+ app_file "app/helpers/foo_helper.rb", <<-RUBY
+ module FooHelper
+ def from_foo_helper
+ "from_foo_helper"
+ end
+ end
+ RUBY
+
+ app_file "app/helpers/bar_helper.rb", <<-RUBY
+ module BarHelper
+ def from_bar_helper
+ "from_bar_helper"
+ end
+ end
+ RUBY
+
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match "/:controller(/:action)"
+ end
+ RUBY
+
+ require "#{app_path}/config/environment"
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get "/foo/included_helpers"
+ assert_equal "from_app_helper from_foo_helper", last_response.body
+
+ get "/foo/not_included_helper"
+ assert_equal "false", last_response.body
+ end
+
# AS
test "if there's no config.active_support.bare, all of ActiveSupport is required" do
use_frameworks []

0 comments on commit ffcd303

Please sign in to comment.