Permalink
Browse files

Merge commit 'mainstream/master'

  • Loading branch information...
2 parents c8fb22b + a6d8ca0 commit 6be72a1e6287c5c098dd518ddc0467e473164869 @lifo lifo committed May 16, 2009
View
27 actionpack/lib/action_controller/abstract/base.rb
@@ -69,14 +69,13 @@ def initialize
end
def process(action_name)
- action_name = action_name.to_s
+ @_action_name = action_name = action_name.to_s
- unless respond_to_action?(action_name)
+ unless action_name = method_for_action(action_name)
raise ActionNotFound, "The action '#{action_name}' could not be found"
end
-
- @_action_name = action_name
- process_action
+
+ process_action(action_name)
self
end
@@ -95,18 +94,22 @@ def action_method?(action)
# is overridden in a subclass. For instance, ActionController::Base
# overrides it to include the case where a template matching the
# action_name is found.
- def process_action
- if action_method?(action_name) then send(action_name)
- elsif respond_to?(:action_missing, true) then action_missing(action_name)
- end
+ def process_action(method_name)
+ send(method_name)
end
-
+
+ def _handle_action_missing
+ action_missing(@_action_name)
+ end
+
# Override this to change the conditions that will raise an
# ActionNotFound error. If you accept a difference case,
# you must handle it by also overriding process_action and
# handling the case.
- def respond_to_action?(action_name)
- action_method?(action_name) || respond_to?(:action_missing, true)
+ def method_for_action(action_name)
+ if action_method?(action_name) then action_name
+ elsif respond_to?(:action_missing, true) then "_handle_action_missing"
+ end
end
end
end
View
4 actionpack/lib/action_controller/abstract/callbacks.rb
@@ -8,8 +8,8 @@ module Callbacks
define_callbacks :process_action, "response_body"
end
- def process_action
- _run_process_action_callbacks(action_name) do
+ def process_action(method_name)
+ _run_process_action_callbacks(method_name) do
super
end
end
View
2 actionpack/lib/action_controller/base/chained/filters.rb
@@ -160,7 +160,7 @@ def should_run_callback?(controller)
def convert_only_and_except_options_to_sets_of_strings(opts)
[:only, :except].each do |key|
if values = opts[key]
- opts[key] = Array(values).map(&:to_s).to_set
+ opts[key] = Array(values).map {|val| val.to_s }.to_set
end
end
end
View
1 actionpack/lib/action_controller/dispatch/middlewares.rb
@@ -6,6 +6,7 @@
use "ActionDispatch::ShowExceptions", lambda { ActionController::Base.consider_all_requests_local }
use "ActionDispatch::Rescue", lambda {
controller = (::ApplicationController rescue ActionController::Base)
+ # TODO: Replace with controller.action(:_rescue_action)
controller.method(:rescue_action)
}
View
1 actionpack/lib/action_controller/new_base.rb
@@ -7,6 +7,7 @@ module ActionController
autoload :Rails2Compatibility, "action_controller/new_base/compatibility"
autoload :Redirector, "action_controller/new_base/redirector"
autoload :Renderer, "action_controller/new_base/renderer"
+ autoload :Rescue, "action_controller/new_base/rescuable"
autoload :Testing, "action_controller/new_base/testing"
autoload :UrlFor, "action_controller/new_base/url_for"
View
42 actionpack/lib/action_controller/new_base/base.rb
@@ -12,14 +12,40 @@ class Base < Http
include ActionController::Renderer
include ActionController::Layouts
include ActionController::ConditionalGet
-
+
# Legacy modules
include SessionManagement
include ActionDispatch::StatusCodes
-
+
# Rails 2.x compatibility
include ActionController::Rails2Compatibility
-
+
+ # TODO: Extract into its own module
+ # This should be moved together with other normalizing behavior
+ module ImplicitRender
+ def process_action(method_name)
+ ret = super
+ render if response_body.nil?
+ ret
+ end
+
+ def _implicit_render
+ render
+ end
+
+ def method_for_action(action_name)
+ super || begin
+ if view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
+ "_implicit_render"
+ end
+ end
+ end
+ end
+
+ include ImplicitRender
+
+ include ActionController::Rescue
+
def self.inherited(klass)
::ActionController::Base.subclasses << klass.to_s
super
@@ -113,15 +139,5 @@ def redirect_to(options = {}, response_status = {}) #:doc:
super(url, status)
end
-
- def process_action
- ret = super
- render if response_body.nil?
- ret
- end
-
- def respond_to_action?(action_name)
- super || view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
- end
end
end
View
31 actionpack/lib/action_controller/new_base/compatibility.rb
@@ -45,6 +45,14 @@ module Rails2Compatibility
cattr_accessor :use_accept_header
self.use_accept_header = true
+
+ cattr_accessor :page_cache_directory
+ self.page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
+
+ cattr_reader :cache_store
+
+ cattr_accessor :consider_all_requests_local
+ self.consider_all_requests_local = true
end
module ClassMethods
@@ -53,6 +61,11 @@ def consider_all_requests_local() end
def rescue_action(env)
raise env["action_dispatch.rescue.exception"]
end
+
+ # Defines the storage option for cached fragments
+ def cache_store=(store_option)
+ @@cache_store = ActiveSupport::Cache.lookup_store(store_option)
+ end
end
def initialize(*)
@@ -69,17 +82,13 @@ def render_to_body(options)
super
end
-
- def respond_to_action?(action_name)
- if respond_to?(:method_missing) && !respond_to?(:action_missing)
- self.class.class_eval do
- private
- def action_missing(name, *args)
- method_missing(name.to_sym, *args)
- end
- end
- end
- super
+
+ 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 _layout_for_name(name)
View
4 actionpack/lib/action_controller/new_base/http.rb
@@ -48,8 +48,6 @@ def call(name, env)
@_response = ActionDispatch::Response.new
@_response.request = request
process(name)
- @_response.body = response_body
- @_response.prepare!
to_rack
end
@@ -62,6 +60,8 @@ def self.action(name)
# :api: private
def to_rack
+ @_response.body = response_body
+ @_response.prepare!
@_response.to_a
end
end
View
53 actionpack/lib/action_controller/new_base/rescuable.rb
@@ -0,0 +1,53 @@
+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
+ extend ActiveSupport::DependencyModule
+
+ included do
+ include ActiveSupport::Rescuable
+ end
+
+ module ClassMethods
+ # This can be removed once we can move action(:_rescue_action) into middlewares.rb
+ # Currently, it does controller.method(:rescue_action), which is hiding the implementation
+ # difference between the old and new base.
+ def rescue_action(env)
+ action(:_rescue_action).call(env)
+ end
+ end
+
+ attr_internal :rescued_exception
+
+ private
+
+ def method_for_action(action_name)
+ return action_name if self.rescued_exception = request.env.delete("action_dispatch.rescue.exception")
+ super
+ end
+
+ def _rescue_action
+ rescue_with_handler(rescued_exception) || raise(rescued_exception)
+ end
+
+ def process_action(*)
+ super
+ rescue Exception => exception
+ self.rescued_exception = exception
+ _rescue_action
+ end
+ end
+end
View
2 actionpack/lib/action_controller/new_base/testing.rb
@@ -7,7 +7,7 @@ def process_with_test(request, response)
@_response = response
@_response.request = request
ret = process(request.parameters[:action])
- @_response.body = self.response_body
+ @_response.body = self.response_body || " "
@_response.prepare!
set_test_assigns
ret
View
7 actionpack/test/abstract_controller/abstract_controller_test.rb
@@ -201,11 +201,10 @@ def index() self.response_body = "success" end
def fail() self.response_body = "fail" end
private
-
- def respond_to_action?(action_name)
- action_name.to_s != "fail"
+
+ def method_for_action(action_name)
+ action_name.to_s != "fail" && action_name
end
-
end
class TestRespondToAction < ActiveSupport::TestCase
View
12 actionpack/test/abstract_unit2.rb
@@ -11,11 +11,19 @@
require 'fixture_template'
require 'action_controller/testing/process2'
require 'action_view/test_case'
+require 'action_controller/testing/integration'
+require 'active_support/dependencies'
+
+ActiveSupport::Dependencies.hook!
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
module ActionController
-
+ Base.session = {
+ :key => '_testing_session',
+ :secret => '8273f16463985e2b3747dc25e30f2528'
+}
+
class ActionControllerError < StandardError #:nodoc:
end
@@ -126,6 +134,6 @@ def assert_template(options = {}, message = nil)
"Expected no partials to be rendered"
end
end
- end
+ end
end
end
View
7 railties/Rakefile
@@ -249,7 +249,7 @@ def copy_with_rewritten_ruby_path(src_file, dest_file)
end
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.textile"'
-task :guides do
+task :generate_guides do
ENV["WARN_BROKEN_LINKS"] = "1" # authors can't disable this
ruby "guides/rails_guides.rb"
end
@@ -298,6 +298,7 @@ PKG_FILES = FileList[
'doc/**/*',
'dispatches/**/*',
'environments/**/*',
+ 'guides/**/*',
'helpers/**/*',
'generators/**/*',
'html/**/*',
@@ -324,7 +325,7 @@ spec = Gem::Specification.new do |s|
s.rdoc_options << '--exclude' << '.'
s.has_rdoc = false
- s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
+ s.files = PKG_FILES.to_a.delete_if {|f| f =~ %r{\.svn|guides/output}}
s.require_path = 'lib'
s.bindir = "bin" # Use these for applications.
s.executables = ["rails"]
@@ -350,7 +351,7 @@ task :pgem => [:gem] do
end
desc "Publish the guides"
-task :pguides => :guides do
+task :pguides => :generate_guides do
require 'rake/contrib/sshpublisher'
mkdir_p 'pkg'
`tar -czf pkg/guides.gz guides/output`

0 comments on commit 6be72a1

Please sign in to comment.