Permalink
Browse files

Merge

  • Loading branch information...
dhh committed Dec 24, 2009
2 parents 2b7256a + 46b3769 commit 38af368360ab35600ef69b21d85ae9604e6ebb22
Showing with 441 additions and 390 deletions.
  1. +2 −0 Gemfile
  2. +24 −0 actionmailer/lib/action_mailer/rails.rb
  3. +0 −10 actionpack/lib/action_controller/notifications.rb
  4. +102 −0 actionpack/lib/action_controller/rails.rb
  5. +1 −1 actionpack/lib/action_dispatch/routing/route_set.rb
  6. +1 −1 actionpack/lib/action_view.rb
  7. +2 −2 actionpack/test/dispatch/response_test.rb
  8. +10 −1 actionpack/test/dispatch/routing_test.rb
  9. +0 −5 activerecord/lib/active_record/notifications.rb
  10. +59 −0 activerecord/lib/active_record/rails.rb
  11. +1 −0 activeresource/test/cases/base/schema_test.rb
  12. +11 −2 activesupport/lib/active_support/json/encoding.rb
  13. +3 −1 activesupport/test/json/encoding_test.rb
  14. +1 −1 railties/builtin/routes.rb
  15. +9 −33 railties/lib/rails.rb
  16. +43 −223 railties/lib/rails/application.rb
  17. +5 −5 railties/lib/rails/commands/server.rb
  18. +14 −11 railties/lib/rails/configuration.rb
  19. +34 −0 railties/lib/rails/core.rb
  20. +1 −1 railties/lib/rails/generators/rails/app/templates/config.ru
  21. +1 −1 railties/lib/rails/generators/rails/app/templates/script/console.tt
  22. +1 −1 railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
  23. +1 −1 railties/lib/rails/generators/rails/app/templates/script/server.tt
  24. +1 −0 railties/lib/rails/initializable.rb
  25. +5 −3 railties/lib/rails/plugin.rb
  26. +29 −20 railties/test/application/configuration_test.rb
  27. +16 −14 railties/test/application/generators_test.rb
  28. +14 −46 railties/test/application/initializer_test.rb
  29. +4 −4 railties/test/application/load_test.rb
  30. +10 −3 railties/test/application/routing_test.rb
  31. +10 −0 railties/test/initializable_test.rb
  32. +8 −0 railties/test/isolation/abstract_unit.rb
  33. +18 −0 railties/test/plugins/framework_extension_test.rb
