Permalink
Browse files

Merge branch 'master' into wip_abstract_controller

Conflicts:
	actionpack/lib/action_controller/abstract/callbacks.rb
	actionpack/lib/action_controller/abstract/renderer.rb
	actionpack/lib/action_controller/base/base.rb
	actionpack/lib/action_controller/dispatch/dispatcher.rb
	actionpack/lib/action_controller/routing/route_set.rb
	actionpack/lib/action_controller/testing/process.rb
	actionpack/test/abstract_controller/layouts_test.rb
	actionpack/test/controller/filters_test.rb
	actionpack/test/controller/helper_test.rb
	actionpack/test/controller/render_test.rb
	actionpack/test/new_base/test_helper.rb
  • Loading branch information...
2 parents 0f6e764 + 0cac68d commit 00a9d4b91cccdd88146cbe716eca844dcdfa08e7 Yehuda Katz + Carl Lerche committed May 12, 2009
Showing with 1,539 additions and 930 deletions.
  1. +1 −1 actionpack/lib/action_controller.rb
  2. +7 −4 actionpack/lib/action_controller/abstract/callbacks.rb
  3. +4 −2 actionpack/lib/action_controller/abstract/helpers.rb
  4. +3 −2 actionpack/lib/action_controller/abstract/layouts.rb
  5. +3 −1 actionpack/lib/action_controller/abstract/logger.rb
  6. +7 −5 actionpack/lib/action_controller/abstract/renderer.rb
  7. +17 −12 actionpack/lib/action_controller/base/base.rb
  8. +0 −4 actionpack/lib/action_controller/base/redirect.rb
  9. +50 −0 actionpack/lib/action_controller/base/rescue.rb
  10. +23 −32 actionpack/lib/action_controller/dispatch/dispatcher.rb
  11. +5 −0 actionpack/lib/action_controller/dispatch/middlewares.rb
  12. +0 −185 actionpack/lib/action_controller/dispatch/rescue.rb
  13. +0 −10 actionpack/lib/action_controller/dispatch/templates/rescues/diagnostics.erb
  14. +10 −10 actionpack/lib/action_controller/new_base/base.rb
  15. +6 −1 actionpack/lib/action_controller/new_base/compatibility.rb
  16. +5 −3 actionpack/lib/action_controller/new_base/hide_actions.rb
  17. +2 −0 actionpack/lib/action_controller/new_base/layouts.rb
  18. +2 −0 actionpack/lib/action_controller/new_base/renderer.rb
  19. +6 −9 actionpack/lib/action_controller/testing/integration.rb
  20. +24 −13 actionpack/lib/action_controller/testing/process.rb
  21. +2 −1 actionpack/lib/action_dispatch.rb
  22. +1 −3 actionpack/lib/action_dispatch/http/response.rb
  23. +0 −14 actionpack/lib/action_dispatch/middleware/reloader.rb
  24. +14 −0 actionpack/lib/action_dispatch/middleware/rescue.rb
  25. +144 −0 actionpack/lib/action_dispatch/middleware/show_exceptions.rb
  26. +1 −2 actionpack/lib/action_dispatch/middleware/stack.rb
  27. +3 −3 ...ion_controller/dispatch → action_dispatch/middleware}/templates/rescues/_request_and_response.erb
  28. 0 ...onpack/lib/{action_controller/dispatch → action_dispatch/middleware}/templates/rescues/_trace.erb
  29. +10 −0 actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
  30. +2 −2 ...onpack/lib/{action_controller/dispatch → action_dispatch/middleware}/templates/rescues/layout.erb
  31. 0 .../{action_controller/dispatch → action_dispatch/middleware}/templates/rescues/missing_template.erb
  32. 0 ...lib/{action_controller/dispatch → action_dispatch/middleware}/templates/rescues/routing_error.erb
  33. +3 −3 ...ib/{action_controller/dispatch → action_dispatch/middleware}/templates/rescues/template_error.erb
  34. 0 ...ib/{action_controller/dispatch → action_dispatch/middleware}/templates/rescues/unknown_action.erb
  35. +3 −14 actionpack/lib/action_dispatch/testing/assertions/response.rb
  36. +5 −0 actionpack/lib/action_dispatch/testing/test_request.rb
  37. +12 −12 actionpack/lib/action_dispatch/testing/test_response.rb
  38. +1 −1 actionpack/lib/action_view/paths.rb
  39. +2 −2 actionpack/test/abstract_controller/abstract_controller_test.rb
  40. +1 −1 actionpack/test/abstract_controller/callbacks_test.rb
  41. +2 −2 actionpack/test/abstract_controller/helper_test.rb
  42. +3 −3 actionpack/test/abstract_controller/layouts_test.rb
  43. +2 −0 actionpack/test/abstract_controller/test_helper.rb
  44. +6 −4 actionpack/test/controller/action_pack_assertions_test.rb
  45. +4 −5 actionpack/test/controller/base_test.rb
  46. +4 −1 actionpack/test/controller/caching_test.rb
  47. +8 −9 actionpack/test/controller/cookie_test.rb
  48. +0 −6 actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
  49. +0 −13 actionpack/test/controller/dispatcher_test.rb
  50. +5 −0 actionpack/test/controller/filters_test.rb
  51. +1 −2 actionpack/test/controller/layout_test.rb
  52. +0 −5 actionpack/test/controller/redirect_test.rb
  53. +5 −5 actionpack/test/controller/render_test.rb
  54. +47 −299 actionpack/test/controller/rescue_test.rb
  55. +4 −4 actionpack/test/controller/send_file_test.rb
  56. +3 −1 actionpack/test/controller/test_test.rb
  57. +103 −0 actionpack/test/dispatch/show_exceptions_test.rb
  58. +5 −1 actionpack/test/template/body_parts_test.rb
  59. +26 −20 actionpack/test/template/output_buffer_test.rb
  60. +2 −11 activemodel/lib/active_model/core.rb
  61. +3 −9 activerecord/lib/active_record.rb
  62. +3 −1 activerecord/lib/active_record/association_preload.rb
  63. +33 −9 activerecord/lib/active_record/associations.rb
  64. +6 −2 activerecord/lib/active_record/associations/association_collection.rb
  65. +14 −0 activerecord/lib/active_record/associations/association_proxy.rb
  66. +11 −1 activerecord/lib/active_record/associations/belongs_to_association.rb
  67. +5 −0 activerecord/lib/active_record/associations/has_many_association.rb
  68. +5 −5 activerecord/lib/active_record/associations/has_many_through_association.rb
  69. +11 −2 activerecord/lib/active_record/associations/has_one_association.rb
  70. +10 −1 activerecord/lib/active_record/nested_attributes.rb
  71. +21 −0 activerecord/lib/active_record/reflection.rb
  72. +12 −0 activerecord/test/cases/associations/eager_test.rb
  73. +1 −8 activerecord/test/cases/associations/has_one_associations_test.rb
  74. +313 −0 activerecord/test/cases/associations/inverse_associations_test.rb
  75. +17 −1 activerecord/test/cases/nested_attributes_test.rb
  76. +7 −0 activerecord/test/fixtures/faces.yml
  77. +29 −0 activerecord/test/fixtures/interests.yml
  78. +5 −0 activerecord/test/fixtures/men.yml
  79. +1 −3 activerecord/test/fixtures/organizations.yml
  80. +1 −3 activerecord/test/fixtures/sponsors.yml
  81. +5 −0 activerecord/test/fixtures/zines.yml
  82. +5 −0 activerecord/test/models/face.rb
  83. +4 −0 activerecord/test/models/interest.rb
  84. +7 −0 activerecord/test/models/man.rb
  85. +0 −4 activerecord/test/models/organization.rb
  86. +2 −0 activerecord/test/models/pirate.rb
  87. +3 −0 activerecord/test/models/zine.rb
  88. +22 −2 activerecord/test/schema/schema.rb
  89. +2 −1 activeresource/Rakefile
  90. +4 −19 activeresource/lib/active_resource.rb
  91. +14 −4 activeresource/lib/active_resource/base.rb
  92. +4 −56 activeresource/lib/active_resource/connection.rb
  93. +4 −0 activeresource/lib/active_resource/custom_methods.rb
  94. +55 −0 activeresource/lib/active_resource/exceptions.rb
  95. +4 −4 activeresource/lib/active_resource/formats.rb
  96. +2 −0 activeresource/lib/active_resource/formats/xml_format.rb
  97. +6 −1 activeresource/lib/active_resource/http_mock.rb
  98. +7 −0 activeresource/lib/active_resource/validations.rb
  99. +3 −6 activeresource/test/abstract_unit.rb
  100. +1 −0 activeresource/test/base/load_test.rb
  101. +1 −1 activeresource/test/base_test.rb
  102. +2 −0 activesupport/CHANGELOG
  103. +1 −0 activesupport/lib/active_support.rb
  104. +2 −2 activesupport/lib/active_support/core_ext/date/calculations.rb
  105. +3 −3 activesupport/lib/active_support/core_ext/date_time/conversions.rb
  106. +1 −1 activesupport/lib/active_support/core_ext/hash/conversions.rb
  107. +0 −1 activesupport/lib/active_support/core_ext/module.rb
  108. +0 −26 activesupport/lib/active_support/core_ext/module/setup.rb
  109. +1 −1 activesupport/lib/active_support/core_ext/time/conversions.rb
  110. +25 −0 activesupport/lib/active_support/dependency_module.rb
  111. +14 −0 activesupport/lib/active_support/ordered_hash.rb
  112. +2 −2 activesupport/lib/active_support/values/time_zone.rb
  113. +16 −0 activesupport/test/core_ext/hash_ext_test.rb
  114. +77 −0 activesupport/test/dependency_module_test.rb
  115. +10 −0 activesupport/test/ordered_hash_test.rb
  116. +5 −0 railties/CHANGELOG
  117. +3 −0 railties/Rakefile
  118. +7 −0 railties/configs/seeds.rb
  119. +3 −2 railties/lib/console_app.rb
  120. +1 −1 railties/lib/initializer.rb
  121. +2 −1 railties/lib/rails/rack/metal.rb
  122. +5 −0 railties/lib/rails_generator/generators/applications/app/app_generator.rb
  123. +11 −2 railties/lib/tasks/databases.rake
  124. +1 −2 railties/lib/tasks/gems.rake
  125. +75 −0 tools/profile_requires.rb
