Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate RAILS_ROOT in favor of Rails.root (which proxies to the app…

…lication's object root)
  • Loading branch information...
commit 2110a524a4913815d036786aa01319fd67db0ee2 1 parent 6094e65
Carl Lerche authored
Showing with 138 additions and 141 deletions.
  1. +1 −1  actionpack/lib/action_controller/metal/helpers.rb
  2. +2 −0  activesupport/lib/active_support/testing/isolation.rb
  3. +1 −0  railties/bin/rails
  4. +2 −2 railties/builtin/rails_info/rails/info.rb
  5. +1 −1  railties/guides/source/2_2_release_notes.textile
  6. +1 −1  railties/guides/source/action_controller_overview.textile
  7. +4 −4 railties/guides/source/command_line.textile
  8. +2 −2 railties/lib/rails/backtrace_cleaner.rb
  9. +0 −1  railties/lib/rails/commands/about.rb
  10. +1 −1  railties/lib/rails/commands/console.rb
  11. +1 −1  railties/lib/rails/commands/dbconsole.rb
  12. +0 −1  railties/lib/rails/commands/destroy.rb
  13. +2 −2 railties/lib/rails/commands/server.rb
  14. +11 −23 railties/lib/rails/configuration.rb
  15. +2 −2 railties/lib/rails/core.rb
  16. +17 −0 railties/lib/rails/deprecation.rb
  17. +1 −1  railties/lib/rails/gem_dependency.rb
  18. +5 −5 railties/lib/rails/generators.rb
  19. +2 −2 railties/lib/rails/generators/base.rb
  20. +1 −1  railties/lib/rails/generators/rails/app/templates/config/application.rb
  21. +0 −3  railties/lib/rails/generators/rails/app/templates/config/boot.rb
  22. +1 −0  railties/lib/rails/initializer.rb
  23. +1 −1  railties/lib/rails/plugin/loader.rb
  24. +2 −2 railties/lib/rails/tasks.rb
  25. +12 −12 railties/lib/rails/tasks/databases.rake
  26. +4 −4 railties/lib/rails/tasks/framework.rake
  27. +1 −1  railties/lib/rails/tasks/gems.rake
  28. +1 −1  railties/lib/rails/tasks/misc.rake
  29. +1 −1  railties/lib/rails/test_help.rb
  30. +5 −5 railties/test/abstract_unit.rb
  31. +4 −4 railties/test/application/configuration_test.rb
  32. +2 −0  railties/test/application/generators_test.rb
  33. +32 −13 railties/test/application/initializer_test.rb
  34. +9 −3 railties/test/application/plugins_test.rb
  35. +0 −2  railties/test/backtrace_cleaner_test.rb
  36. +0 −1  railties/test/boot_test.rb
  37. +3 −17 railties/test/generators/generators_test_helper.rb
  38. +2 −0  railties/test/initializer/initialize_i18n_test.rb
  39. +1 −0  railties/test/initializer/path_test.rb
  40. +0 −20 railties/test/initializer_test.rb
View
2  actionpack/lib/action_controller/metal/helpers.rb
@@ -54,7 +54,7 @@ module Helpers
included do
# Set the default directory for helpers
extlib_inheritable_accessor(:helpers_dir) do
- defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/app/helpers" : "app/helpers"
+ defined?(Rails) ? "#{Rails.root}/app/helpers" : "app/helpers"
end
end
View
2  activesupport/lib/active_support/testing/isolation.rb
@@ -1,3 +1,5 @@
+require "active_support/core_ext/load_error"
+
module ActiveSupport
module Testing
class ProxyTestResult
View
1  railties/bin/rails
@@ -19,6 +19,7 @@ end
ARGV << "--help" if ARGV.empty?
+require 'rails'
require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
View
4 railties/builtin/rails_info/rails/info.rb
@@ -75,7 +75,7 @@ def to_html
protected
def rails_vendor_root
- @rails_vendor_root ||= "#{RAILS_ROOT}/vendor/rails"
+ @rails_vendor_root ||= "#{Rails.root}/vendor/rails"
end
def git_info
@@ -124,7 +124,7 @@ def git_info
# The application's location on the filesystem.
property 'Application root' do
- File.expand_path(RAILS_ROOT)
+ File.expand_path(Rails.root)
end
# The current Rails environment (development, test, or production).
View
2  railties/guides/source/2_2_release_notes.textile
@@ -51,7 +51,7 @@ If you want to generate these guides locally, inside your application:
rake doc:guides
</ruby>
-This will put the guides inside +RAILS_ROOT/doc/guides+ and you may start surfing straight away by opening +RAILS_ROOT/doc/guides/index.html+ in your favourite browser.
+This will put the guides inside +Rails.root/doc/guides+ and you may start surfing straight away by opening +Rails.root/doc/guides/index.html+ in your favourite browser.
* Lead Contributors: "Rails Documentation Team":http://guides.rails.info/credits.html
* Major contributions from "Xavier Noria":http://advogato.org/person/fxn/diary.html and "Hongli Lai":http://izumi.plan99.net/blog/.
View
2  railties/guides/source/action_controller_overview.textile
@@ -653,7 +653,7 @@ class ClientsController < ApplicationController
# Stream a file that has already been generated and stored on disk.
def download_pdf
client = Client.find(params[:id])
- send_data("#{RAILS_ROOT}/files/clients/#{client.id}.pdf",
+ send_data("#{Rails.root}/files/clients/#{client.id}.pdf",
:filename => "#{client.name}.pdf",
:type => "application/pdf")
end
View
8 railties/guides/source/command_line.textile
@@ -424,10 +424,10 @@ INFO: For a good rundown on generators, see "Understanding Generators":http://wi
Generators are code that generates code. Let's experiment by building one. Our generator will generate a text file.
-The Rails generator by default looks in these places for available generators, where RAILS_ROOT is the root of your Rails application, like /home/foobar/commandsapp:
+The Rails generator by default looks in these places for available generators, where Rails.root is the root of your Rails application, like /home/foobar/commandsapp:
-* RAILS_ROOT/lib/generators
-* RAILS_ROOT/vendor/generators
+* Rails.root/lib/generators
+* Rails.root/vendor/generators
* Inside any plugin with a directory like "generators" or "rails_generators"
* ~/.rails/generators
* Inside any Gem you have installed with a name ending in "_generator"
@@ -465,7 +465,7 @@ We take whatever args are supplied, save them to an instance variable, and liter
* Check there's a *public* directory. You bet there is.
* Run the ERb template called "tutorial.erb".
-* Save it into "RAILS_ROOT/public/tutorial.txt".
+* Save it into "Rails.root/public/tutorial.txt".
* Pass in the arguments we saved through the +:assign+ parameter.
Next we'll build the template:
View
4 railties/lib/rails/backtrace_cleaner.rb
@@ -18,7 +18,7 @@ class BacktraceCleaner < ActiveSupport::BacktraceCleaner
def initialize
super
- add_filter { |line| line.sub("#{RAILS_ROOT}/", '') }
+ add_filter { |line| line.sub("#{Rails.root}/", '') }
add_filter { |line| line.sub(ERB_METHOD_SIG, '') }
add_filter { |line| line.sub('./', '/') } # for tests
@@ -37,7 +37,7 @@ def add_gem_filters
add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
end
- vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{RAILS_ROOT}/",'')
+ vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{Rails.root}/",'')
add_filter { |line| line.sub(/(#{vendor_gems_path})\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) [v] \4')}
end
end
View
1  railties/lib/rails/commands/about.rb
@@ -1,4 +1,3 @@
-require "#{RAILS_ROOT}/config/application"
Rails.application.new
require 'rails/info'
puts Rails::Info
View
2  railties/lib/rails/commands/console.rb
@@ -12,7 +12,7 @@
end
libs = " -r irb/completion"
-libs << %( -r "#{RAILS_ROOT}/config/environment")
+libs << %( -r "#{Rails.root}/config/environment")
libs << " -r rails/console_app"
libs << " -r rails/console_sandbox" if options[:sandbox]
libs << " -r rails/console_with_helpers"
View
2  railties/lib/rails/commands/dbconsole.rb
@@ -25,7 +25,7 @@
end
env = ARGV.first || ENV['RAILS_ENV'] || 'development'
-unless config = YAML::load(ERB.new(IO.read(RAILS_ROOT + "/config/database.yml")).result)[env]
+unless config = YAML::load(ERB.new(IO.read(Rails.root + "/config/database.yml")).result)[env]
abort "No database is configured for the environment '#{env}'"
end
View
1  railties/lib/rails/commands/destroy.rb
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators'))
-require "#{RAILS_ROOT}/config/application"
if ARGV.size == 0
Rails::Generators.help
View
4 railties/lib/rails/commands/server.rb
@@ -7,7 +7,7 @@
:Port => 3000,
:Host => "0.0.0.0",
:environment => (ENV['RAILS_ENV'] || "development").dup,
- :config => RAILS_ROOT + "/config.ru",
+ :config => Rails.root + "/config.ru",
:detach => false,
:debugger => false
}
@@ -46,7 +46,7 @@
if options[:detach]
Process.daemon
- pid = "#{RAILS_ROOT}/tmp/pids/server.pid"
+ pid = "#{Rails.root}/tmp/pids/server.pid"
File.open(pid, 'w'){ |f| f.write(Process.pid) }
at_exit { File.delete(pid) if File.exist?(pid) }
end
View
34 railties/lib/rails/configuration.rb
@@ -34,37 +34,25 @@ def after_initialize(&blk)
def root
@root ||= begin
- if defined?(RAILS_ROOT)
- root = RAILS_ROOT
- else
- call_stack = caller.map { |p| p.split(':').first }
- root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails] }
- root_path = File.dirname(root_path)
-
- while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/config.ru")
- parent = File.dirname(root_path)
- root_path = parent != root_path && parent
- end
-
- Object.class_eval("RAILS_ROOT = ''")
+ call_stack = caller.map { |p| p.split(':').first }
+ root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails] }
+ root_path = File.dirname(root_path)
- root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd
+ while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/config.ru")
+ parent = File.dirname(root_path)
+ root_path = parent != root_path && parent
end
- root = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ?
- Pathname.new(root).expand_path.to_s :
- Pathname.new(root).realpath.to_s
+ root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd
- # TODO: Remove RAILS_ROOT
- RAILS_ROOT.replace(root)
- root
+ RUBY_PLATFORM =~ /(:?mswin|mingw)/ ?
+ Pathname.new(root).expand_path :
+ Pathname.new(root).realpath
end
end
def root=(root)
- Object.class_eval("RAILS_ROOT = ''") unless defined?(RAILS_ROOT)
- RAILS_ROOT.replace(root)
- @root = root
+ @root = Pathname.new(root).expand_path
end
def paths
View
4 railties/lib/rails/core.rb
@@ -6,7 +6,7 @@ module Rails
# TODO: w0t?
class << self
def application
- @@application
+ @@application ||= nil
end
def application=(application)
@@ -43,7 +43,7 @@ def backtrace_cleaner
end
def root
- Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT)
+ application && application.config.root
end
def env
View
17 railties/lib/rails/deprecation.rb
@@ -0,0 +1,17 @@
+require "active_support/string_inquirer"
+require "active_support/deprecation"
+
+RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
+ def target
+ Rails.root
+ end
+
+ def replace(val)
+ puts OMG
+ end
+
+ def warn(callstack, called, args)
+ msg = "RAILS_ROOT is deprecated! Use Rails.root instead."
+ ActiveSupport::Deprecation.warn(msg, callstack)
+ end
+end).new
View
2  railties/lib/rails/gem_dependency.rb
@@ -11,7 +11,7 @@ class GemDependency < Gem::Dependency
attr_accessor :lib, :source, :dep
def self.unpacked_path
- @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems')
+ @unpacked_path ||= File.join(Rails.root, 'vendor', 'gems')
end
@@framework_gems = {}
View
10 railties/lib/rails/generators.rb
@@ -92,8 +92,8 @@ def self.gems_generators_paths
generator_path = File.join(spec.full_gem_path, "lib/generators")
paths << generator_path if File.exist?(generator_path)
end
- elsif defined?(RAILS_ROOT)
- paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")]
+ elsif defined?(Rails.root)
+ paths += Dir[File.join(Rails.root, "vendor", "gems", "gems", "*", "lib", "generators")]
end
paths
@@ -102,8 +102,8 @@ def self.gems_generators_paths
# Load paths from plugin.
#
def self.plugins_generators_paths
- return [] unless defined?(RAILS_ROOT)
- Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
+ return [] unless Rails.root
+ Dir[File.join(Rails.root, "vendor", "plugins", "*", "lib", "generators")]
end
# Hold configured generators fallbacks. If a plugin developer wants a
@@ -143,7 +143,7 @@ def self.no_color!
def self.load_paths
@load_paths ||= begin
paths = []
- paths << File.join(RAILS_ROOT, "lib", "generators") if defined?(RAILS_ROOT)
+ paths << File.join(Rails.root, "lib", "generators") if Rails.root
paths << File.join(Thor::Util.user_home, ".rails", "generators")
paths += self.plugins_generators_paths
paths += self.gems_generators_paths
View
4 railties/lib/rails/generators/base.rb
@@ -203,8 +203,8 @@ def self.inherited(base) #:nodoc:
super
base.source_root # Cache source root
- if defined?(RAILS_ROOT) && base.name !~ /Base$/
- path = File.expand_path(File.join(RAILS_ROOT, 'lib', 'templates'))
+ if Rails.root && base.name !~ /Base$/
+ path = File.expand_path(File.join(Rails.root, 'lib', 'templates'))
if base.name.include?('::')
base.source_paths << File.join(path, base.base_name, base.generator_name)
else
View
2  railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -7,7 +7,7 @@
# -- all .rb files in that directory are automatically loaded.
# Add additional load paths for your own custom dirs
- # config.load_paths += %W( #{RAILS_ROOT}/extras )
+ # config.load_paths += %W( #{root}/extras )
# Specify gems that this application depends on and have them installed with rake gems:install
# config.gem "bj"
View
3  railties/lib/rails/generators/rails/app/templates/config/boot.rb
@@ -1,8 +1,6 @@
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
module Rails
# Mark the version of Rails that generated the boot.rb file. This is
# a temporary solution and will most likely be removed as Rails 3.0
@@ -70,7 +68,6 @@ class VendorBoot < Boot
def load_initializer
require "rails"
install_gem_spec_stubs
- Rails::GemDependency.add_frozen_gem_path
end
def install_gem_spec_stubs
View
1  railties/lib/rails/initializer.rb
@@ -9,6 +9,7 @@
require 'rails/paths'
require 'rails/core'
require 'rails/configuration'
+require 'rails/deprecation'
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
View
2  railties/lib/rails/plugin/loader.rb
@@ -147,7 +147,7 @@ def effective_order_of(plugin)
end
def application_lib_index
- $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0
+ $LOAD_PATH.index(File.join(Rails.root, 'lib')) || 0
end
def enabled?(plugin)
View
4 railties/lib/rails/tasks.rb
@@ -20,5 +20,5 @@
# Load any custom rakefile extensions
# TODO: Don't hardcode these paths.
-Dir["#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
-Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
+Dir["#{Rails.root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
+Dir["#{Rails.root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
View
24 railties/lib/rails/tasks/databases.rake
@@ -283,7 +283,7 @@ namespace :db do
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
task :dump => :environment do
require 'active_record/schema_dumper'
- File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file|
+ File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
Rake::Task["db:schema:dump"].reenable
@@ -291,11 +291,11 @@ namespace :db do
desc "Load a schema.rb file into the database"
task :load => :environment do
- file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
+ file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
if File.exists?(file)
load(file)
else
- abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{RAILS_ROOT}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
+ abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
end
end
end
@@ -307,7 +307,7 @@ namespace :db do
case abcs[RAILS_ENV]["adapter"]
when "mysql", "oci", "oracle"
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
- File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
+ File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
when "postgresql"
ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
@@ -327,13 +327,13 @@ namespace :db do
when "firebird"
set_firebird_env(abcs[RAILS_ENV])
db_string = firebird_db_string(abcs[RAILS_ENV])
- sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql"
+ sh "isql -a #{db_string} > #{Rails.root}/db/#{RAILS_ENV}_structure.sql"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
if ActiveRecord::Base.connection.supports_migrations?
- File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
+ File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
end
end
end
@@ -356,28 +356,28 @@ namespace :db do
when "mysql"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
- IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
+ IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
ActiveRecord::Base.connection.execute(table)
end
when "postgresql"
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
- `psql -U "#{abcs["test"]["username"]}" -f #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
+ `psql -U "#{abcs["test"]["username"]}" -f #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
when "sqlite", "sqlite3"
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
- `#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql`
+ `#{abcs["test"]["adapter"]} #{dbfile} < #{Rails.root}/db/#{RAILS_ENV}_structure.sql`
when "sqlserver"
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test)
- IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
+ IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl)
end
when "firebird"
set_firebird_env(abcs["test"])
db_string = firebird_db_string(abcs["test"])
- sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}"
+ sh "isql -i #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{db_string}"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
@@ -446,7 +446,7 @@ def drop_database(config)
when /^sqlite/
require 'pathname'
path = Pathname.new(config['database'])
- file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path)
+ file = path.absolute? ? path.to_s : File.join(Rails.root, path)
FileUtils.rm(file)
when 'postgresql'
View
8 railties/lib/rails/tasks/framework.rake
@@ -86,7 +86,7 @@ namespace :rails do
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
require 'generators'
- generator = Rails::Generators::App.new [ RAILS_ROOT ], {}, :destination_root => RAILS_ROOT
+ generator = Rails::Generators::App.new [ Rails.root ], {}, :destination_root => Rails.root
generator.apply template, :verbose => false
end
@@ -96,7 +96,7 @@ namespace :rails do
require 'rails/generators/rails/app/app_generator'
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
- :destination_root => RAILS_ROOT
+ :destination_root => Rails.root
generator.invoke(method)
end
@@ -117,8 +117,8 @@ namespace :rails do
desc "Rename application.rb to application_controller.rb"
task :application_controller do
- old_style = RAILS_ROOT + '/app/controllers/application.rb'
- new_style = RAILS_ROOT + '/app/controllers/application_controller.rb'
+ old_style = Rails.root + '/app/controllers/application.rb'
+ new_style = Rails.root + '/app/controllers/application_controller.rb'
if File.exists?(old_style) && !File.exists?(new_style)
FileUtils.mv(old_style, new_style)
puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
View
2  railties/lib/rails/tasks/gems.rake
@@ -61,7 +61,7 @@ def current_gems
end
def frozen_gems(load_specs=true)
- Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*-*')].map do |gem_dir|
+ Dir[File.join(Rails.root, 'vendor', 'gems', '*-*')].map do |gem_dir|
Rails::GemDependency.from_directory_name(gem_dir, load_specs)
end
end
View
2  railties/lib/rails/tasks/misc.rake
@@ -1,7 +1,7 @@
task :default => :test
task :environment do
$rails_rake_task = true
- require(File.join(RAILS_ROOT, 'config', 'environment'))
+ require(File.join(Rails.root, 'config', 'environment'))
end
task :rails_env do
View
2  railties/lib/rails/test_help.rb
@@ -17,7 +17,7 @@
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
- self.fixture_path = "#{RAILS_ROOT}/test/fixtures/"
+ self.fixture_path = "#{Rails.root}/test/fixtures/"
self.use_instantiated_fixtures = false
self.use_transactional_fixtures = true
end
View
10 railties/test/abstract_unit.rb
@@ -14,15 +14,15 @@
require 'stringio'
require 'test/unit'
+require 'fileutils'
require 'active_support'
require 'active_support/core_ext/logger'
require 'active_support/test_case'
require 'action_controller'
+require 'rails'
-if defined?(RAILS_ROOT)
- RAILS_ROOT.replace File.dirname(__FILE__)
-else
- RAILS_ROOT = File.dirname(__FILE__)
-end
+Rails::Initializer.run do |config|
+ config.root = File.dirname(__FILE__)
+end
View
8 railties/test/application/configuration_test.rb
@@ -12,7 +12,7 @@ def setup
test "the application root is set correctly" do
require "#{app_path}/config/environment"
- assert_equal app_path, Rails.application.root
+ assert_equal Pathname.new(app_path), Rails.application.root
end
test "the application root can be set" do
@@ -22,7 +22,7 @@ def setup
config.root = '#{app_path}/hello'
RUBY
require "#{app_path}/config/environment"
- assert_equal "#{app_path}/hello", Rails.application.root
+ assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root
end
test "the application root is detected as where config.ru is located" do
@@ -31,7 +31,7 @@ def setup
RUBY
FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru"
require "#{app_path}/config/environment"
- assert_equal "#{app_path}/config", Rails.application.root
+ assert_equal Pathname.new("#{app_path}/config"), Rails.application.root
end
test "the application root is Dir.pwd if there is no config.ru" do
@@ -42,7 +42,7 @@ def setup
Dir.chdir("#{app_path}/app") do
require "#{app_path}/config/environment"
- assert_equal "#{app_path}/app", Rails.application.root
+ assert_equal Pathname.new("#{app_path}/app"), Rails.application.root
end
end
end
View
2  railties/test/application/generators_test.rb
@@ -37,6 +37,7 @@ def setup
test "generators aliases and options on initialization" do
Rails::Initializer.run do |c|
+ c.frameworks = []
c.generators.rails :aliases => { :test_framework => "-w" }
c.generators.orm :datamapper
c.generators.test_framework :rspec
@@ -50,6 +51,7 @@ def setup
test "generators no color on initialization" do
Rails::Initializer.run do |c|
+ c.frameworks = []
c.generators.colorize_logging = false
end
# Initialize the application
View
45 railties/test/application/initializer_test.rb
@@ -10,33 +10,38 @@ def setup
end
test "initializing an application initializes rails" do
- class MyApp < Rails::Application ; end
+ Rails::Initializer.run do |config|
+ config.root = app_path
+ end
if RUBY_VERSION < '1.9'
$KCODE = ''
- MyApp.new
+ Rails.application.new
assert_equal 'UTF8', $KCODE
else
Encoding.default_external = Encoding::US_ASCII
- MyApp.new
+ Rails.application.new
assert_equal Encoding::UTF_8, Encoding.default_external
end
end
test "initializing an application adds the application paths to the load path" do
- class MyApp < Rails::Application ; end
+ Rails::Initializer.run do |config|
+ config.root = app_path
+ end
- MyApp.new
+ Rails.application.new
assert $:.include?("#{app_path}/app/models")
end
test "adding an unknown framework raises an error" do
- class MyApp < Rails::Application
+ Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks << :action_foo
end
assert_raises RuntimeError do
- MyApp.new
+ Rails.application.new
end
end
@@ -49,6 +54,7 @@ module Zoo::ReptileHouse ; end
ZOO
Rails::Initializer.run do |config|
+ config.root = app_path
config.eager_load_paths = "#{app_path}/lib"
end
@@ -60,7 +66,7 @@ module Zoo::ReptileHouse ; end
test "load environment with global" do
app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'"
assert_nil $initialize_test_set_from_env
- Rails::Initializer.run { }
+ Rails::Initializer.run { |config| config.root = app_path }
Rails.application.new
assert_equal "success", $initialize_test_set_from_env
end
@@ -68,6 +74,7 @@ module Zoo::ReptileHouse ; end
test "action_controller load paths set only if action controller in use" do
assert_nothing_raised NameError do
Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks = []
end
Rails.application.new
@@ -76,6 +83,7 @@ module Zoo::ReptileHouse ; end
test "action_pack is added to the load path if action_controller is required" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks = [:action_controller]
end
Rails.application.new
@@ -85,6 +93,7 @@ module Zoo::ReptileHouse ; end
test "action_pack is added to the load path if action_view is required" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks = [:action_view]
end
Rails.application.new
@@ -94,6 +103,7 @@ module Zoo::ReptileHouse ; end
test "after_initialize block works correctly" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.after_initialize { $test_after_initialize_block1 = "success" }
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
end
@@ -105,6 +115,7 @@ module Zoo::ReptileHouse ; end
test "after_initialize block works correctly when no block is passed" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.after_initialize { $test_after_initialize_block1 = "success" }
config.after_initialize # don't pass a block, this is what we're testing!
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
@@ -118,6 +129,7 @@ module Zoo::ReptileHouse ; end
# i18n
test "setting another default locale" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.i18n.default_locale = :de
end
Rails.application.new
@@ -128,18 +140,21 @@ module Zoo::ReptileHouse ; end
test "no config locales dir present should return empty load path" do
FileUtils.rm_rf "#{app_path}/config/locales"
Rails::Initializer.run do |c|
+ c.root = app_path
assert_equal [], c.i18n.load_path
end
end
test "config locales dir present should be added to load path" do
Rails::Initializer.run do |c|
+ c.root = app_path
assert_equal ["#{app_path}/config/locales/en.yml"], c.i18n.load_path
end
end
test "config defaults should be added with config settings" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.i18n.load_path << "my/other/locale.yml"
end
@@ -151,6 +166,7 @@ module Zoo::ReptileHouse ; end
# DB middleware
test "database middleware doesn't initialize when session store is not active_record" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.action_controller.session_store = :cookie_store
end
Rails.application.new
@@ -160,6 +176,7 @@ module Zoo::ReptileHouse ; end
test "database middleware doesn't initialize when activerecord is not in frameworks" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.frameworks = []
end
assert_equal [], Rails.application.config.middleware
@@ -167,6 +184,7 @@ module Zoo::ReptileHouse ; end
test "database middleware initializes when session store is active record" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.action_controller.session_store = :active_record_store
end
Rails.application.new
@@ -178,6 +196,7 @@ module Zoo::ReptileHouse ; end
test "ensure database middleware doesn't use action_controller on initializing" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.frameworks -= [:action_controller]
c.action_controller.session_store = :active_record_store
end
@@ -189,6 +208,7 @@ module Zoo::ReptileHouse ; end
# Pathview test
test "load view paths doesn't perform anything when action_view not in frameworks" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.frameworks -= [:action_view]
end
Rails.application.new
@@ -197,12 +217,11 @@ module Zoo::ReptileHouse ; end
assert_equal [], ActionController::Base.view_paths
end
- # Rails root test
- test "Rails.root == RAILS_ROOT" do
- assert_equal RAILS_ROOT, Rails.root.to_s
- end
-
test "Rails.root should be a Pathname" do
+ Rails::Initializer.run do |c|
+ c.root = app_path
+ end
+ Rails.application.new
assert_instance_of Pathname, Rails.root
end
end
View
12 railties/test/application/plugins_test.rb
@@ -17,7 +17,7 @@ def setup
end
test "all plugins are loaded when registered plugin list is untouched" do
- Rails::Initializer.run { }
+ Rails::Initializer.run { |c| c.root = app_path }
Rails.application.new
assert_plugins [
:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby
@@ -25,19 +25,20 @@ def setup
end
test "no plugins are loaded if the configuration has an empty plugin list" do
- Rails::Initializer.run { |c| c.plugins = [] }
+ Rails::Initializer.run { |c| c.root = app_path; c.plugins = [] }
assert_plugins [], Rails.application.config.loaded_plugins
end
test "only the specified plugins are located in the order listed" do
plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
- Rails::Initializer.run { |c| c.plugins = plugin_names }
+ Rails::Initializer.run { |c| c.root = app_path; c.plugins = plugin_names }
Rails.application.new
assert_plugins plugin_names, Rails.application.config.loaded_plugins
end
test "all plugins loaded after all" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.plugins = [:stubby, :all, :acts_as_chunky_bacon]
end
Rails.application.new
@@ -47,6 +48,7 @@ def setup
test "plugin names may be strings" do
plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
Rails::Initializer.run do |config|
+ config.root = app_path
config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
end
Rails.application.new
@@ -56,6 +58,7 @@ def setup
test "all plugins loaded when all is used" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.plugins = [:stubby, :acts_as_chunky_bacon, :all]
end
Rails.application.new
@@ -65,6 +68,7 @@ def setup
test "all loaded plugins are added to the load paths" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.plugins = [:stubby, :acts_as_chunky_bacon]
end
Rails.application.new
@@ -75,6 +79,7 @@ def setup
test "registering a plugin name that does not exist raises a load error" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.plugins = [:stubby, :acts_as_a_non_existant_plugin]
end
@@ -89,6 +94,7 @@ def setup
begin
Rails::Initializer.run do |config|
+ config.root = app_path
config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2]
end
Rails.application.new
View
2  railties/test/backtrace_cleaner_test.rb
@@ -1,6 +1,4 @@
require 'abstract_unit'
-
-require 'rails/initializer'
require 'rails/backtrace_cleaner'
if defined? Test::Unit::Util::BacktraceFilter
View
1  railties/test/boot_test.rb
@@ -57,7 +57,6 @@ def test_load_initializer_requires_from_vendor_rails
boot = VendorBoot.new
boot.expects(:require).with("rails")
boot.expects(:install_gem_spec_stubs)
- Rails::GemDependency.expects(:add_frozen_gem_path)
boot.load_initializer
end
end
View
20 railties/test/generators/generators_test_helper.rb
@@ -1,24 +1,10 @@
-require 'test/unit'
-require 'fileutils'
-
-fixtures = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
-if defined?(RAILS_ROOT)
- RAILS_ROOT.replace fixtures
-else
- RAILS_ROOT = fixtures
-end
-
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activemodel/lib"
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib"
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
# TODO: Fix this RAILS_ENV stuff
RAILS_ENV = 'test'
-require "rails/core"
-require 'rails/generators'
+require 'abstract_unit'
+Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
+require 'rails/generators'
require 'rubygems'
-
require 'active_record'
require 'action_dispatch'
View
2  railties/test/initializer/initialize_i18n_test.rb
@@ -12,6 +12,7 @@ def setup
# test_config_defaults_and_settings_should_be_added_to_i18n_defaults
test "i18n config defaults and settings should be added to i18n defaults" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.i18n.load_path << "my/other/locale.yml"
end
Rails.application.new
@@ -34,6 +35,7 @@ def setup
app_file "vendor/plugins/engine/config/locales/en.yml", "hello:"
Rails::Initializer.run do |c|
+ c.root = app_path
c.i18n.load_path << "my/other/locale.yml"
end
Rails.application.new
View
1  railties/test/initializer/path_test.rb
@@ -7,6 +7,7 @@ def setup
build_app
boot_rails
Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record]
config.after_initialize do
ActionController::Base.session_store = nil
View
20 railties/test/initializer_test.rb
@@ -1,20 +0,0 @@
-require 'abstract_unit'
-require 'rails/initializer'
-require 'rails/generators'
-
-require 'action_view'
-require 'action_mailer'
-require 'active_record'
-
-require 'plugin_test_helper'
-
-class RailsRootTest < Test::Unit::TestCase
- def test_rails_dot_root_equals_rails_root
- assert_equal RAILS_ROOT, Rails.root.to_s
- end
-
- def test_rails_dot_root_should_be_a_pathname
- assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s
- end
-end
-

2 comments on commit 2110a52

@jpartogi

In "railties/lib/rails/generators/rails/app/templates/config/boot.rb" there's still RAILS_ROOT:

Should that be changed too? Otherwise this error will showup:
config/boot.rb:35:in `preinitializer_path': uninitialized constant Module::RAILS_ROOT (NameError)

@carllerche
Collaborator

Yep.. thanks for pointing it out :)

Please sign in to comment.
Something went wrong with that request. Please try again.