Permalink
Browse files

Merge pull request #4497 from carlosantoniodasilva/action-controller-…

…refactor

Action controller refactor - remove Compatibility module
  • Loading branch information...
2 parents 422958f + 96a817f commit ba154bd76fb481d9faca123e988924bd864c0318 @josevalim josevalim committed Jan 17, 2012
Showing with 76 additions and 232 deletions.
  1. +16 −1 actionpack/CHANGELOG.md
  2. +7 −4 actionpack/lib/action_controller/base.rb
  3. +0 −58 actionpack/lib/action_controller/metal/compatibility.rb
  4. +1 −1 actionpack/lib/action_controller/metal/exceptions.rb
  5. +8 −0 actionpack/lib/action_controller/metal/rendering.rb
  6. +1 −1 actionpack/lib/action_controller/metal/streaming.rb
  7. +2 −1 actionpack/lib/action_dispatch/railtie.rb
  8. +1 −0 actionpack/lib/action_view/lookup_context.rb
  9. +0 −2 actionpack/lib/action_view/test_case.rb
  10. +4 −6 actionpack/test/activerecord/active_record_store_test.rb
  11. +0 −4 actionpack/test/controller/assert_select_test.rb
  12. +2 −47 actionpack/test/controller/base_test.rb
  13. +0 −6 actionpack/test/controller/caching_test.rb
  14. +0 −2 actionpack/test/controller/capture_test.rb
  15. +4 −6 actionpack/test/controller/content_type_test.rb
  16. +0 −14 actionpack/test/controller/filters_test.rb
  17. +0 −4 actionpack/test/controller/flash_test.rb
  18. +0 −7 actionpack/test/controller/helper_test.rb
  19. +1 −5 actionpack/test/controller/mime_responds_test.rb
  20. +0 −2 actionpack/test/controller/redirect_test.rb
  21. +6 −10 actionpack/test/controller/render_test.rb
  22. +0 −2 actionpack/test/controller/request_forgery_protection_test.rb
  23. +0 −1 actionpack/test/controller/resources_test.rb
  24. +0 −1 actionpack/test/controller/routing_test.rb
  25. +10 −13 actionpack/test/controller/test_case_test.rb
  26. +0 −8 actionpack/test/controller/view_paths_test.rb
  27. +0 −2 actionpack/test/controller/webservice_test.rb
  28. +2 −2 actionpack/test/dispatch/debug_exceptions_test.rb
  29. +0 −2 actionpack/test/dispatch/session/cache_store_test.rb
  30. +0 −2 actionpack/test/dispatch/session/cookie_store_test.rb
  31. +0 −2 actionpack/test/dispatch/session/mem_cache_store_test.rb
  32. +1 −1 actionpack/test/dispatch/show_exceptions_test.rb
  33. +1 −6 actionpack/test/template/atom_feed_helper_test.rb
  34. +1 −9 actionpack/test/template/url_helper_test.rb
  35. +8 −0 railties/test/application/configuration_test.rb