View
@@ -31,3 +31,5 @@ if ENV['CI']
gem "test-unit", ">= 2.0.5"
end
end
+
+disable_system_gems
@@ -0,0 +1,24 @@
+require "action_mailer"
+
+module ActionMailer
+ class Plugin < Rails::Plugin
+ plugin_name :action_mailer
+
+ initializer "action_mailer.set_configs" do |app|
+ app.config.action_mailer.each do |k,v|
+ ActionMailer::Base.send "#{k}=", v
+ end
+ end
+
+ # TODO: ActionController::Base.logger should delegate to its own config.logger
+ initializer "action_mailer.logger" do
+ ActionMailer::Base.logger ||= Rails.logger
+ end
+
+ initializer "action_mailer.view_paths" do |app|
+ # TODO: this should be combined with the logic for default config.action_mailer.view_paths
+ view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes)
+ ActionMailer::Base.template_root = view_path if ActionMailer::Base.view_paths.blank?
+ end
+ end
+end
@@ -1,10 +0,0 @@
-require 'active_support/notifications'
-
-ActiveSupport::Notifications.subscribe(/(read|write|cache|expire|exist)_(fragment|page)\??/) do |*args|
- event = ActiveSupport::Notifications::Event.new(*args)
-
- if logger = ActionController::Base.logger
- human_name = event.name.to_s.humanize
- logger.info("#{human_name} (%.1fms)" % event.duration)
- end
-end
@@ -0,0 +1,102 @@
+module ActionController
+ class Plugin < Rails::Plugin
+ plugin_name :action_controller
+
+ initializer "action_controller.set_configs" do |app|
+ app.config.action_controller.each do |k,v|
+ ActionController::Base.send "#{k}=", v
+ end
+ end
+
+ # TODO: ActionController::Base.logger should delegate to its own config.logger
+ initializer "action_controller.logger" do
+ ActionController::Base.logger ||= Rails.logger
+ end
+
+ # Routing must be initialized after plugins to allow the former to extend the routes
+ # ---
+ # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
+ # this does nothing. Otherwise, it loads the routing definitions and sets up
+ # loading module used to lazily load controllers (Configuration#controller_paths).
+ initializer "action_controller.initialize_routing" do |app|
+ app.route_configuration_files << app.config.routes_configuration_file
+ app.route_configuration_files << app.config.builtin_routes_configuration_file
+ app.reload_routes!
+ end
+
+ # Include middleware to serve up static assets
+ initializer "action_controller.initialize_static_server" do |app|
+ if app.config.serve_static_assets
+ app.config.middleware.use(ActionDispatch::Static, Rails.public_path)
+ end
+ end
+
+ initializer "action_controller.initialize_middleware_stack" do |app|
+ middleware = app.config.middleware
+ middleware.use(::Rack::Lock, :if => lambda { ActionController::Base.allow_concurrency })
+ middleware.use(::Rack::Runtime)
+ middleware.use(ActionDispatch::ShowExceptions, lambda { ActionController::Base.consider_all_requests_local })
+ middleware.use(ActionDispatch::Callbacks, lambda { ActionController::Dispatcher.prepare_each_request })
+ middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
+ middleware.use(ActionDispatch::ParamsParser)
+ middleware.use(::Rack::MethodOverride)
+ middleware.use(::Rack::Head)
+ middleware.use(ActionDispatch::StringCoercion)
+ end
+
+ initializer "action_controller.initialize_framework_caches" do
+ ActionController::Base.cache_store ||= RAILS_CACHE
+ end
+
+ # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
+ # (but only for those frameworks that are to be loaded). If the framework's
+ # paths have already been set, it is not changed, otherwise it is
+ # set to use Configuration#view_path.
+ initializer "action_controller.initialize_framework_views" do |app|
+ # TODO: this should be combined with the logic for default config.action_controller.view_paths
+ view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes)
+ ActionController::Base.view_paths = view_path if ActionController::Base.view_paths.blank?
+ end
+
+ initializer "action_controller.initialize_metal" do |app|
+ Rails::Rack::Metal.requested_metals = app.config.metals
+
+ app.config.middleware.insert_before(:"ActionDispatch::ParamsParser",
+ Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?)
+ end
+
+ # # Prepare dispatcher callbacks and run 'prepare' callbacks
+ initializer "action_controller.prepare_dispatcher" do |app|
+ # TODO: This used to say unless defined?(Dispatcher). Find out why and fix.
+ require 'rails/dispatcher'
+
+ Dispatcher.define_dispatcher_callbacks(app.config.cache_classes)
+
+ unless app.config.cache_classes
+ # Setup dev mode route reloading
+ routes_last_modified = app.routes_changed_at
+ reload_routes = lambda do
+ unless app.routes_changed_at == routes_last_modified
+ routes_last_modified = app.routes_changed_at
+ app.reload_routes!
+ end
+ end
+ ActionDispatch::Callbacks.before_dispatch { |callbacks| reload_routes.call }
+ end
+ end
+
+ initializer "action_controller.notifications" do |app|
+ require 'active_support/notifications'
+
+ ActiveSupport::Notifications.subscribe(/(read|write|cache|expire|exist)_(fragment|page)\??/) do |*args|
+ event = ActiveSupport::Notifications::Event.new(*args)
+
+ if logger = ActionController::Base.logger
+ human_name = event.name.to_s.humanize
+ logger.info("#{human_name} (%.1fms)" % event.duration)
+ end
+ end
+ end
+
+ end
+end
@@ -273,7 +273,7 @@ def controller_namespaces
# TODO: Move this into Railties
if defined?(Rails.application)
# Find namespaces in controllers/ directory
- Rails.application.configuration.controller_paths.each do |load_path|
+ Rails.application.config.controller_paths.each do |load_path|
load_path = File.expand_path(load_path)
Dir["#{load_path}/**/*_controller.rb"].collect do |path|
namespaces << File.dirname(path).sub(/#{load_path}\/?/, '')
@@ -32,7 +32,6 @@ module ActionView
extend ActiveSupport::Autoload
eager_autoload do
- autoload :Base
autoload :Context
autoload :Template
autoload :Helpers
@@ -56,5 +55,6 @@ module ActionView
end
require 'action_view/erb/util'
+require 'action_view/base'
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
@@ -178,7 +178,7 @@ def app
@app = lambda { |env|
[200,
{'ETag' => '"202cb962ac59075b964b07152d234b70"',
- 'Cache-Control' => 'public'}, 'Hello']
+ 'Cache-Control' => 'public'}, ['Hello']]
}
get '/'
@@ -217,7 +217,7 @@ def app
@app = lambda { |env|
[200,
{'Content-Type' => 'application/xml; charset=utf-16'},
- 'Hello']
+ ['Hello']]
}
get '/'
@@ -109,8 +109,9 @@ def self.matches?(request)
scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do
resources :rooms
end
-
+
match '/info' => 'projects#info', :as => 'info'
+
root :to => 'projects#index'
end
end
@@ -478,6 +479,14 @@ def test_index
end
end
+ def test_index
+ with_test_routes do
+ assert_equal '/info', info_path
+ get '/info'
+ assert_equal 'projects#info', @response.body
+ end
+ end
+
private
def with_test_routes
real_routes, temp_routes = ActionController::Routing::Routes, Routes
@@ -1,5 +0,0 @@
-require 'active_support/notifications'
-
-ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload|
- ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before)
-end
@@ -0,0 +1,59 @@
+# For now, action_controller must always be present with
+# rails, so let's make sure that it gets required before
+# here. This is needed for correctly setting up the middleware.
+# In the future, this might become an optional require.
+require "action_controller/rails"
+
+module ActiveRecord
+ class Plugin < Rails::Plugin
+ plugin_name :active_record
+
+ initializer "active_record.set_configs" do |app|
+ app.config.active_record.each do |k,v|
+ ActiveRecord::Base.send "#{k}=", v
+ end
+ end
+
+ # This sets the database configuration from Configuration#database_configuration
+ # and then establishes the connection.
+ initializer "active_record.initialize_database" do |app|
+ ActiveRecord::Base.configurations = app.config.database_configuration
+ ActiveRecord::Base.establish_connection
+ end
+
+ initializer "active_record.initialize_timezone" do
+ ActiveRecord::Base.time_zone_aware_attributes = true
+ ActiveRecord::Base.default_timezone = :utc
+ end
+
+ # Setup database middleware after initializers have run
+ initializer "active_record.initialize_database_middleware" do |app|
+ middleware = app.config.middleware
+ if middleware.include?(ActiveRecord::SessionStore)
+ middleware.insert_before ActiveRecord::SessionStore, ActiveRecord::ConnectionAdapters::ConnectionManagement
+ middleware.insert_before ActiveRecord::SessionStore, ActiveRecord::QueryCache
+ else
+ middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
+ middleware.use ActiveRecord::QueryCache
+ end
+ end
+
+ initializer "active_record.load_observers" do
+ ActiveRecord::Base.instantiate_observers
+ end
+
+ # TODO: ActiveRecord::Base.logger should delegate to its own config.logger
+ initializer "active_record.logger" do
+ ActiveRecord::Base.logger ||= Rails.logger
+ end
+
+ initializer "active_record.notifications" do
+ require 'active_support/notifications'
+
+ ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload|
+ ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before)
+ end
+ end
+
+ end
+end
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'active_support/core_ext/hash/conversions'
require "fixtures/person"
require "fixtures/street_address"
@@ -65,6 +65,15 @@ def check_for_circular_references(value)
ESCAPED_CHARS = {
+ "\x00" => '\u0000', "\x01" => '\u0001', "\x02" => '\u0002',
+ "\x03" => '\u0003', "\x04" => '\u0004', "\x05" => '\u0005',
+ "\x06" => '\u0006', "\x07" => '\u0007', "\x0B" => '\u000B',
+ "\x0E" => '\u000E', "\x0F" => '\u000F', "\x10" => '\u0010',
+ "\x11" => '\u0011', "\x12" => '\u0012', "\x13" => '\u0013',
+ "\x14" => '\u0014', "\x15" => '\u0015', "\x16" => '\u0016',
+ "\x17" => '\u0017', "\x18" => '\u0018', "\x19" => '\u0019',
+ "\x1A" => '\u001A', "\x1B" => '\u001B', "\x1C" => '\u001C',
+ "\x1D" => '\u001D', "\x1E" => '\u001E', "\x1F" => '\u001F',
"\010" => '\b',
"\f" => '\f',
"\n" => '\n',
@@ -86,9 +95,9 @@ class << self
def escape_html_entities_in_json=(value)
self.escape_regex = \
if @escape_html_entities_in_json = value
- /[\010\f\n\r\t"\\><&]/
+ /[\x00-\x1F"\\><&]/
else
- /[\010\f\n\r\t"\\]/
+ /[\x00-\x1F"\\]/
end
end
@@ -23,7 +23,9 @@ def as_json(options)
StringTests = [[ 'this is the <string>', %("this is the \\u003Cstring\\u003E")],
[ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ],
- [ 'http://test.host/posts/1', %("http://test.host/posts/1")]]
+ [ 'http://test.host/posts/1', %("http://test.host/posts/1")],
+ [ "Control characters: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
+ %("Control characters: \\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000B\\f\\r\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F") ]]
ArrayTests = [[ ['a', 'b', 'c'], %([\"a\",\"b\",\"c\"]) ],
[ [1, 'a', :b, nil, false], %([1,\"a\",\"b\",null,false]) ]]
@@ -1,3 +1,3 @@
ActionController::Routing::Routes.draw do |map|
- match '/rails/info/properties' => "rails::info#properties"
+ match '/rails/info/properties' => "rails/info#properties"
end
View
@@ -1,33 +1,9 @@
-require "pathname"
-
-require 'active_support'
-require 'active_support/core_ext/kernel/reporting'
-require 'active_support/core_ext/logger'
-require 'action_dispatch'
-
-require 'rails/initializable'
-require 'rails/application'
-require 'rails/plugin'
-require 'rails/railties_path'
-require 'rails/version'
-require 'rails/rack'
-require 'rails/paths'
-require 'rails/core'
-require 'rails/configuration'
-require 'rails/deprecation'
-require 'rails/initializer'
-require 'rails/ruby_version_check'
-
-# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
-# multibyte safe operations. Plugin authors supporting other encodings
-# should override this behaviour and set the relevant +default_charset+
-# on ActionController::Base.
-#
-# For Ruby 1.9, UTF-8 is the default internal and external encoding.
-if RUBY_VERSION < '1.9'
- $KCODE='u'
-else
- Encoding.default_external = Encoding::UTF_8
-end
-
-RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV)
+require "rails/core"
+
+%w(active_model active_record action_controller action_view action_mailer active_resource).each do |framework|
+ begin
+ require framework
+ require "#{framework}/rails"
+ rescue LoadError
+ end
+end
Oops, something went wrong.

0 comments on commit 38af368

Please sign in to comment.