Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport config.action_controller.include_all_helpers to 3-0-stable #1874

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_controller/metal/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions railties/test/application/initializers/frameworks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 []
Expand Down