aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/CHANGELOG3
-rwxr-xr-xrailties/fresh_rakefile26
-rw-r--r--railties/helpers/test_helper.rb2
3 files changed, 17 insertions, 14 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index bf27ddaa9b..008cf98c45 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,8 @@
*SVN*
+* Added that rake clone_structure_to_test, db_structure_dump, and purge_test_database tasks now pick up the source database to use from
+ RAILS_ENV instead of just forcing development #424 [Tobias Luetke]
+
* Fixed script/console to work with Windows (that requires the use of irb.bat) #418 [octopod]
* Fixed WEBrick servlet slowdown over time by restricting the load path reloading to mod_ruby
diff --git a/railties/fresh_rakefile b/railties/fresh_rakefile
index d46c057194..2a4ca7098b 100755
--- a/railties/fresh_rakefile
+++ b/railties/fresh_rakefile
@@ -10,7 +10,7 @@ require 'code_statistics'
require 'active_record/support/std_ext/test_unit_ext' # temporary fix until test/unit is cured for 1.8.2
desc "Run all the tests on a fresh test database"
-task :default => [ :clone_development_structure_to_test, :test_units, :test_functional ]
+task :default => [ :clone_structure_to_test, :test_units, :test_functional ]
desc "Generate API documentatio, show coding stats"
task :doc => [ :appdoc, :stats ]
@@ -74,36 +74,36 @@ task :stats do
end
desc "Recreate the test databases from the development structure"
-task :clone_development_structure_to_test => [ :db_structure_dump, :purge_test_database ] do
+task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do
if ActiveRecord::Base.configurations["test"]["adapter"] == "mysql"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
- IO.readlines("db/development_structure.sql").join.split("\n\n").each do |table|
+ IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
ActiveRecord::Base.connection.execute(table)
end
elsif ActiveRecord::Base.configurations["test"]["adapter"] == "postgresql"
- `psql -U #{ActiveRecord::Base.configurations["test"]["username"]} -f db/development_structure.sql #{ActiveRecord::Base.configurations["test"]["database"]}`
+ `psql -U #{ActiveRecord::Base.configurations["test"]["username"]} -f db/#{RAILS_ENV}_structure.sql #{ActiveRecord::Base.configurations["test"]["database"]}`
elsif ActiveRecord::Base.configurations["test"]["adapter"] == "sqlite"
- `sqlite #{ActiveRecord::Base.configurations["test"]["dbfile"]} < db/development_structure.sql`
+ `sqlite #{ActiveRecord::Base.configurations["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql`
end
end
desc "Dump the database structure to a SQL file"
task :db_structure_dump do
- if ActiveRecord::Base.configurations["development"]["adapter"] == "mysql"
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["development"])
- File.open("db/development_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
- elsif ActiveRecord::Base.configurations["development"]["adapter"] == "postgresql"
- `pg_dump -U #{ActiveRecord::Base.configurations["development"]["username"]} -s -f db/development_structure.sql #{ActiveRecord::Base.configurations["development"]["database"]}`
- elsif ActiveRecord::Base.configurations["development"]["adapter"] == "sqlite"
- `sqlite #{ActiveRecord::Base.configurations["development"]["dbfile"]} .schema > db/development_structure.sql`
+ if ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "mysql"
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV])
+ File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
+ elsif ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "postgresql"
+ `pg_dump -U #{ActiveRecord::Base.configurations[RAILS_ENV]["username"]} -s -f db/#{RAILS_ENV}_structure.sql #{ActiveRecord::Base.configurations[RAILS_ENV]["database"]}`
+ elsif ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "sqlite"
+ `sqlite #{ActiveRecord::Base.configurations[RAILS_ENV]["dbfile"]} .schema > db/#{RAILS_ENV}_structure.sql`
end
end
desc "Drop the test database and bring it back again"
task :purge_test_database do
if ActiveRecord::Base.configurations["test"]["adapter"] == "mysql"
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["development"])
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV])
ActiveRecord::Base.connection.recreate_database(ActiveRecord::Base.configurations["test"]["database"])
elsif ActiveRecord::Base.configurations["test"]["adapter"] == "postgresql"
`dropdb -U #{ActiveRecord::Base.configurations["test"]["username"]} #{ActiveRecord::Base.configurations["test"]["database"]}`
diff --git a/railties/helpers/test_helper.rb b/railties/helpers/test_helper.rb
index 83f4069ffd..e560caa79d 100644
--- a/railties/helpers/test_helper.rb
+++ b/railties/helpers/test_helper.rb
@@ -1,4 +1,4 @@
-ENV["RAILS_ENV"] ||= "test"
+ENV["RAILS_ENV"] = "test"
require File.dirname(__FILE__) + "/../config/environment"
require 'application'