View
@@ -21,6 +21,21 @@
## Rails 3.2.0 (unreleased) ##
+* Add `config.action_dispatch.default_charset` to configure default charset for ActionDispatch::Response. *Carlos Antonio da Silva*
+
+* Deprecate setting default charset at controller level, use the new `config.action_dispatch.default_charset` instead. *Carlos Antonio da Silva*
+
+* Deprecate ActionController::UnknownAction in favour of AbstractController::ActionNotFound. *Carlos Antonio da Silva*
+
+* Deprecate ActionController::DoubleRenderError in favour of AbstractController::DoubleRenderError. *Carlos Antonio da Silva*
+
+* Deprecate method_missing handling for not found actions, use action_missing instead. *Carlos Antonio da Silva*
+
+* Deprecate ActionController#performed?, check for response_body presence instead. *Carlos Antonio da Silva*
+
+* Deprecate ActionController#rescue_action, ActionController#initialize_template_class, and ActionController#assign_shortcuts.
+ These methods were not being used internally anymore and are going to be removed in Rails 4. *Carlos Antonio da Silva*
+
* Use a BodyProxy instead of including a Module that responds to
close. Closes #4441 if Active Record is disabled assets are delivered
correctly *Santiago Pastorino*
@@ -45,7 +60,7 @@
<%= f.button %>
<% end %>
-* Date helpers accept a new option, `:use_two_digit_numbers = true`, that renders select boxes for months and days with a leading zero without changing the respective values.
+* Date helpers accept a new option, `:use_two_digit_numbers = true`, that renders select boxes for months and days with a leading zero without changing the respective values.
For example, this is useful for displaying ISO8601-style dates such as '2011-08-01'. *Lennart Fridén and Kim Persson*
* Make ActiveSupport::Benchmarkable a default module for ActionController::Base, so the #benchmark method is once again available in the controller context like it used to be *DHH*
@@ -116,7 +116,7 @@ module ActionController
#
# Title: <%= @post.title %>
#
- # You don't have to rely on the automated rendering. For example, actions that could result in the rendering of different templates
+ # You don't have to rely on the automated rendering. For example, actions that could result in the rendering of different templates
# will use the manual rendering methods:
#
# def search
@@ -133,7 +133,7 @@ module ActionController
# == Redirects
#
# Redirects are used to move from one action to another. For example, after a <tt>create</tt> action, which stores a blog entry to the
- # database, we might like to show the user the new entry. Because we're following good DRY principles (Don't Repeat Yourself), we're
+ # database, we might like to show the user the new entry. Because we're following good DRY principles (Don't Repeat Yourself), we're
# going to reuse (and redirect to) a <tt>show</tt> action that we'll assume has already been created. The code might look like this:
#
# def create
@@ -228,8 +228,11 @@ def self.without_modules(*modules)
include mod
end
- # Rails 2.x compatibility
- include ActionController::Compatibility
+ # Define some internal variables that should not be propagated to the view.
+ self.protected_instance_variables = [
+ :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request,
+ :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout
+ ]
ActiveSupport.run_load_hooks(:action_controller, self)
end
@@ -1,58 +0,0 @@
-module ActionController
- module Compatibility
- extend ActiveSupport::Concern
-
- class ::ActionController::ActionControllerError < StandardError #:nodoc:
- end
-
- # Temporary hax
- included do
- ::ActionController::UnknownAction = ::AbstractController::ActionNotFound
- ::ActionController::DoubleRenderError = ::AbstractController::DoubleRenderError
-
- # ROUTES TODO: This should be handled by a middleware and route generation
- # should be able to handle SCRIPT_NAME
- self.config.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
-
- 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
- ]
-
- def rescue_action(env)
- raise env["action_dispatch.rescue.exception"]
- end
- end
-
- # For old tests
- def initialize_template_class(*) end
- def assign_shortcuts(*) end
-
- def _normalize_options(options)
- options[:text] = nil if options.delete(:nothing) == true
- options[:text] = " " if options.key?(:text) && options[:text].nil?
- super
- end
-
- def render_to_body(options)
- options[:template].sub!(/^\//, '') if options.key?(:template)
- super || " "
- end
-
- def _handle_method_missing
- method_missing(@_action_name.to_sym)
- end
-
- def method_for_action(action_name)
- super || (respond_to?(:method_missing) && "_handle_method_missing")
- end
-
- def performed?
- response_body
- end
- end
-end
@@ -43,4 +43,4 @@ def initialize(message = nil)
class UnknownHttpMethod < ActionControllerError #:nodoc:
end
-end
+end
@@ -29,6 +29,10 @@ def render_to_string(*)
self.response_body = nil
end
+ def render_to_body(*)
+ super || " "
+ end
+
private
# Normalize arguments by catching blocks and setting them on :update.
@@ -44,6 +48,10 @@ def _normalize_options(options) #:nodoc:
options[:text] = options[:text].to_text
end
+ if options.delete(:nothing) || (options.key?(:text) && options[:text].nil?)
+ options[:text] = " "
+ end
+
if options[:status]
options[:status] = Rack::Utils.status_code(options[:status])
end
@@ -216,7 +216,7 @@ def _process_options(options) #:nodoc:
end
end
- # Call render_to_body if we are streaming instead of usual +render+.
+ # Call render_body if we are streaming instead of usual +render+.
def _render_template(options) #:nodoc:
if options.delete(:stream)
Rack::Chunked::Body.new view_renderer.render_body(view_context, options)
@@ -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:/",
@@ -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)
@@ -152,6 +152,7 @@ def detail_args_for(options)
def normalize_name(name, prefixes) #:nodoc:
prefixes = nil if prefixes.blank?
parts = name.to_s.split('/')
+ parts.shift if parts.first.empty?
name = parts.pop
return name, prefixes || [""] if parts.empty?
@@ -233,10 +233,8 @@ def method_missing(selector, *args)
super
end
end
-
end
include Behavior
-
end
end
@@ -33,8 +33,6 @@ def renew
session[:foo] = "baz"
head :ok
end
-
- def rescue_action(e) raise end
end
def setup
@@ -225,16 +223,16 @@ def test_allows_session_fixation
assert_equal session_id, cookies['_session_id']
end
end
-
+
def test_incoming_invalid_session_id_via_cookie_should_be_ignored
with_test_route_set do
open_session do |sess|
sess.cookies['_session_id'] = 'INVALID'
-
+
sess.get '/set_session_value'
new_session_id = sess.cookies['_session_id']
assert_not_equal 'INVALID', new_session_id
-
+
sess.get '/get_session_value'
new_session_id_2 = sess.cookies['_session_id']
assert_equal new_session_id, new_session_id_2
@@ -248,7 +246,7 @@ def test_incoming_invalid_session_id_via_parameter_should_be_ignored
sess.get '/set_session_value', :_session_id => 'INVALID'
new_session_id = sess.cookies['_session_id']
assert_not_equal 'INVALID', new_session_id
-
+
sess.get '/get_session_value'
new_session_id_2 = sess.cookies['_session_id']
assert_equal new_session_id, new_session_id_2
@@ -47,10 +47,6 @@ def xml()
render :text=>@content, :layout=>false, :content_type=>Mime::XML
@content = nil
end
-
- def rescue_action(e)
- raise e
- end
end
tests AssertSelectController
@@ -40,29 +40,6 @@ def hidden_action
end
end
-class MethodMissingController < ActionController::Base
- hide_action :shouldnt_be_called
- def shouldnt_be_called
- raise "NO WAY!"
- end
-
-protected
-
- def method_missing(selector)
- render :text => selector.to_s
- end
-end
-
-class AnotherMethodMissingController < ActionController::Base
- cattr_accessor :_exception
- rescue_from Exception, :with => :_exception=
-
- protected
- def method_missing(*attrs, &block)
- super
- end
-end
-
class DefaultUrlOptionsController < ActionController::Base
def from_view
render :inline => "<%= #{params[:route]} %>"
@@ -159,32 +136,10 @@ def test_process_should_be_precise
assert_equal exception.message, "The action 'non_existent' could not be found for EmptyController"
end
- def test_get_on_priv_should_show_selector
- use_controller MethodMissingController
- get :shouldnt_be_called
- assert_response :success
- assert_equal 'shouldnt_be_called', @response.body
- end
-
- def test_method_missing_is_not_an_action_name
- use_controller MethodMissingController
- assert !@controller.__send__(:action_method?, 'method_missing')
-
- get :method_missing
- assert_response :success
- assert_equal 'method_missing', @response.body
- end
-
- def test_method_missing_should_recieve_symbol
- use_controller AnotherMethodMissingController
- get :some_action
- assert_kind_of NameError, @controller._exception
- end
-
def test_get_on_hidden_should_fail
use_controller NonEmptyController
- assert_raise(ActionController::UnknownAction) { get :hidden_action }
- assert_raise(ActionController::UnknownAction) { get :another_hidden_action }
+ assert_raise(AbstractController::ActionNotFound) { get :hidden_action }
+ assert_raise(AbstractController::ActionNotFound) { get :another_hidden_action }
end
end
@@ -686,8 +686,6 @@ def setup
@controller.params = @params
@controller.request = @request
@controller.response = @response
- @controller.send(:initialize_template_class, @response)
- @controller.send(:assign_shortcuts, @request, @response)
end
def test_fragment_cache_key
@@ -795,10 +793,6 @@ def formatted_fragment_cached
format.xml
end
end
-
- def rescue_action(e)
- raise e
- end
end
class FunctionalFragmentCachingTest < ActionController::TestCase
@@ -28,8 +28,6 @@ def non_erb_block_content_for
def proper_block_detection
@todo = "some todo"
end
-
- def rescue_action(e) raise end
end
class CaptureTest < ActionController::TestCase
@@ -48,8 +48,6 @@ def render_default_content_types_for_respond_to
format.rss { render :text => "hello world!", :content_type => Mime::XML }
end
end
-
- def rescue_action(e) raise end
end
class ContentTypeTest < ActionController::TestCase
@@ -70,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:
@@ -107,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
Oops, something went wrong.

0 comments on commit ba154bd

Please sign in to comment.