1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Set deprecation warnings for RAILS_ENV and RAILS_DEFAULT_LOGGER.

This commit is contained in:
José Valim 2010-01-12 14:11:47 +01:00
parent 9dd4c79d61
commit 1a275730b2
8 changed files with 70 additions and 49 deletions

View file

@ -51,8 +51,8 @@ module ActiveRecord
def self.establish_connection(spec = nil)
case spec
when nil
raise AdapterNotSpecified unless defined? RAILS_ENV
establish_connection(RAILS_ENV)
raise AdapterNotSpecified unless defined?(Rails.env)
establish_connection(Rails.env)
when ConnectionSpecification
@@connection_handler.establish_connection(name, spec)
when Symbol, String

View file

@ -26,9 +26,9 @@ namespace :db do
end
end
desc 'Create the database defined in config/database.yml for the current RAILS_ENV'
desc 'Create the database defined in config/database.yml for the current Rails.env'
task :create => :load_config do
create_database(ActiveRecord::Base.configurations[RAILS_ENV])
create_database(ActiveRecord::Base.configurations[Rails.env])
end
def create_database(config)
@ -111,9 +111,9 @@ namespace :db do
end
end
desc 'Drops the database for the current RAILS_ENV'
desc 'Drops the database for the current Rails.env'
task :drop => :load_config do
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
config = ActiveRecord::Base.configurations[Rails.env || 'development']
begin
drop_database(config)
rescue Exception => e
@ -188,7 +188,7 @@ namespace :db do
desc "Retrieves the charset for the current environment's database"
task :charset => :environment do
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
config = ActiveRecord::Base.configurations[Rails.env || 'development']
case config['adapter']
when 'mysql'
ActiveRecord::Base.establish_connection(config)
@ -203,7 +203,7 @@ namespace :db do
desc "Retrieves the collation for the current environment's database"
task :collation => :environment do
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
config = ActiveRecord::Base.configurations[Rails.env || 'development']
case config['adapter']
when 'mysql'
ActiveRecord::Base.establish_connection(config)
@ -305,36 +305,36 @@ namespace :db do
desc "Dump the database structure to a SQL file"
task :dump => :environment do
abcs = ActiveRecord::Base.configurations
case abcs[RAILS_ENV]["adapter"]
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 }
ActiveRecord::Base.establish_connection(abcs[Rails.env])
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"]
ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
search_path = abcs[RAILS_ENV]["schema_search_path"]
ENV['PGHOST'] = abcs[Rails.env]["host"] if abcs[Rails.env]["host"]
ENV['PGPORT'] = abcs[Rails.env]["port"].to_s if abcs[Rails.env]["port"]
ENV['PGPASSWORD'] = abcs[Rails.env]["password"].to_s if abcs[Rails.env]["password"]
search_path = abcs[Rails.env]["schema_search_path"]
unless search_path.blank?
search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
end
`pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
`pg_dump -i -U "#{abcs[Rails.env]["username"]}" -s -x -O -f db/#{Rails.env}_structure.sql #{search_path} #{abcs[Rails.env]["database"]}`
raise "Error dumping database" if $?.exitstatus == 1
when "sqlite", "sqlite3"
dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
`#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
dbfile = abcs[Rails.env]["database"] || abcs[Rails.env]["dbfile"]
`#{abcs[Rails.env]["adapter"]} #{dbfile} .schema > db/#{Rails.env}_structure.sql`
when "sqlserver"
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
`scptxfr /s #{abcs[Rails.env]["host"]} /d #{abcs[Rails.env]["database"]} /I /f db\\#{Rails.env}_structure.sql /q /A /r`
`scptxfr /s #{abcs[Rails.env]["host"]} /d #{abcs[Rails.env]["database"]} /I /F db\ /q /A /r`
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"
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"
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
@ -357,28 +357,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`
`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
@ -401,7 +401,7 @@ namespace :db do
when "sqlserver"
dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{Rails.env}_structure.sql`
when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|

View file

@ -129,12 +129,12 @@ module Rails
# The current Rails environment (development, test, or production).
property 'Environment' do
RAILS_ENV
Rails.env
end
# The name of the database adapter for the current environment.
property 'Database adapter' do
ActiveRecord::Base.configurations[RAILS_ENV]['adapter']
ActiveRecord::Base.configurations[Rails.env]['adapter']
end
property 'Database schema version' do

View file

@ -38,11 +38,6 @@ module Rails
config.load_once_paths.freeze
end
# TODO: Wrap in deprecation warning, everyone should be using Rails.env now
initializer :set_rails_env do
silence_warnings { Object.const_set "RAILS_ENV", Rails.env }
end
# Create tmp directories
initializer :ensure_tmp_directories_exist do
%w(cache pids sessions sockets).each do |dir_to_make|
@ -83,9 +78,6 @@ module Rails
)
logger
end
# TODO: Wrap it in a deprecation proxy
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", Rails.logger }
end
# Sets the logger for Active Record, Action Controller, and Action Mailer

View file

@ -6,8 +6,8 @@ RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
Rails.root
end
def replace(val)
puts OMG
def replace(*args)
warn(caller, :replace, *args)
end
def warn(callstack, called, args)
@ -15,3 +15,33 @@ RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
ActiveSupport::Deprecation.warn(msg, callstack)
end
end).new
RAILS_ENV = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
def target
Rails.env
end
def replace(*args)
warn(caller, :replace, *args)
end
def warn(callstack, called, args)
msg = "RAILS_ENV is deprecated! Use Rails.env instead."
ActiveSupport::Deprecation.warn(msg, callstack)
end
end).new
RAILS_DEFAULT_LOGGER = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
def target
Rails.logger
end
def replace(*args)
warn(caller, :replace, *args)
end
def warn(callstack, called, args)
msg = "RAILS_DEFAULT_LOGGER is deprecated! Use Rails.logger instead."
ActiveSupport::Deprecation.warn(msg, callstack)
end
end).new

View file

@ -1,6 +1,7 @@
task :default => :test
task :rails_env do
# TODO Do we really need this?
unless defined? RAILS_ENV
RAILS_ENV = ENV['RAILS_ENV'] ||= 'development'
end

View file

@ -1,5 +1,3 @@
# TODO: Fix this RAILS_ENV stuff
RAILS_ENV = 'test' unless defined?(RAILS_ENV)
require 'abstract_unit'
module Rails

View file

@ -63,7 +63,7 @@ module InitializerTests
end
test "environments has a glob equal to the current environment" do
assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.glob
assert_equal "#{Rails.env}.rb", @paths.config.environments.glob
end
test "load path includes each of the paths in config.paths as long as the directories exist" do
@ -85,17 +85,17 @@ module InitializerTests
end
test "controller paths include builtin in development mode" do
RAILS_ENV.replace "development"
Rails.env.replace "development"
assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
test "controller paths does not have builtin_directories in test mode" do
RAILS_ENV.replace "test"
Rails.env.replace "test"
assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
test "controller paths does not have builtin_directories in production mode" do
RAILS_ENV.replace "production"
Rails.env.replace "production"
assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end