Skip to content

Commit

Permalink
Remove deprecated default_charset= from AC::Base
Browse files Browse the repository at this point in the history
This should be set globally as a configuration, using
`config.action_dispatch.default_charset` instead
  • Loading branch information
carlosantoniodasilva committed Jan 17, 2012
1 parent 67c96ab commit cb650a5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 0 additions & 4 deletions actionpack/lib/action_controller/metal/compatibility.rb
Expand Up @@ -4,10 +4,6 @@ module Compatibility

# Temporary hax
included do
class << self
delegate :default_charset=, :to => "ActionDispatch::Response"
end

self.protected_instance_variables = [
:@_status, :@_headers, :@_params, :@_env, :@_response, :@_request,
:@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_dispatch/railtie.rb
Expand Up @@ -11,6 +11,7 @@ class Railtie < Rails::Railtie
config.action_dispatch.ignore_accept_header = false
config.action_dispatch.rescue_templates = { }
config.action_dispatch.rescue_responses = { }
config.action_dispatch.default_charset = nil

config.action_dispatch.rack_cache = {
:metastore => "rails:/",
Expand All @@ -21,7 +22,7 @@ class Railtie < Rails::Railtie
initializer "action_dispatch.configure" do |app|
ActionDispatch::Http::URL.tld_length = app.config.action_dispatch.tld_length
ActionDispatch::Request.ignore_accept_header = app.config.action_dispatch.ignore_accept_header
ActionDispatch::Response.default_charset = app.config.encoding
ActionDispatch::Response.default_charset = app.config.action_dispatch.default_charset || app.config.encoding

ActionDispatch::ExceptionWrapper.rescue_responses.merge!(config.action_dispatch.rescue_responses)
ActionDispatch::ExceptionWrapper.rescue_templates.merge!(config.action_dispatch.rescue_templates)
Expand Down
8 changes: 4 additions & 4 deletions actionpack/test/controller/content_type_test.rb
Expand Up @@ -68,12 +68,12 @@ def test_render_defaults
end

def test_render_changed_charset_default
OldContentTypeController.default_charset = "utf-16"
ActionDispatch::Response.default_charset = "utf-16"
get :render_defaults
assert_equal "utf-16", @response.charset
assert_equal Mime::HTML, @response.content_type
ensure
OldContentTypeController.default_charset = "utf-8"
ActionDispatch::Response.default_charset = "utf-8"
end

# :ported:
Expand Down Expand Up @@ -105,12 +105,12 @@ def test_nil_charset_from_body
end

def test_nil_default_for_erb
OldContentTypeController.default_charset = nil
ActionDispatch::Response.default_charset = nil
get :render_default_for_erb
assert_equal Mime::HTML, @response.content_type
assert_nil @response.charset, @response.headers.inspect
ensure
OldContentTypeController.default_charset = "utf-8"
ActionDispatch::Response.default_charset = "utf-8"
end

def test_default_for_erb
Expand Down
8 changes: 8 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -287,6 +287,14 @@ def index
assert_equal Rails.application, ActionDispatch.test_app
end

test "sets ActionDispatch::Response.default_charset" do
make_basic_app do |app|
app.config.action_dispatch.default_charset = "utf-16"
end

assert_equal "utf-16", ActionDispatch::Response.default_charset
end

test "sets all Active Record models to whitelist all attributes by default" do
add_to_config <<-RUBY
config.active_record.whitelist_attributes = true
Expand Down

0 comments on commit cb650a5

Please sign in to comment.