@@ -60,7 +60,7 @@ def self.load_all!
autoload :Redirector, 'action_controller/base/redirect'
autoload :Renderer, 'action_controller/base/render'
autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
- autoload :Rescue, 'action_controller/dispatch/rescue'
+ autoload :Rescue, 'action_controller/base/rescue'
autoload :Resources, 'action_controller/routing/resources'
autoload :Responder, 'action_controller/base/responder'
autoload :Routing, 'action_controller/routing'
@@ -1,10 +1,13 @@
module AbstractController
module Callbacks
- setup do
- include ActiveSupport::NewCallbacks
- define_callbacks :process_action, "response_body"
+ extend ActiveSupport::DependencyModule
+
+ depends_on ActiveSupport::NewCallbacks
+
+ included do
+ define_callbacks :process_action
end
-
+
def process_action
_run_process_action_callbacks(action_name) do
super
@@ -1,8 +1,10 @@
module AbstractController
module Helpers
+ extend ActiveSupport::DependencyModule
+
depends_on Renderer
-
- setup do
+
+ included do
extlib_inheritable_accessor :master_helper_module
self.master_helper_module = Module.new
end
@@ -1,8 +1,9 @@
module AbstractController
module Layouts
-
+ extend ActiveSupport::DependencyModule
+
depends_on Renderer
-
+
module ClassMethods
def layout(layout)
unless [String, Symbol, FalseClass, NilClass].include?(layout.class)
@@ -1,6 +1,8 @@
module AbstractController
module Logger
- setup do
+ extend ActiveSupport::DependencyModule
+
+ included do
cattr_accessor :logger
end
end
@@ -11,16 +11,18 @@ def initialize(message = nil)
end
module Renderer
+ extend ActiveSupport::DependencyModule
+
depends_on AbstractController::Logger
-
- setup do
+
+ included do
attr_internal :formats
-
+
extlib_inheritable_accessor :_view_paths
-
+
self._view_paths ||= ActionView::PathSet.new
end
-
+
def _action_view
@_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
end
@@ -30,10 +30,6 @@ def initialize(*allowed_methods)
def allowed_methods_header
allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
end
-
- def handle_response!(response)
- response.headers['Allow'] ||= allowed_methods_header
- end
end
class NotImplemented < MethodNotAllowed #:nodoc:
@@ -369,16 +365,20 @@ def session
attr_reader :template
+ def action(name, env)
+ # HACK: For global rescue to have access to the original request and response
+ request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env)
+ response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new
+ self.action_name = name && name.to_s
+ process(request, response).to_a
+ end
+
+
class << self
def action(name = nil)
@actions ||= {}
- @actions[name] ||= proc do |env|
- controller = new
- # HACK: For global rescue to have access to the original request and response
- request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env)
- response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new
- controller.action_name = name && name.to_s
- controller.process(request, response).to_a
+ @actions[name] ||= proc do |env|
+ new.action(name, env)
end
end
@@ -511,6 +511,12 @@ def exempt_from_layout(*types)
end
public
+ def call(env)
+ request = ActionDispatch::Request.new(env)
+ response = ActionDispatch::Response.new
+ process(request, response).to_a
+ end
+
# Extracts the action_name from the request parameters and performs that action.
def process(request, response, method = :perform_action, *arguments) #:nodoc:
response.request = request
@@ -819,7 +825,6 @@ def initialize_template_class(response)
@template = ActionView::Base.new(self.class.view_paths, {}, self, formats)
response.template = @template if response.respond_to?(:template=)
@template.helpers.send :include, self.class.master_helper_module
- response.redirected_to = nil
@performed_render = @performed_redirect = false
end
@@ -48,8 +48,6 @@ def redirect_to(options = {}, response_status = {}) #:doc:
status = 302
end
- response.redirected_to = options
-
case options
# The scheme name consist of a letter followed by any combination of
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
@@ -82,8 +80,6 @@ def redirect_to_full_url(url, status)
# The response body is not reset here, see +erase_render_results+
def erase_redirect_results #:nodoc:
@performed_redirect = false
- response.redirected_to = nil
- response.redirected_to_method_params = nil
response.status = DEFAULT_RENDER_STATUS_CODE
response.headers.delete('Location')
end
@@ -0,0 +1,50 @@
+module ActionController #:nodoc:
+ # Actions that fail to perform as expected throw exceptions. These
+ # exceptions can either be rescued for the public view (with a nice
+ # user-friendly explanation) or for the developers view (with tons of
+ # debugging information). The developers view is already implemented by
+ # the Action Controller, but the public view should be tailored to your
+ # specific application.
+ #
+ # The default behavior for public exceptions is to render a static html
+ # file with the name of the error code thrown. If no such file exists, an
+ # empty response is sent with the correct status code.
+ #
+ # You can override what constitutes a local request by overriding the
+ # <tt>local_request?</tt> method in your own controller. Custom rescue
+ # behavior is achieved by overriding the <tt>rescue_action_in_public</tt>
+ # and <tt>rescue_action_locally</tt> methods.
+ module Rescue
+ def self.included(base) #:nodoc:
+ base.send :include, ActiveSupport::Rescuable
+ base.extend(ClassMethods)
+
+ base.class_eval do
+ alias_method_chain :perform_action, :rescue
+ end
+ end
+
+ module ClassMethods
+ def rescue_action(env)
+ exception = env.delete('action_dispatch.rescue.exception')
+ request = ActionDispatch::Request.new(env)
+ response = ActionDispatch::Response.new
+ new.process(request, response, :rescue_action, exception).to_a
+ end
+ end
+
+ protected
+ # Exception handler called when the performance of an action raises
+ # an exception.
+ def rescue_action(exception)
+ rescue_with_handler(exception) || raise(exception)
+ end
+
+ private
+ def perform_action_with_rescue
+ perform_action_without_rescue
+ rescue Exception => exception
+ rescue_action(exception)
+ end
+ end
+end
@@ -5,9 +5,9 @@ class Dispatcher
class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
- unless self.middleware.include?(ActionDispatch::Reloader)
- self.middleware.insert_after(ActionDispatch::Failsafe, ActionDispatch::Reloader)
- end
+ # Development mode callbacks
+ before_dispatch :reload_application
+ after_dispatch :cleanup_application
ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
end
@@ -40,53 +40,44 @@ def to_prepare(identifier = nil, &block)
def run_prepare_callbacks
new.send :run_callbacks, :prepare_dispatch
end
-
- def reload_application
- # Run prepare callbacks before every request in development mode
- run_prepare_callbacks
-
- Routing::Routes.reload
- end
-
- def cleanup_application
- # Cleanup the application before processing the current request.
- ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
- ActiveSupport::Dependencies.clear
- ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
- end
end
+ cattr_accessor :router
+ self.router = Routing::Routes
+
cattr_accessor :middleware
self.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
middlewares = File.join(File.dirname(__FILE__), "middlewares.rb")
- middleware.instance_eval(File.read(middlewares))
+ middleware.instance_eval(File.read(middlewares), middlewares, 1)
end
include ActiveSupport::Callbacks
define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
def initialize
- @app = @@middleware.build(lambda { |env| self._call(env) })
+ @app = @@middleware.build(@@router)
freeze
end
def call(env)
+ run_callbacks :before_dispatch
@app.call(env)
+ ensure
+ run_callbacks :after_dispatch, :enumerator => :reverse_each
end
- def _call(env)
- begin
- run_callbacks :before_dispatch
- Routing::Routes.call(env)
- rescue Exception => exception
- if !env["rack.test"] && controller ||= (::ApplicationController rescue Base)
- controller.call_with_exception(env, exception).to_a
- else
- raise exception
- end
- ensure
- run_callbacks :after_dispatch, :enumerator => :reverse_each
- end
+ def reload_application
+ # Run prepare callbacks before every request in development mode
+ run_callbacks :prepare_dispatch
+
+ @@router.reload
+ end
+
+ def cleanup_application
+ # Cleanup the application before processing the current request.
+ ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
+ ActiveSupport::Dependencies.clear
+ ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
end
def flush_logger
@@ -3,6 +3,11 @@
}
use "ActionDispatch::Failsafe"
+use "ActionDispatch::ShowExceptions", lambda { ActionController::Base.consider_all_requests_local }
+use "ActionDispatch::Rescue", lambda {
+ controller = (::ApplicationController rescue ActionController::Base)
+ controller.method(:rescue_action)
+}
use lambda { ActionController::Base.session_store },
lambda { ActionController::Base.session_options }
Oops, something went wrong.

0 comments on commit 00a9d4b

Please sign in to comment.