Remove global Rails initializers

This commit is contained in:
Carlhuda
2009-11-30 15:58:38 -08:00
committed by Carlhuda
parent 4dee277a9b
commit abfc4dad3e
7 changed files with 35 additions and 59 deletions

View File

@@ -10,4 +10,19 @@ require 'rails/core'
require 'rails/configuration'
require 'rails/deprecation'
require 'rails/initializer'
require 'rails/plugin'
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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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" },

View File

@@ -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

View File

@@ -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