aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-14 17:25:10 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-14 17:25:10 -0700
commitda65320433088548bc4cff33758e5acd71fd137a (patch)
tree97a5b945c5fece6da744383fda42072b3296988e /actionpack
parent8fac2c88cae0f2fd42fad3c2c2c6c860df14d629 (diff)
downloadrails-da65320433088548bc4cff33758e5acd71fd137a.tar.gz
rails-da65320433088548bc4cff33758e5acd71fd137a.tar.bz2
rails-da65320433088548bc4cff33758e5acd71fd137a.zip
Got new base to pass controller/base_test.rb, implemented method_missing action semantics in compatibility mode, and fixed a few action_missing bugs.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/abstract/base.rb10
-rw-r--r--actionpack/lib/action_controller/abstract/logger.rb33
-rw-r--r--actionpack/lib/action_controller/new_base/compatibility.rb15
-rw-r--r--actionpack/lib/action_controller/new_base/hide_actions.rb4
-rw-r--r--actionpack/lib/action_controller/new_base/http.rb5
-rw-r--r--actionpack/lib/action_controller/routing.rb1
-rw-r--r--actionpack/test/abstract_unit.rb2
-rw-r--r--actionpack/test/controller/base_test.rb2
8 files changed, 61 insertions, 11 deletions
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb
index 8f2bfb5711..483356a4be 100644
--- a/actionpack/lib/action_controller/abstract/base.rb
+++ b/actionpack/lib/action_controller/abstract/base.rb
@@ -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 \ No newline at end of file
diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb
index 5fb78f1755..d0603a4ad7 100644
--- a/actionpack/lib/action_controller/abstract/logger.rb
+++ b/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 \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb
index d17f498b60..993e571aba 100644
--- a/actionpack/lib/action_controller/new_base/compatibility.rb
+++ b/actionpack/lib/action_controller/new_base/compatibility.rb
@@ -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/}, '')
diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb
index d1857a9169..a29b09a893 100644
--- a/actionpack/lib/action_controller/new_base/hide_actions.rb
+++ b/actionpack/lib/action_controller/new_base/hide_actions.rb
@@ -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
diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb
index fb6041a04e..f3a60b3bf8 100644
--- a/actionpack/lib/action_controller/new_base/http.rb
+++ b/actionpack/lib/action_controller/new_base/http.rb
@@ -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
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index c0eb61340b..06a07a4d0a 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/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'
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 825ac9a46c..7982f06545 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -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
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index a09db95d7d..3a4cdb81d9 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -117,7 +117,7 @@ class PerformActionTest < ActionController::TestCase
end
def method_missing(method, *args)
- @logged << args.first
+ @logged << args.first.to_s
end
end