Permalink
Browse files

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

  • Loading branch information...
2 parents 628110d + 195fadb commit cf6e025a4538e488ed35f61f1f7f3498833a34e6 @jeremy jeremy committed May 18, 2009
Showing with 871 additions and 409 deletions.
  1. +3 −1 Rakefile
  2. +2 −0 actionpack/CHANGELOG
  3. +1 −1 actionpack/Rakefile
  4. +3 −0 actionpack/lib/action_controller/abstract.rb
  5. +30 −12 actionpack/lib/action_controller/abstract/base.rb
  6. +2 −2 actionpack/lib/action_controller/abstract/callbacks.rb
  7. +33 −0 actionpack/lib/action_controller/abstract/logger.rb
  8. +2 −3 actionpack/lib/action_controller/base/base.rb
  9. +2 −7 actionpack/lib/action_controller/base/chained/filters.rb
  10. +2 −1 actionpack/lib/action_controller/base/http_authentication.rb
  11. +39 −61 actionpack/lib/action_controller/dispatch/dispatcher.rb
  12. +2 −1 actionpack/lib/action_controller/dispatch/middlewares.rb
  13. +1 −0 actionpack/lib/action_controller/new_base.rb
  14. +29 −13 actionpack/lib/action_controller/new_base/base.rb
  15. +24 −0 actionpack/lib/action_controller/new_base/compatibility.rb
  16. +2 −2 actionpack/lib/action_controller/new_base/hide_actions.rb
  17. +2 −7 actionpack/lib/action_controller/new_base/http.rb
  18. +53 −0 actionpack/lib/action_controller/new_base/rescuable.rb
  19. +1 −1 actionpack/lib/action_controller/new_base/testing.rb
  20. +0 −1 actionpack/lib/action_controller/routing.rb
  21. +0 −3 actionpack/lib/action_controller/testing/process.rb
  22. +1 −1 actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
  23. +1 −1 actionpack/lib/action_dispatch.rb
  24. +40 −0 actionpack/lib/action_dispatch/middleware/callbacks.rb
  25. +0 −52 actionpack/lib/action_dispatch/middleware/failsafe.rb
  26. +4 −6 actionpack/lib/action_dispatch/middleware/params_parser.rb
  27. +40 −47 actionpack/lib/action_dispatch/middleware/show_exceptions.rb
  28. +1 −0 actionpack/lib/action_view.rb
  29. +2 −0 actionpack/lib/action_view/helpers/form_options_helper.rb
  30. +6 −1 actionpack/lib/action_view/helpers/number_helper.rb
  31. +1 −1 actionpack/lib/action_view/helpers/tag_helper.rb
  32. +7 −6 actionpack/lib/action_view/helpers/text_helper.rb
  33. +1 −1 actionpack/lib/action_view/template/handlers.rb
  34. +3 −4 actionpack/test/abstract_controller/abstract_controller_test.rb
  35. +1 −1 actionpack/test/abstract_unit.rb
  36. +10 −2 actionpack/test/abstract_unit2.rb
  37. +3 −3 actionpack/test/activerecord/active_record_store_test.rb
  38. +1 −0 actionpack/test/activerecord/polymorphic_routes_test.rb
  39. +23 −0 actionpack/test/controller/action_pack_assertions_test.rb
  40. +1 −1 actionpack/test/controller/base_test.rb
  41. +20 −14 actionpack/test/controller/dispatcher_test.rb
  42. +0 −1 actionpack/test/controller/filters_test.rb
  43. +0 −3 actionpack/test/controller/helper_test.rb
  44. +20 −3 actionpack/test/controller/http_digest_authentication_test.rb
  45. +5 −0 actionpack/test/controller/render_test.rb
  46. +14 −0 actionpack/test/controller/rescue_test.rb
  47. +5 −0 actionpack/test/dispatch/show_exceptions_test.rb
  48. +20 −3 actionpack/test/new_base/render_action_test.rb
  49. +0 −2 actionpack/test/new_base/render_layout_test.rb
  50. +27 −0 actionpack/test/new_base/render_partial_test.rb
  51. +48 −28 actionpack/test/new_base/render_template_test.rb
  52. +3 −3 actionpack/test/new_base/render_test.rb
  53. +11 −0 actionpack/test/new_base/render_xml_test.rb
  54. +1 −1 actionpack/test/new_base/test_helper.rb
  55. +22 −0 actionpack/test/template/form_options_helper_test.rb
  56. +4 −0 actionpack/test/template/number_helper_test.rb
  57. +7 −0 actionpack/test/template/text_helper_test.rb
  58. +2 −0 activerecord/CHANGELOG
  59. +3 −0 activerecord/lib/active_record.rb
  60. +1 −1 activerecord/lib/active_record/associations.rb
  61. +9 −0 activerecord/lib/active_record/associations/association_collection.rb
  62. +8 −8 activerecord/lib/active_record/associations/has_one_through_association.rb
  63. +3 −3 activerecord/lib/active_record/attribute_methods.rb
  64. +1 −1 activerecord/lib/active_record/base.rb
  65. +10 −1 activerecord/lib/active_record/named_scope.rb
  66. +9 −1 activerecord/lib/active_record/session_store.rb
  67. +0 −24 activerecord/test/cases/aaa_create_tables_test.rb
  68. +4 −0 activerecord/test/cases/associations/eager_test.rb
  69. +39 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  70. +8 −1 activerecord/test/cases/associations/has_one_through_associations_test.rb
  71. +2 −2 activerecord/test/cases/finder_test.rb
  72. +18 −0 activerecord/test/cases/helper.rb
  73. +34 −0 activerecord/test/cases/named_scope_test.rb
  74. +4 −1 activerecord/test/fixtures/people.yml
  75. +1 −0 activerecord/test/models/person.rb
  76. +5 −1 activerecord/test/schema/schema.rb
  77. +0 −6 activerecord/test/schema/schema2.rb
  78. +8 −3 activesupport/lib/active_support/json.rb
  79. +7 −2 activesupport/lib/active_support/json/backends/jsongem.rb
  80. +7 −2 activesupport/lib/active_support/json/backends/yaml.rb
  81. +10 −6 activesupport/lib/active_support/xml_mini/jdom.rb
  82. +10 −6 activesupport/lib/active_support/xml_mini/libxml.rb
  83. +10 −6 activesupport/lib/active_support/xml_mini/nokogiri.rb
  84. +9 −5 activesupport/lib/active_support/xml_mini/rexml.rb
  85. +3 −0 activesupport/test/json/decoding_test.rb
  86. +13 −0 activesupport/test/xml_mini/nokogiri_engine_test.rb
  87. +14 −0 activesupport/test/xml_mini/rexml_engine_test.rb
  88. +4 −3 railties/Rakefile
  89. +7 −3 railties/builtin/rails_info/rails/info.rb
  90. +1 −1 railties/configs/routes.rb
  91. +1 −1 railties/lib/commands/performance/profiler.rb
  92. +2 −3 railties/lib/console_app.rb
  93. +2 −3 railties/lib/initializer.rb
  94. +6 −6 railties/lib/rails/plugin/loader.rb
  95. +1 −1 railties/lib/rails/plugin/locator.rb
  96. +1 −1 railties/lib/rails_generator/generators/applications/app/template_runner.rb
  97. +1 −1 railties/lib/rails_generator/generators/components/model/templates/model.rb
  98. +1 −1 railties/lib/rails_generator/scripts.rb
  99. +4 −4 railties/lib/tasks/gems.rake
  100. +2 −0 railties/test/rails_info_test.rb
