mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure controller filters are executed before stuff starts to happen.
This commit is contained in:
parent
ee4c89627a
commit
4ba334c0f4
3 changed files with 21 additions and 3 deletions
|
@ -2,7 +2,6 @@ module ActionController
|
||||||
class Base < Metal
|
class Base < Metal
|
||||||
abstract!
|
abstract!
|
||||||
|
|
||||||
include AbstractController::Callbacks
|
|
||||||
include AbstractController::Layouts
|
include AbstractController::Layouts
|
||||||
include AbstractController::Translation
|
include AbstractController::Translation
|
||||||
|
|
||||||
|
@ -23,6 +22,7 @@ module ActionController
|
||||||
|
|
||||||
# Rails 2.x compatibility
|
# Rails 2.x compatibility
|
||||||
include ActionController::Compatibility
|
include ActionController::Compatibility
|
||||||
|
include ActionController::ImplicitRender
|
||||||
|
|
||||||
include ActionController::Cookies
|
include ActionController::Cookies
|
||||||
include ActionController::Flash
|
include ActionController::Flash
|
||||||
|
@ -36,8 +36,12 @@ module ActionController
|
||||||
# Add instrumentations hooks at the bottom, to ensure they instrument
|
# Add instrumentations hooks at the bottom, to ensure they instrument
|
||||||
# all the methods properly.
|
# all the methods properly.
|
||||||
include ActionController::Instrumentation
|
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
|
include ActionController::Rescue
|
||||||
|
|
||||||
def self.inherited(klass)
|
def self.inherited(klass)
|
||||||
|
|
|
@ -6,7 +6,7 @@ module ActionController
|
||||||
include AbstractController::Rendering
|
include AbstractController::Rendering
|
||||||
|
|
||||||
# Before processing, set the request formats in current controller formats.
|
# 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 }
|
self.formats = request.formats.map { |x| x.to_sym }
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
|
@ -617,6 +617,15 @@ class TestController < ActionController::Base
|
||||||
raise
|
raise
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def determine_layout
|
def determine_layout
|
||||||
|
@ -1034,6 +1043,11 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "<html>Hello world!</html>", @response.body
|
assert_equal "<html>Hello world!</html>", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_render_with_filters
|
||||||
|
get :render_with_filters
|
||||||
|
assert_equal "<test>passed formatted xml erb</test>", @response.body
|
||||||
|
end
|
||||||
|
|
||||||
# :ported:
|
# :ported:
|
||||||
def test_double_render
|
def test_double_render
|
||||||
assert_raise(ActionController::DoubleRenderError) { get :double_render }
|
assert_raise(ActionController::DoubleRenderError) { get :double_render }
|
||||||
|
|
Loading…
Reference in a new issue