aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-13 21:28:34 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-13 21:28:34 +0100
commit4ba334c0f4dac35b0c02cf3c4cca47d328283009 (patch)
tree67c88d5bd1693268242bd02a504f0a5233dffe86
parentee4c89627ad5d7b041b88ab4027d3f0d5d582d8e (diff)
downloadrails-4ba334c0f4dac35b0c02cf3c4cca47d328283009.tar.gz
rails-4ba334c0f4dac35b0c02cf3c4cca47d328283009.tar.bz2
rails-4ba334c0f4dac35b0c02cf3c4cca47d328283009.zip
Ensure controller filters are executed before stuff starts to happen.
-rw-r--r--actionpack/lib/action_controller/base.rb8
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb2
-rw-r--r--actionpack/test/controller/render_test.rb14
3 files changed, 21 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index fcd3cb9bd3..ad2b68af21 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -2,7 +2,6 @@ module ActionController
class Base < Metal
abstract!
- include AbstractController::Callbacks
include AbstractController::Layouts
include AbstractController::Translation
@@ -23,6 +22,7 @@ module ActionController
# Rails 2.x compatibility
include ActionController::Compatibility
+ include ActionController::ImplicitRender
include ActionController::Cookies
include ActionController::Flash
@@ -36,8 +36,12 @@ module ActionController
# Add instrumentations hooks at the bottom, to ensure they instrument
# all the methods properly.
include ActionController::Instrumentation
- include ImplicitRender
+ # Before callbacks should also be executed the earliest as possible, so
+ # also include them at the bottom.
+ include AbstractController::Callbacks
+
+ # The same with rescue, append it at the end to wrap as much as possible.
include ActionController::Rescue
def self.inherited(klass)
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 2167fe9a32..86bb810947 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -6,7 +6,7 @@ module ActionController
include AbstractController::Rendering
# Before processing, set the request formats in current controller formats.
- def process(*) #:nodoc:
+ def process_action(*) #:nodoc:
self.formats = request.formats.map { |x| x.to_sym }
super
end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index e3c4869391..20fcb87da6 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -617,6 +617,15 @@ class TestController < ActionController::Base
raise
end
+ before_filter :only => :render_with_filters do
+ request.format = :xml
+ end
+
+ # Ensure that the before filter is executed *before* self.formats is set.
+ def render_with_filters
+ render :action => :formatted_xml_erb
+ end
+
private
def determine_layout
@@ -1034,6 +1043,11 @@ class RenderTest < ActionController::TestCase
assert_equal "<html>Hello world!</html>", @response.body
end
+ def test_render_with_filters
+ get :render_with_filters
+ assert_equal "<test>passed formatted xml erb</test>", @response.body
+ end
+
# :ported:
def test_double_render
assert_raise(ActionController::DoubleRenderError) { get :double_render }