Browse files

Got new base to pass controller/base_test.rb, implemented method_miss…

…ing action semantics in compatibility mode, and fixed a few action_missing bugs.
  • Loading branch information...
1 parent 8fac2c8 commit da65320433088548bc4cff33758e5acd71fd137a Yehuda Katz + Carl Lerche committed May 14, 2009
View
10 actionpack/lib/action_controller/abstract/base.rb
@@ -67,6 +67,8 @@ def initialize
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 @@ def action_methods
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 @@ def process_action
# 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
View
33 actionpack/lib/action_controller/abstract/logger.rb
@@ -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
View
15 actionpack/lib/action_controller/new_base/compatibility.rb
@@ -42,6 +42,9 @@ module Rails2Compatibility
# 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 @@ def render_to_body(options)
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/}, '')
View
4 actionpack/lib/action_controller/new_base/hide_actions.rb
@@ -12,8 +12,8 @@ def action_names() action_methods end
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
View
5 actionpack/lib/action_controller/new_base/http.rb
@@ -21,11 +21,6 @@ def self.controller_path
# :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
View
1 actionpack/lib/action_controller/routing.rb
@@ -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'
View
2 actionpack/test/abstract_unit.rb
@@ -37,7 +37,7 @@
# 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
View
2 actionpack/test/controller/base_test.rb
@@ -117,7 +117,7 @@ def initialize
end
def method_missing(method, *args)
- @logged << args.first
+ @logged << args.first.to_s
end
end

0 comments on commit da65320

Please sign in to comment.