View
@@ -15,9 +15,11 @@ task :default => :test
%w(test isolated_test rdoc pgem package release).each do |task_name|
desc "Run #{task_name} task for all projects"
task task_name do
+ errors = []
PROJECTS.each do |project|
- system %(cd #{project} && #{env} #{$0} #{task_name})
+ system(%(cd #{project} && #{env} #{$0} #{task_name})) || errors << project
end
+ fail("Errors in #{errors.join(', ')}") unless errors.empty?
end
end
View
@@ -1,5 +1,7 @@
*Edge*
+* Instead of checking Rails.env.test? in Failsafe middleware, check env["rails.raise_exceptions"] [Bryan Helmkamp]
+
* Fixed that TestResponse.cookies was returning cookies unescaped #1867 [Doug McInnes]
View
@@ -22,7 +22,7 @@ task :default => [ :test ]
# Run the unit tests
desc "Run all unit tests"
-task :test => [:test_action_pack, :test_active_record_integration, :test_new_base]
+task :test => [:test_action_pack, :test_active_record_integration]
Rake::TestTask.new(:test_action_pack) do |t|
t.libs << "test"
@@ -1,3 +1,6 @@
+require "active_support/core_ext/module/attr_internal"
+require "active_support/core_ext/module/delegation"
+
module AbstractController
autoload :Base, "action_controller/abstract/base"
autoload :Callbacks, "action_controller/abstract/callbacks"
@@ -25,6 +25,15 @@ def abstract!
end
alias_method :abstract?, :abstract
+
+ def inherited(klass)
+ ::AbstractController::Base.subclasses << klass.to_s
+ super
+ end
+
+ def subclasses
+ @subclasses ||= []
+ end
def internal_methods
controller = self
@@ -60,12 +69,13 @@ def initialize
end
def process(action_name)
- unless respond_to_action?(action_name)
+ @_action_name = action_name = action_name.to_s
+
+ unless action_name = method_for_action(action_name)
raise ActionNotFound, "The action '#{action_name}' could not be found"
end
-
- @_action_name = action_name
- process_action
+
+ process_action(action_name)
self
end
@@ -75,23 +85,31 @@ 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)
- elsif respond_to?(:action_missing, true) then action_missing(action_name)
- end
+ def process_action(method_name)
+ send(method_name)
end
-
+
+ def _handle_action_missing
+ action_missing(@_action_name)
+ end
+
# Override this to change the conditions that will raise an
# ActionNotFound error. If you accept a difference case,
# you must handle it by also overriding process_action and
# handling the case.
- def respond_to_action?(action_name)
- action_methods.include?(action_name.to_s) || respond_to?(:action_missing, true)
+ def method_for_action(action_name)
+ if action_method?(action_name) then action_name
+ elsif respond_to?(:action_missing, true) then "_handle_action_missing"
+ end
end
end
-end
+end
@@ -8,8 +8,8 @@ module Callbacks
define_callbacks :process_action, "response_body"
end
- def process_action
- _run_process_action_callbacks(action_name) do
+ def process_action(method_name)
+ _run_process_action_callbacks(method_name) do
super
end
end
@@ -4,8 +4,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
@@ -368,9 +368,8 @@ def session
attr_reader :template
def action(name, env)
- # HACK: For global rescue to have access to the original request and response
- request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env)
- response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new
+ request = ActionDispatch::Request.new(env)
+ response = ActionDispatch::Response.new
self.action_name = name && name.to_s
process(request, response).to_a
end
@@ -160,7 +160,7 @@ def should_run_callback?(controller)
def convert_only_and_except_options_to_sets_of_strings(opts)
[:only, :except].each do |key|
if values = opts[key]
- opts[key] = Array(values).map(&:to_s).to_set
+ opts[key] = Array(values).map {|val| val.to_s }.to_set
end
end
end
@@ -571,12 +571,7 @@ def skip_filter(*filters)
# Returns an array of Filter objects for this controller.
def filter_chain
- if chain = read_inheritable_attribute('filter_chain')
- return chain
- else
- write_inheritable_attribute('filter_chain', FilterChain.new)
- return filter_chain
- end
+ read_inheritable_attribute('filter_chain') || write_inheritable_attribute('filter_chain', FilterChain.new)
end
# Returns all the before filters for this class and all its ancestors.
@@ -194,9 +194,10 @@ def validate_digest_response(request, realm, &password_procedure)
if valid_nonce && realm == credentials[:realm] && opaque == credentials[:opaque]
password = password_procedure.call(credentials[:username])
+ method = request.env['rack.methodoverride.original_method'] || request.env['REQUEST_METHOD']
[true, false].any? do |password_is_ha1|
- expected = expected_response(request.env['REQUEST_METHOD'], request.env['REQUEST_URI'], credentials, password, password_is_ha1)
+ expected = expected_response(method, request.env['REQUEST_URI'], credentials, password, password_is_ha1)
expected == credentials[:response]
end
end
@@ -1,87 +1,65 @@
+require 'active_support/core_ext/module/delegation'
+
module ActionController
# Dispatches requests to the appropriate controller and takes care of
# reloading the app after each request when Dependencies.load? is true.
class Dispatcher
+ cattr_accessor :prepare_each_request
+ self.prepare_each_request = false
+
+ cattr_accessor :router
+ self.router = Routing::Routes
+
+ cattr_accessor :middleware
+ self.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
+ middlewares = File.join(File.dirname(__FILE__), "middlewares.rb")
+ middleware.instance_eval(File.read(middlewares), middlewares, 1)
+ end
+
class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
+ # Run prepare callbacks before every request in development mode
+ self.prepare_each_request = true
+
# Development mode callbacks
- before_dispatch :reload_application
- after_dispatch :cleanup_application
+ ActionDispatch::Callbacks.before_dispatch do |app|
+ ActionController::Dispatcher.router.reload
+ end
+
+ ActionDispatch::Callbacks.after_dispatch do
+ # Cleanup the application before processing the current request.
+ ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
+ ActiveSupport::Dependencies.clear
+ ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
+ end
ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
end
if defined?(ActiveRecord)
- to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers }
+ to_prepare(:activerecord_instantiate_observers) do
+ ActiveRecord::Base.instantiate_observers
+ end
end
- after_dispatch :flush_logger if Base.logger && Base.logger.respond_to?(:flush)
+ if Base.logger && Base.logger.respond_to?(:flush)
+ after_dispatch do
+ Base.logger.flush
+ end
+ end
to_prepare do
I18n.reload!
end
end
- # Add a preparation callback. Preparation callbacks are run before every
- # request in development mode, and before the first request in production
- # mode.
- #
- # An optional identifier may be supplied for the callback. If provided,
- # to_prepare may be called again with the same identifier to replace the
- # existing callback. Passing an identifier is a suggested practice if the
- # code adding a preparation block may be reloaded.
- def to_prepare(identifier = nil, &block)
- @prepare_dispatch_callbacks ||= ActiveSupport::Callbacks::CallbackChain.new
- callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier)
- @prepare_dispatch_callbacks.replace_or_append!(callback)
- end
+ delegate :to_prepare, :prepare_dispatch, :before_dispatch, :after_dispatch,
+ :to => ActionDispatch::Callbacks
- def run_prepare_callbacks
- new.send :run_callbacks, :prepare_dispatch
+ def new
+ @@middleware.build(@@router)
end
end
-
- cattr_accessor :router
- self.router = Routing::Routes
-
- cattr_accessor :middleware
- self.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
- middlewares = File.join(File.dirname(__FILE__), "middlewares.rb")
- middleware.instance_eval(File.read(middlewares), middlewares, 1)
- end
-
- include ActiveSupport::Callbacks
- define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
-
- def initialize
- @app = @@middleware.build(@@router)
- freeze
- end
-
- def call(env)
- run_callbacks :before_dispatch
- @app.call(env)
- ensure
- run_callbacks :after_dispatch, :enumerator => :reverse_each
- end
-
- def reload_application
- # Run prepare callbacks before every request in development mode
- run_callbacks :prepare_dispatch
-
- @@router.reload
- end
-
- def cleanup_application
- # Cleanup the application before processing the current request.
- ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
- ActiveSupport::Dependencies.clear
- ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
- end
-
- def flush_logger
- Base.logger.flush
- end
end
end
@@ -2,10 +2,11 @@
!ActionController::Base.allow_concurrency
}
-use "ActionDispatch::Failsafe"
use "ActionDispatch::ShowExceptions", lambda { ActionController::Base.consider_all_requests_local }
+use "ActionDispatch::Callbacks", lambda { ActionController::Dispatcher.prepare_each_request }
use "ActionDispatch::Rescue", lambda {
controller = (::ApplicationController rescue ActionController::Base)
+ # TODO: Replace with controller.action(:_rescue_action)
controller.method(:rescue_action)
}
@@ -7,6 +7,7 @@ module ActionController
autoload :Rails2Compatibility, "action_controller/new_base/compatibility"
autoload :Redirector, "action_controller/new_base/redirector"
autoload :Renderer, "action_controller/new_base/renderer"
+ autoload :Rescue, "action_controller/new_base/rescuable"
autoload :Testing, "action_controller/new_base/testing"
autoload :UrlFor, "action_controller/new_base/url_for"
Oops, something went wrong.

0 comments on commit cf6e025

Please sign in to comment.