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:
commit
c6ee495e2e
4 changed files with 83 additions and 80 deletions
|
@ -38,15 +38,15 @@ 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
|
||||||
|
Rake::TestTask.new(adapter => "#{adapter}:env") { |t|
|
||||||
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
|
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
|
||||||
t.libs << 'test'
|
t.libs << 'test'
|
||||||
t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject {
|
t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject {
|
||||||
|
@ -57,7 +57,8 @@ end
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
}
|
}
|
||||||
|
|
||||||
task "isolated_test_#{adapter}" do
|
namespace :isolated do
|
||||||
|
task adapter => "#{adapter}:env" do
|
||||||
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
|
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
|
||||||
puts [adapter, adapter_short].inspect
|
puts [adapter, adapter_short].inspect
|
||||||
(Dir["test/cases/**/*_test.rb"].reject {
|
(Dir["test/cases/**/*_test.rb"].reject {
|
||||||
|
@ -66,6 +67,8 @@ end
|
||||||
sh(Gem.ruby, '-w' ,"-Itest", file)
|
sh(Gem.ruby, '-w' ,"-Itest", file)
|
||||||
end or raise "Failures"
|
end or raise "Failures"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
namespace adapter do
|
namespace adapter do
|
||||||
task :test => "test_#{adapter}"
|
task :test => "test_#{adapter}"
|
||||||
|
@ -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
|
||||||
|
namespace :mysql 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'
|
desc 'Drop the MySQL test databases'
|
||||||
task :drop_databases do
|
task :drop do
|
||||||
config = ARTest.config['connections']['mysql']
|
config = ARTest.config['connections']['mysql']
|
||||||
%x( mysqladmin --user=#{config['arunit']['username']} -f drop #{config['arunit']['database']} )
|
%x( mysqladmin --user=#{config['arunit']['username']} -f drop #{config['arunit']['database']} )
|
||||||
%x( mysqladmin --user=#{config['arunit2']['username']} -f drop #{config['arunit2']['database']} )
|
%x( mysqladmin --user=#{config['arunit2']['username']} -f drop #{config['arunit2']['database']} )
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Rebuild the MySQL test databases'
|
desc 'Rebuild the MySQL test databases'
|
||||||
task :rebuild_databases => [:drop_databases, :build_databases]
|
task :rebuild => [:drop, :build]
|
||||||
end
|
end
|
||||||
|
|
||||||
task :build_mysql_databases => 'mysql:build_databases'
|
namespace :postgresql do
|
||||||
task :drop_mysql_databases => 'mysql:drop_databases'
|
|
||||||
task :rebuild_mysql_databases => 'mysql:rebuild_databases'
|
|
||||||
|
|
||||||
|
|
||||||
namespace :postgresql do
|
|
||||||
desc 'Build the PostgreSQL test databases'
|
desc 'Build the PostgreSQL test databases'
|
||||||
task :build_databases do
|
task :build do
|
||||||
config = ARTest.config['connections']['postgresql']
|
config = ARTest.config['connections']['postgresql']
|
||||||
%x( createdb -E UTF8 -T template0 #{config['arunit']['database']} )
|
%x( createdb -E UTF8 -T template0 #{config['arunit']['database']} )
|
||||||
%x( createdb -E UTF8 -T template0 #{config['arunit2']['database']} )
|
%x( createdb -E UTF8 -T template0 #{config['arunit2']['database']} )
|
||||||
|
|
||||||
# notify about preparing hstore
|
# prepare hstore
|
||||||
if %x( createdb --version ).strip.gsub(/(.*)(\d\.\d\.\d)$/, "\\2") < "9.1.0"
|
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"
|
puts "Please prepare hstore data type. See http://www.postgresql.org/docs/9.0/static/hstore.html"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Drop the PostgreSQL test databases'
|
desc 'Drop the PostgreSQL test databases'
|
||||||
task :drop_databases do
|
task :drop do
|
||||||
config = ARTest.config['connections']['postgresql']
|
config = ARTest.config['connections']['postgresql']
|
||||||
%x( dropdb #{config['arunit']['database']} )
|
%x( dropdb #{config['arunit']['database']} )
|
||||||
%x( dropdb #{config['arunit2']['database']} )
|
%x( dropdb #{config['arunit2']['database']} )
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Rebuild the PostgreSQL test databases'
|
desc 'Rebuild the PostgreSQL test databases'
|
||||||
task :rebuild_databases => [:drop_databases, :build_databases]
|
task :rebuild => [:drop, :build]
|
||||||
|
end
|
||||||
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 ------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue