mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Got new base to pass controller/base_test.rb, implemented method_missing action semantics in compatibility mode, and fixed a few action_missing bugs.
This commit is contained in:
parent
8fac2c88ca
commit
da65320433
8 changed files with 61 additions and 11 deletions
|
@ -67,6 +67,8 @@ module AbstractController
|
|||
end
|
||||
|
||||
def process(action_name)
|
||||
action_name = action_name.to_s
|
||||
|
||||
unless respond_to_action?(action_name)
|
||||
raise ActionNotFound, "The action '#{action_name}' could not be found"
|
||||
end
|
||||
|
@ -82,13 +84,17 @@ module AbstractController
|
|||
self.class.action_methods
|
||||
end
|
||||
|
||||
def action_method?(action)
|
||||
action_methods.include?(action)
|
||||
end
|
||||
|
||||
# It is possible for respond_to?(action_name) to be false and
|
||||
# respond_to?(:action_missing) to be false if respond_to_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 respond_to?(action_name) then send(action_name)
|
||||
if action_method?(action_name) then send(action_name)
|
||||
elsif respond_to?(:action_missing, true) then action_missing(action_name)
|
||||
end
|
||||
end
|
||||
|
@ -98,7 +104,7 @@ module AbstractController
|
|||
# you must handle it by also overriding process_action and
|
||||
# handling the case.
|
||||
def respond_to_action?(action_name)
|
||||
action_methods.include?(action_name) || respond_to?(:action_missing, true)
|
||||
action_method?(action_name) || respond_to?(:action_missing, true)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,8 +2,41 @@ module AbstractController
|
|||
module Logger
|
||||
extend ActiveSupport::DependencyModule
|
||||
|
||||
class DelayedLog
|
||||
def initialize(&blk)
|
||||
@blk = blk
|
||||
end
|
||||
|
||||
def to_s
|
||||
@blk.call
|
||||
end
|
||||
alias to_str to_s
|
||||
end
|
||||
|
||||
included do
|
||||
cattr_accessor :logger
|
||||
end
|
||||
|
||||
def process(action)
|
||||
ret = super
|
||||
|
||||
if logger
|
||||
log = DelayedLog.new do
|
||||
"\n\nProcessing #{self.class.name}\##{action_name} " \
|
||||
"to #{request.formats} " \
|
||||
"(for #{request_origin}) [#{request.method.to_s.upcase}]"
|
||||
end
|
||||
|
||||
logger.info(log)
|
||||
end
|
||||
|
||||
ret
|
||||
end
|
||||
|
||||
def request_origin
|
||||
# this *needs* to be cached!
|
||||
# otherwise you'd get different results if calling it more than once
|
||||
@request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -42,6 +42,9 @@ module ActionController
|
|||
# Controls the resource action separator
|
||||
cattr_accessor :resource_action_separator
|
||||
self.resource_action_separator = "/"
|
||||
|
||||
cattr_accessor :use_accept_header
|
||||
self.use_accept_header = true
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
@ -66,6 +69,18 @@ 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
|
||||
end
|
||||
|
||||
def _layout_for_name(name)
|
||||
name &&= name.sub(%r{^/?layouts/}, '')
|
||||
|
|
|
@ -12,8 +12,8 @@ module ActionController
|
|||
|
||||
private
|
||||
|
||||
def respond_to_action?(action_name)
|
||||
!hidden_actions.include?(action_name) && (super || respond_to?(:method_missing))
|
||||
def action_method?(action_name)
|
||||
!hidden_actions.include?(action_name) && super
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
|
|
@ -21,11 +21,6 @@ module ActionController
|
|||
# :api: public
|
||||
def controller_path() self.class.controller_path end
|
||||
|
||||
# :api: private
|
||||
def self.internal_methods
|
||||
ActionController::Http.public_instance_methods(true)
|
||||
end
|
||||
|
||||
# :api: private
|
||||
def self.action_names() action_methods end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'cgi'
|
||||
require 'uri'
|
||||
require 'set'
|
||||
require 'action_controller/routing/optimisations'
|
||||
require 'action_controller/routing/routing_ext'
|
||||
require 'action_controller/routing/route'
|
||||
|
|
|
@ -37,7 +37,7 @@ ActionController::Base.session_store = nil
|
|||
# Register danish language for testing
|
||||
I18n.backend.store_translations 'da', {}
|
||||
I18n.backend.store_translations 'pt-BR', {}
|
||||
ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort
|
||||
ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
|
||||
|
||||
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
||||
ActionController::Base.view_paths = FIXTURE_LOAD_PATH
|
||||
|
|
|
@ -117,7 +117,7 @@ class PerformActionTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
@logged << args.first
|
||||
@logged << args.first.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue