提交 b231825f 编写于 作者: Y Yves Senn

Revert "Merge pull request #14940 from arunagw/hbakhtiyor-test-db-namespaces-ar"

This reverts commit fe985960, reversing
changes made to add95606.
上级 fe985960
...@@ -38,38 +38,33 @@ namespace :test do ...@@ -38,38 +38,33 @@ namespace :test do
end end
end end
desc 'Build MySQL and PostgreSQL test databases'
namespace :db do namespace :db do
task :create => ['mysql:db:build', 'postgresql:db:build'] desc 'Build MySQL and PostgreSQL test databases'
task :drop => ['mysql:db:drop', 'postgresql:db:drop'] task create: ['mysql:build_databases', 'postgresql:build_databases']
desc 'Drop MySQL and PostgreSQL test databases'
task drop: ['mysql:drop_databases', 'postgresql:drop_databases']
end end
%w( mysql mysql2 postgresql sqlite3 sqlite3_mem firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter| %w( mysql mysql2 postgresql sqlite3 sqlite3_mem firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
namespace :test do Rake::TestTask.new("test_#{adapter}") { |t|
namespace :db do adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
Rake::TestTask.new(adapter) { |t| t.libs << 'test'
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject {
t.libs << 'test' |x| x =~ /\/adapters\//
t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject { } + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")).sort
|x| x =~ /\/adapters\//
} + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")).sort t.warning = true
t.verbose = true
t.warning = true }
t.verbose = true
} task "isolated_test_#{adapter}" do
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
namespace :isolated do puts [adapter, adapter_short].inspect
task adapter do (Dir["test/cases/**/*_test.rb"].reject {
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] |x| x =~ /\/adapters\//
puts [adapter, adapter_short].inspect } + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file|
(Dir["test/cases/**/*_test.rb"].reject { sh(Gem.ruby, '-w' ,"-Itest", file)
|x| x =~ /\/adapters\// end or raise "Failures"
} + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file|
sh(Gem.ruby, '-w' ,"-Itest", file)
end or raise "Failures"
end
end
end
end end
namespace adapter do namespace adapter do
...@@ -81,8 +76,8 @@ end ...@@ -81,8 +76,8 @@ end
end end
# Make sure the adapter test evaluates the env setting task # Make sure the adapter test evaluates the env setting task
task "test_#{adapter}" => ["#{adapter}:env", "test:db:#{adapter}"] task "test_#{adapter}" => "#{adapter}:env"
task "isolated_test_#{adapter}" => ["#{adapter}:env", "test:db:isolated:#{adapter}"] task "isolated_test_#{adapter}" => "#{adapter}:env"
end end
rule '.sqlite3' do |t| rule '.sqlite3' do |t|
...@@ -95,109 +90,102 @@ task :test_sqlite3 => [ ...@@ -95,109 +90,102 @@ task :test_sqlite3 => [
] ]
namespace :mysql do namespace :mysql do
namespace :db do desc 'Build the MySQL test databases'
desc 'Build the MySQL test databases' task :build_databases do
task :build do config = ARTest.config['connections']['mysql']
config = ARTest.config['connections']['mysql'] %x( mysql --user=#{config['arunit']['username']} -e "create DATABASE #{config['arunit']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
%x( mysql --user=#{config['arunit']['username']} -e "create DATABASE #{config['arunit']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ") %x( mysql --user=#{config['arunit2']['username']} -e "create DATABASE #{config['arunit2']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
%x( mysql --user=#{config['arunit2']['username']} -e "create DATABASE #{config['arunit2']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ") end
end
desc 'Drop the MySQL test databases'
task :drop do
config = ARTest.config['connections']['mysql']
%x( mysqladmin --user=#{config['arunit']['username']} -f drop #{config['arunit']['database']} )
%x( mysqladmin --user=#{config['arunit2']['username']} -f drop #{config['arunit2']['database']} )
end
desc 'Rebuild the MySQL test databases' desc 'Drop the MySQL test databases'
task :rebuild => [:drop, :build] task :drop_databases do
config = ARTest.config['connections']['mysql']
%x( mysqladmin --user=#{config['arunit']['username']} -f drop #{config['arunit']['database']} )
%x( mysqladmin --user=#{config['arunit2']['username']} -f drop #{config['arunit2']['database']} )
end end
desc 'Rebuild the MySQL test databases'
task :rebuild_databases => [:drop_databases, :build_databases]
end end
task :build_mysql_databases => 'mysql:db:build' task :build_mysql_databases => 'mysql:build_databases'
task :drop_mysql_databases => 'mysql:db:drop' task :drop_mysql_databases => 'mysql:drop_databases'
task :rebuild_mysql_databases => 'mysql:db:rebuild' task :rebuild_mysql_databases => 'mysql:rebuild_databases'
namespace :postgresql do namespace :postgresql do
# notify about preparing hstore desc 'Build the PostgreSQL test databases'
namespace :db do task :build_databases do
desc 'Build the PostgreSQL test databases' config = ARTest.config['connections']['postgresql']
task :build do %x( createdb -E UTF8 -T template0 #{config['arunit']['database']} )
config = ARTest.config['connections']['postgresql'] %x( createdb -E UTF8 -T template0 #{config['arunit2']['database']} )
%x( createdb -E UTF8 -T template0 #{config['arunit']['database']} )
%x( createdb -E UTF8 -T template0 #{config['arunit2']['database']} )
# prepare hstore
if %x( createdb --version ).strip.gsub(/(.*)(\d\.\d\.\d)$/, "\\2") < "9.1.0"
puts "Please prepare hstore data type. See http://www.postgresql.org/docs/9.0/static/hstore.html"
end
end
desc 'Drop the PostgreSQL test databases' # notify about preparing hstore
task :drop do if %x( createdb --version ).strip.gsub(/(.*)(\d\.\d\.\d)$/, "\\2") < "9.1.0"
config = ARTest.config['connections']['postgresql'] puts "Please prepare hstore data type. See http://www.postgresql.org/docs/9.0/static/hstore.html"
%x( dropdb #{config['arunit']['database']} )
%x( dropdb #{config['arunit2']['database']} )
end end
end
desc 'Rebuild the PostgreSQL test databases' desc 'Drop the PostgreSQL test databases'
task :rebuild => [:drop, :build] task :drop_databases do
config = ARTest.config['connections']['postgresql']
%x( dropdb #{config['arunit']['database']} )
%x( dropdb #{config['arunit2']['database']} )
end end
desc 'Rebuild the PostgreSQL test databases'
task :rebuild_databases => [:drop_databases, :build_databases]
end end
task :build_postgresql_databases => 'postgresql:db:build' task :build_postgresql_databases => 'postgresql:build_databases'
task :drop_postgresql_databases => 'postgresql:db:drop' task :drop_postgresql_databases => 'postgresql:drop_databases'
task :rebuild_postgresql_databases => 'postgresql:db:rebuild' task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
namespace :frontbase do namespace :frontbase do
namespace :db do desc 'Build the FrontBase test databases'
desc 'Build the FrontBase test databases' task :build_databases => :rebuild_frontbase_databases
task :build => :rebuild_frontbase_databases
desc 'Rebuild the FrontBase test databases' desc 'Rebuild the FrontBase test databases'
task :rebuild do task :rebuild_databases do
build_frontbase_database = Proc.new do |db_name, sql_definition_file| build_frontbase_database = Proc.new do |db_name, sql_definition_file|
%( %(
STOP DATABASE #{db_name}; STOP DATABASE #{db_name};
DELETE DATABASE #{db_name}; DELETE DATABASE #{db_name};
CREATE DATABASE #{db_name}; CREATE DATABASE #{db_name};
CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM; CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM;
SET COMMIT FALSE; SET COMMIT FALSE;
CREATE USER RAILS; CREATE USER RAILS;
CREATE SCHEMA RAILS AUTHORIZATION RAILS; CREATE SCHEMA RAILS AUTHORIZATION RAILS;
COMMIT; COMMIT;
SET SESSION AUTHORIZATION RAILS; SET SESSION AUTHORIZATION RAILS;
SCRIPT '#{sql_definition_file}'; SCRIPT '#{sql_definition_file}';
COMMIT; COMMIT;
DISCONNECT ALL; DISCONNECT ALL;
) )
end end
config = ARTest.config['connections']['frontbase'] config = ARTest.config['connections']['frontbase']
create_activerecord_unittest = build_frontbase_database[config['arunit']['database'], File.join(SCHEMA_ROOT, 'frontbase.sql')] create_activerecord_unittest = build_frontbase_database[config['arunit']['database'], File.join(SCHEMA_ROOT, 'frontbase.sql')]
create_activerecord_unittest2 = build_frontbase_database[config['arunit2']['database'], File.join(SCHEMA_ROOT, 'frontbase2.sql')] create_activerecord_unittest2 = build_frontbase_database[config['arunit2']['database'], File.join(SCHEMA_ROOT, 'frontbase2.sql')]
execute_frontbase_sql = Proc.new do |sql| execute_frontbase_sql = Proc.new do |sql|
system(<<-SHELL) system(<<-SHELL)
/Library/FrontBase/bin/sql92 <<-SQL /Library/FrontBase/bin/sql92 <<-SQL
#{sql} #{sql}
SQL SQL
SHELL SHELL
end
execute_frontbase_sql[create_activerecord_unittest]
execute_frontbase_sql[create_activerecord_unittest2]
end end
execute_frontbase_sql[create_activerecord_unittest]
execute_frontbase_sql[create_activerecord_unittest2]
end end
end end
task :build_frontbase_databases => 'frontbase:db:build' task :build_frontbase_databases => 'frontbase:build_databases'
task :rebuild_frontbase_databases => 'frontbase:db:rebuild' task :rebuild_frontbase_databases => 'frontbase:rebuild_databases'
spec = eval(File.read('activerecord.gemspec')) spec = eval(File.read('activerecord.gemspec'))
......
...@@ -52,7 +52,7 @@ def heading ...@@ -52,7 +52,7 @@ def heading
def tasks def tasks
if activerecord? if activerecord?
['mysql:db:rebuild', "#{adapter}:#{'isolated_' if isolated?}test"] ['mysql:rebuild_databases', "#{adapter}:#{'isolated_' if isolated?}test"]
else else
["test#{':isolated' if isolated?}"] ["test#{':isolated' if isolated?}"]
end end
......
...@@ -265,15 +265,15 @@ This is how you run the Active Record test suite only for SQLite3: ...@@ -265,15 +265,15 @@ This is how you run the Active Record test suite only for SQLite3:
```bash ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake test:db:sqlite3 $ bundle exec rake test_sqlite3
``` ```
You can now run the tests as you did for `sqlite3`. The tasks are respectively You can now run the tests as you did for `sqlite3`. The tasks are respectively
```bash ```bash
test:db:mysql test_mysql
test:db:mysql2 test_mysql2
test:db:postgresql test_postgresql
``` ```
Finally, Finally,
......
...@@ -249,7 +249,7 @@ and create the test databases: ...@@ -249,7 +249,7 @@ and create the test databases:
```bash ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake mysql:db:build $ bundle exec rake mysql:build_databases
``` ```
PostgreSQL's authentication works differently. A simple way to set up the development environment for example is to run with your development account PostgreSQL's authentication works differently. A simple way to set up the development environment for example is to run with your development account
...@@ -267,7 +267,7 @@ and then create the test databases with ...@@ -267,7 +267,7 @@ and then create the test databases with
```bash ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake postgresql:db:build $ bundle exec rake postgresql:build_databases
``` ```
It is possible to build databases for both PostgreSQL and MySQL with It is possible to build databases for both PostgreSQL and MySQL with
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册