diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-05-16 17:13:58 +0200 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-05-16 17:13:58 +0200 |
commit | 6be72a1e6287c5c098dd518ddc0467e473164869 (patch) | |
tree | 89e7f6bf9ff6b7cf1ed5f2424991dc472e6a2c24 | |
parent | c8fb22bc2933beb5c6cc4113380c8faf77d87ffe (diff) | |
parent | a6d8ca0f0e65ce509793713cb1efe4ab721b9eb4 (diff) | |
download | rails-6be72a1e6287c5c098dd518ddc0467e473164869.tar.gz rails-6be72a1e6287c5c098dd518ddc0467e473164869.tar.bz2 rails-6be72a1e6287c5c098dd518ddc0467e473164869.zip |
Merge commit 'mainstream/master'
-rw-r--r-- | actionpack/lib/action_controller/abstract/base.rb | 27 | ||||
-rw-r--r-- | actionpack/lib/action_controller/abstract/callbacks.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/base/chained/filters.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/dispatch/middlewares.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/base.rb | 42 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/compatibility.rb | 31 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/http.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/rescuable.rb | 53 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/testing.rb | 2 | ||||
-rw-r--r-- | actionpack/test/abstract_controller/abstract_controller_test.rb | 7 | ||||
-rw-r--r-- | actionpack/test/abstract_unit2.rb | 12 | ||||
-rw-r--r-- | railties/Rakefile | 7 |
13 files changed, 142 insertions, 51 deletions
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index f2db201063..1f2f096dae 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/actionpack/lib/action_controller/abstract/base.rb @@ -69,14 +69,13 @@ module AbstractController 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 @@ module AbstractController # 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
\ No newline at end of file diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb index 3aff83a209..51b968c694 100644 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ b/actionpack/lib/action_controller/abstract/callbacks.rb @@ -8,8 +8,8 @@ module AbstractController 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 diff --git a/actionpack/lib/action_controller/base/chained/filters.rb b/actionpack/lib/action_controller/base/chained/filters.rb index 9022b8b279..98fe306fd5 100644 --- a/actionpack/lib/action_controller/base/chained/filters.rb +++ b/actionpack/lib/action_controller/base/chained/filters.rb @@ -160,7 +160,7 @@ module ActionController #:nodoc: 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 diff --git a/actionpack/lib/action_controller/dispatch/middlewares.rb b/actionpack/lib/action_controller/dispatch/middlewares.rb index f99637b109..0e4ab6fa39 100644 --- a/actionpack/lib/action_controller/dispatch/middlewares.rb +++ b/actionpack/lib/action_controller/dispatch/middlewares.rb @@ -6,6 +6,7 @@ use "ActionDispatch::Failsafe" 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) } diff --git a/actionpack/lib/action_controller/new_base.rb b/actionpack/lib/action_controller/new_base.rb index 1f215bb6f1..bc47713529 100644 --- a/actionpack/lib/action_controller/new_base.rb +++ b/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" diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 1adcc9c71f..c25ffd5c84 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -12,14 +12,40 @@ module ActionController 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 @@ module ActionController 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
\ No newline at end of file diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb index 993e571aba..0a283887b6 100644 --- a/actionpack/lib/action_controller/new_base/compatibility.rb +++ b/actionpack/lib/action_controller/new_base/compatibility.rb @@ -45,6 +45,14 @@ module ActionController 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 @@ module ActionController 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 @@ module ActionController 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) diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb index e9a1d5b12f..8891a2a8c3 100644 --- a/actionpack/lib/action_controller/new_base/http.rb +++ b/actionpack/lib/action_controller/new_base/http.rb @@ -48,8 +48,6 @@ module ActionController @_response = ActionDispatch::Response.new @_response.request = request process(name) - @_response.body = response_body - @_response.prepare! to_rack end @@ -62,6 +60,8 @@ module ActionController # :api: private def to_rack + @_response.body = response_body + @_response.prepare! @_response.to_a end end diff --git a/actionpack/lib/action_controller/new_base/rescuable.rb b/actionpack/lib/action_controller/new_base/rescuable.rb new file mode 100644 index 0000000000..29ffe19d5f --- /dev/null +++ b/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 diff --git a/actionpack/lib/action_controller/new_base/testing.rb b/actionpack/lib/action_controller/new_base/testing.rb index 106990b9ba..b39d8d539d 100644 --- a/actionpack/lib/action_controller/new_base/testing.rb +++ b/actionpack/lib/action_controller/new_base/testing.rb @@ -7,7 +7,7 @@ module ActionController @_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 diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 689aa99fd8..9c028e7d1e 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -201,11 +201,10 @@ module AbstractController 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 diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb index 932f594ad2..519e6bea36 100644 --- a/actionpack/test/abstract_unit2.rb +++ b/actionpack/test/abstract_unit2.rb @@ -11,11 +11,19 @@ require 'action_controller/new_base' 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 @@ module ActionController "Expected no partials to be rendered" end end - end + end end end diff --git a/railties/Rakefile b/railties/Rakefile index 133a603ed6..69c1ca762a 100644 --- a/railties/Rakefile +++ b/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` |