diff options
author | Carlhuda <carlhuda@Carlhudas-iMac.local> | 2009-11-30 15:58:38 -0800 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2009-12-02 11:35:47 -0800 |
commit | abfc4dad3ebb17eccd32d1f1eb8a3e9c0f6e6e4e (patch) | |
tree | d18e9cbdd059bab5379570b8c21d4c5e238fb929 /railties | |
parent | 4dee277a9bc05083de6c831cf9aae0846849ecda (diff) | |
download | rails-abfc4dad3ebb17eccd32d1f1eb8a3e9c0f6e6e4e.tar.gz rails-abfc4dad3ebb17eccd32d1f1eb8a3e9c0f6e6e4e.tar.bz2 rails-abfc4dad3ebb17eccd32d1f1eb8a3e9c0f6e6e4e.zip |
Remove global Rails initializers
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails.rb | 17 | ||||
-rw-r--r-- | railties/lib/rails/application.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/initializable.rb | 22 | ||||
-rw-r--r-- | railties/lib/rails/initializer.rb | 2 | ||||
-rw-r--r-- | railties/test/application/generators_test.rb | 26 | ||||
-rw-r--r-- | railties/test/application/initializer_test.rb | 16 | ||||
-rw-r--r-- | railties/test/initializer/check_ruby_version_test.rb | 7 |
7 files changed, 35 insertions, 59 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index c23b67e321..aeac85f4b3 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -10,4 +10,19 @@ require 'rails/core' require 'rails/configuration' require 'rails/deprecation' require 'rails/initializer' -require 'rails/plugin'
\ No newline at end of file +require 'rails/plugin' +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)
\ No newline at end of file diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 7ea79aa9c9..41ae3f9687 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -82,10 +82,6 @@ module Rails @app.call(env) end - initializer :initialize_rails do - Rails.run_initializers - end - # Set the <tt>$LOAD_PATH</tt> based on the value of # Configuration#load_paths. Duplicates are removed. initializer :set_load_path do diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index 3866b856b2..96234739cf 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -106,26 +106,4 @@ module Rails end end end - - include Initializable - - # Check for valid Ruby version (1.8.2 or 1.8.4 or higher). This is done in an - # external file, so we can use it from the `rails` program as well without duplication. - initializer :check_ruby_version, :global => true do - require 'rails/ruby_version_check' - end - - # 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. - initializer :initialize_encoding, :global => true do - if RUBY_VERSION < '1.9' - $KCODE='u' - else - Encoding.default_external = Encoding::UTF_8 - end - end end
\ No newline at end of file diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb index 44101dcc94..95478428ec 100644 --- a/railties/lib/rails/initializer.rb +++ b/railties/lib/rails/initializer.rb @@ -1,7 +1,5 @@ require "rails" # In case people require this file directly -RAILS_ENV = (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development').dup unless defined?(RAILS_ENV) - module Rails class Initializer class Error < StandardError ; end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index ccbcd84176..2ed49d1057 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -11,8 +11,16 @@ module ApplicationTests require "rails/generators" end + def app_const + @app_const ||= Class.new(Rails::Application) + end + + def with_config + yield app_const.config + end + test "generators default values" do - Rails::Initializer.run do |c| + with_config do |c| assert_equal(true, c.generators.colorize_logging) assert_equal({}, c.generators.aliases) assert_equal({}, c.generators.options) @@ -20,7 +28,7 @@ module ApplicationTests end test "generators set rails options" do - Rails::Initializer.run do |c| + with_config do |c| c.generators.orm = :datamapper c.generators.test_framework = :rspec c.generators.helper = false @@ -30,7 +38,7 @@ module ApplicationTests end test "generators set rails aliases" do - Rails::Initializer.run do |c| + with_config do |c| c.generators.aliases = { :rails => { :test_framework => "-w" } } expected = { :rails => { :test_framework => "-w" } } assert_equal expected, c.generators.aliases @@ -38,14 +46,14 @@ module ApplicationTests end test "generators aliases and options on initialization" do - Rails::Initializer.run do |c| + application = with_config do |c| c.frameworks = [] c.generators.rails :aliases => { :test_framework => "-w" } c.generators.orm :datamapper c.generators.test_framework :rspec end # Initialize the application - Rails.initialize! + app_const.initialize! Rails::Generators.configure! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] @@ -53,19 +61,19 @@ module ApplicationTests end test "generators no color on initialization" do - Rails::Initializer.run do |c| + with_config do |c| c.frameworks = [] c.generators.colorize_logging = false end # Initialize the application - Rails.initialize! + app_const.initialize! Rails::Generators.configure! assert_equal Thor::Base.shell, Thor::Shell::Basic end test "generators with hashes for options and aliases" do - Rails::Initializer.run do |c| + with_config do |c| c.generators do |g| g.orm :datamapper, :migration => false g.plugin :aliases => { :generator => "-g" }, @@ -84,7 +92,7 @@ module ApplicationTests end test "generators with hashes are deep merged" do - Rails::Initializer.run do |c| + with_config do |c| c.generators do |g| g.orm :datamapper, :migration => false g.plugin :aliases => { :generator => "-g" }, diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 719520bf68..1b319e8a6d 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -10,22 +10,6 @@ module ApplicationTests require "rails" end - test "initializing an application initializes rails" do - Rails::Initializer.run do |config| - config.root = app_path - end - - if RUBY_VERSION < '1.9' - $KCODE = '' - Rails.initialize! - assert_equal 'UTF8', $KCODE - else - Encoding.default_external = Encoding::US_ASCII - Rails.initialize! - assert_equal Encoding::UTF_8, Encoding.default_external - end - end - test "initializing an application adds the application paths to the load path" do Rails::Initializer.run do |config| config.root = app_path diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 97d884e1be..0691caad9d 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -7,7 +7,6 @@ module InitializerTests def setup build_app boot_rails - require "rails" end test "rails does not initialize with ruby version 1.8.1" do @@ -50,8 +49,7 @@ module InitializerTests def assert_rails_boots(version = nil) set_ruby_version(version) if version assert_nothing_raised "It appears that rails does not boot" do - Rails::Initializer.run { |c| c.frameworks = [] } - Rails.initialize! + require "rails" end end @@ -59,8 +57,7 @@ module InitializerTests set_ruby_version(version) $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do - Rails::Initializer.run { |c| c.frameworks = [] } - Rails.initialize! + require "rails" end end end |