Permalink
Browse files

Merge branch 'master' of git://github.com/rails/rails

  • Loading branch information...
2 parents d3da87c + fa9f000 commit fbdbac2b88218e5e3e6087c67dacf7e755aa4106 @mikel mikel committed Jan 21, 2010
@@ -15,5 +15,6 @@ module AbstractController
autoload :LocalizedCache
autoload :Logger
autoload :Rendering
+ autoload :Translation
autoload :UrlFor
end
@@ -34,7 +34,7 @@ def template_cache
end
end
- def render(options)
+ def render(*args)
Thread.current[:format_locale_key] = HashKey.get(self.class, formats, I18n.locale)
super
end
@@ -40,12 +40,13 @@ def view_context
# Mostly abstracts the fact that calling render twice is a DoubleRenderError.
# Delegates render_to_body and sticks the result in self.response_body.
- def render(*args)
+ def render(*args, &block)
if response_body
- raise AbstractController::DoubleRenderError, "Can only render or redirect once per action"
+ raise AbstractController::DoubleRenderError
end
- self.response_body = render_to_body(*args)
+ options = _normalize_options(*args, &block)
+ self.response_body = render_to_body(options)
end
# Raw rendering of a template to a Rack-compatible body.
@@ -69,7 +70,8 @@ def render_to_body(options = {})
# render_to_body into a String.
#
# :api: plugin
- def render_to_string(options = {})
+ def render_to_string(*args)
+ options = _normalize_options(*args)
AbstractController::Rendering.body_to_s(render_to_body(options))
end
@@ -96,6 +98,20 @@ def view_paths
_view_paths
end
+ # Normalize options, by converting render "foo" to render :template => "foo"
+ # and render "/foo" to render :file => "/foo".
+ def _normalize_options(action=nil, options={})
+ case action
+ when Hash
+ options, action = action, nil
+ when String
+ key = (action.index("/") == 0 ? :file : :template)
+ options.merge!(key => action)
+ end
+
+ options
+ end
+
# Return a string representation of a Rack-compatible response body.
def self.body_to_s(body)
if body.respond_to?(:to_str)
@@ -1,4 +1,4 @@
-module ActionController
+module AbstractController
module Translation
def translate(*args)
I18n.translate(*args)
@@ -8,7 +8,6 @@ module ActionController
autoload :Base
autoload :Caching
autoload :PolymorphicRoutes
- autoload :Translation
autoload :Metal
autoload :Middleware
@@ -4,6 +4,7 @@ class Base < Metal
include AbstractController::Callbacks
include AbstractController::Layouts
+ include AbstractController::Translation
include ActionController::Helpers
helper :all # By default, all helpers should be included
@@ -33,7 +34,6 @@ class Base < Metal
include ActionController::Streaming
include ActionController::HttpAuthentication::Basic::ControllerMethods
include ActionController::HttpAuthentication::Digest::ControllerMethods
- include ActionController::Translation
# Add instrumentations hooks at the bottom, to ensure they instrument
# all the methods properly.
@@ -74,17 +74,14 @@ def self.subclasses
@subclasses ||= []
end
- def _normalize_options(action = nil, options = {}, &blk)
- if action.is_a?(Hash)
- options, action = action, nil
- elsif action.is_a?(String) || action.is_a?(Symbol)
- key = case action = action.to_s
- when %r{^/} then :file
- when %r{/} then :template
- else :action
- end
- options.merge! key => action
- elsif action
+ def _normalize_options(action=nil, options={}, &blk)
+ case action
+ when NilClass
+ when Hash, String
+ options = super
+ when Symbol
+ options.merge! :action => action
+ else
options.merge! :partial => action
end
@@ -99,15 +96,5 @@ def _normalize_options(action = nil, options = {}, &blk)
options[:update] = blk if block_given?
options
end
-
- def render(action = nil, options = {}, &blk)
- options = _normalize_options(action, options, &blk)
- super(options)
- end
-
- def render_to_string(action = nil, options = {}, &blk)
- options = _normalize_options(action, options, &blk)
- super(options)
- end
end
end
@@ -60,6 +60,7 @@ def status=(status)
# :api: private
def dispatch(name, env)
@_env = env
+ @_env['action_controller.instance'] = self
process(name)
to_a
end
@@ -32,18 +32,12 @@ def process_action(action, *args)
end
end
- def render(*args, &block)
- if logger
- render_output = nil
-
- self.view_runtime = cleanup_view_runtime do
- Benchmark.ms { render_output = super }
- end
-
- render_output
- else
- super
+ def render(*args)
+ render_output = nil
+ self.view_runtime = cleanup_view_runtime do
+ Benchmark.ms { render_output = super }
end
+ render_output
end
def send_file(path, options={})
@@ -12,9 +12,10 @@ def process_action(*)
super
end
- def render(options)
- super
- self.content_type ||= options[:_template].mime_type.to_s
+ def render(*args)
+ args << {} unless args.last.is_a?(Hash)
+ super(*args)
+ self.content_type ||= args.last[:_template].mime_type.to_s
response_body
end
@@ -29,9 +29,31 @@ def symbolized_path_parameters
def path_parameters
@env["action_dispatch.request.path_parameters"] ||= {}
end
-
- private
+ def filter_parameters
+ # TODO: Remove dependency on controller
+ if controller = @env['action_controller.instance']
+ controller.send(:filter_parameters, params)
+ else
+ params
+ end
+ end
+
+ def filter_env
+ if controller = @env['action_controller.instance']
+ @env.map do |key, value|
+ if (key =~ /RAW_POST_DATA/i)
+ '[FILTERED]'
+ else
+ controller.send(:filter_parameters, {key => value}).values[0]
+ end
+ end
+ else
+ env
+ end
+ end
+
+ private
# Convert nested Hashs to HashWithIndifferentAccess
def normalize_parameters(value)
case value
@@ -9,7 +9,9 @@ def initialize(app)
end
def call(env)
- payload = retrieve_payload_from_env(env)
+ request = Request.new(env)
+ payload = retrieve_payload_from_env(request.filter_env)
+
ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", payload)
ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", payload) do
@@ -21,11 +23,10 @@ def call(env)
raise exception
end
- protected
-
- # Remove any rack related constants from the env, like rack.input.
- def retrieve_payload_from_env(env)
- Hash[:env => env.except(*env.keys.select { |k| k.to_s.index("rack.") == 0 })]
- end
+ protected
+ # Remove any rack related constants from the env, like rack.input.
+ def retrieve_payload_from_env(env)
+ Hash[:env => env.except(*env.keys.select { |k| k.to_s.index("rack.") == 0 })]
+ end
end
-end
+end
@@ -44,6 +44,12 @@ def segment_keys
def to_a
[@app, @conditions, @defaults, @name]
end
+
+ def to_s
+ @to_s ||= begin
+ "%-6s %-40s %s" % [(verb || :any).to_s.upcase, path, requirements.inspect]
+ end
+ end
end
end
end
@@ -240,9 +240,9 @@ def process(method, path, parameters = nil, rack_environment = nil)
path = location.query ? "#{location.path}?#{location.query}" : location.path
end
- [ControllerCapture, ActionController::Testing].each do |mod|
- unless ActionController::Base < mod
- ActionController::Base.class_eval { include mod }
+ unless ActionController::Base < ActionController::Testing
+ ActionController::Base.class_eval do
+ include ActionController::Testing
end
end
@@ -269,16 +269,15 @@ def process(method, path, parameters = nil, rack_environment = nil)
end
session = Rack::Test::Session.new(@mock_session)
-
- @controller = ActionController::Base.capture_instantiation do
- session.request(path, env)
- end
+ session.request(path, env)
@request_count += 1
@request = ActionDispatch::Request.new(session.last_request.env)
@response = ActionDispatch::TestResponse.from_response(@mock_session.last_response)
@html_document = nil
+ @controller = session.last_request.env['action_controller.instance']
+
return response.status
end
@@ -296,31 +295,6 @@ def generic_url_rewriter
end
end
- # A module used to extend ActionController::Base, so that integration tests
- # can capture the controller used to satisfy a request.
- module ControllerCapture #:nodoc:
- extend ActiveSupport::Concern
-
- included do
- alias_method_chain :initialize, :capture
- end
-
- def initialize_with_capture(*args)
- initialize_without_capture
- self.class.last_instantiation ||= self
- end
-
- module ClassMethods #:nodoc:
- mattr_accessor :last_instantiation
-
- def capture_instantiation
- self.last_instantiation = nil
- yield
- return last_instantiation
- end
- end
- end
-
module Runner
def app
@app
Oops, something went wrong.

0 comments on commit fbdbac2

Please sign in to comment.