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

Merge pull request #14962 from arunagw/aa-fix-rake-activerecord

Reorganize ActiveRecord tasks [Arun Agrawal & Abd ar-Rahman Hamidi]
This commit is contained in:
Yves Senn 2014-05-19 09:34:43 +02:00
commit c6ee495e2e
4 changed files with 83 additions and 80 deletions

View file

@ -38,33 +38,36 @@ namespace :test do
end end
end end
desc 'Build MySQL and PostgreSQL test databases'
namespace :db do namespace :db do
desc 'Build MySQL and PostgreSQL test databases' task :create => ['db:mysql:build', 'db:postgresql:build']
task create: ['mysql:build_databases', 'postgresql:build_databases'] task :drop => ['db:mysql:drop', 'db:postgresql:drop']
desc 'Drop MySQL and PostgreSQL test databases'
task drop: ['mysql:drop_databases', 'postgresql:drop_databases']
end end
%w( mysql mysql2 postgresql sqlite3 sqlite3_mem db2 oracle jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter| %w( mysql mysql2 postgresql sqlite3 sqlite3_mem db2 oracle jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
Rake::TestTask.new("test_#{adapter}") { |t| namespace :test do
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] Rake::TestTask.new(adapter => "#{adapter}:env") { |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.warning = true
t.verbose = true t.verbose = true
} }
task "isolated_test_#{adapter}" do namespace :isolated do
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] task adapter => "#{adapter}:env" do
puts [adapter, adapter_short].inspect adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
(Dir["test/cases/**/*_test.rb"].reject { puts [adapter, adapter_short].inspect
|x| x =~ /\/adapters\// (Dir["test/cases/**/*_test.rb"].reject {
} + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file| |x| x =~ /\/adapters\//
sh(Gem.ruby, '-w' ,"-Itest", file) } + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file|
end or raise "Failures" sh(Gem.ruby, '-w' ,"-Itest", file)
end or raise "Failures"
end
end
end end
namespace adapter do namespace adapter do
@ -76,8 +79,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" task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
task "isolated_test_#{adapter}" => "#{adapter}:env" task "isolated_test_#{adapter}" => ["#{adapter}:env", "test:isolated:#{adapter}"]
end end
rule '.sqlite3' do |t| rule '.sqlite3' do |t|
@ -89,63 +92,58 @@ task :test_sqlite3 => [
'test/fixtures/fixture_database_2.sqlite3' 'test/fixtures/fixture_database_2.sqlite3'
] ]
namespace :mysql do namespace :db do
desc 'Build the MySQL test databases' namespace :mysql do
task :build_databases do desc 'Build the MySQL test databases'
config = ARTest.config['connections']['mysql'] task :build do
%x( mysql --user=#{config['arunit']['username']} -e "create DATABASE #{config['arunit']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ") config = ARTest.config['connections']['mysql']
%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['arunit']['username']} -e "create DATABASE #{config['arunit']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
end %x( mysql --user=#{config['arunit2']['username']} -e "create DATABASE #{config['arunit2']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
desc 'Drop the MySQL test databases'
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
desc 'Rebuild the MySQL test databases'
task :rebuild_databases => [:drop_databases, :build_databases]
end
task :build_mysql_databases => 'mysql:build_databases'
task :drop_mysql_databases => 'mysql:drop_databases'
task :rebuild_mysql_databases => 'mysql:rebuild_databases'
namespace :postgresql do
desc 'Build the PostgreSQL test databases'
task :build_databases do
config = ARTest.config['connections']['postgresql']
%x( createdb -E UTF8 -T template0 #{config['arunit']['database']} )
%x( createdb -E UTF8 -T template0 #{config['arunit2']['database']} )
# notify about preparing 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 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'
task :rebuild => [:drop, :build]
end end
desc 'Drop the PostgreSQL test databases' namespace :postgresql do
task :drop_databases do desc 'Build the PostgreSQL test databases'
config = ARTest.config['connections']['postgresql'] task :build do
%x( dropdb #{config['arunit']['database']} ) config = ARTest.config['connections']['postgresql']
%x( dropdb #{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'
task :drop do
config = ARTest.config['connections']['postgresql']
%x( dropdb #{config['arunit']['database']} )
%x( dropdb #{config['arunit2']['database']} )
end
desc 'Rebuild the PostgreSQL test databases'
task :rebuild => [:drop, :build]
end end
desc 'Rebuild the PostgreSQL test databases'
task :rebuild_databases => [:drop_databases, :build_databases]
end end
task :build_postgresql_databases => 'postgresql:build_databases' task :build_mysql_databases => 'db:mysql:build'
task :drop_postgresql_databases => 'postgresql:drop_databases' task :drop_mysql_databases => 'db:mysql:drop'
task :rebuild_postgresql_databases => 'postgresql:rebuild_databases' task :rebuild_mysql_databases => 'db:mysql:rebuild'
task :build_postgresql_databases => 'db:postgresql:build'
spec = eval(File.read('activerecord.gemspec')) task :drop_postgresql_databases => 'db:postgresql:drop'
Gem::PackageTask.new(spec) do |p| task :rebuild_postgresql_databases => 'db:postgresql:rebuild'
p.gem_spec = spec
end
task :lines do task :lines do
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0 lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
@ -171,6 +169,11 @@ task :lines do
puts "Total: Lines #{total_lines}, LOC #{total_codelines}" puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
end end
spec = eval(File.read('activerecord.gemspec'))
Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
# Publishing ------------------------------------------------------ # Publishing ------------------------------------------------------

View file

@ -52,7 +52,7 @@ class Build
def tasks def tasks
if activerecord? if activerecord?
['mysql:rebuild_databases', "#{adapter}:#{'isolated_' if isolated?}test"] ['db:mysql:rebuild', "#{adapter}:#{'isolated_' if isolated?}test"]
else else
["test#{':isolated' if isolated?}"] ["test#{':isolated' if isolated?}"]
end end

View file

@ -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_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_mysql test:mysql
test_mysql2 test:mysql2
test_postgresql test:postgresql
``` ```
Finally, Finally,

View file

@ -249,7 +249,7 @@ and create the test databases:
```bash ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake mysql:build_databases $ bundle exec rake db:mysql:build
``` ```
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
```bash ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake postgresql:build_databases $ bundle exec rake db:postgresql:build
``` ```
It is possible to build databases for both PostgreSQL and MySQL with It is possible to build databases for both PostgreSQL and MySQL with