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
|
||||
|
||||
desc 'Build MySQL and PostgreSQL test databases'
|
||||
namespace :db do
|
||||
desc 'Build MySQL and PostgreSQL test databases'
|
||||
task create: ['mysql:build_databases', 'postgresql:build_databases']
|
||||
desc 'Drop MySQL and PostgreSQL test databases'
|
||||
task drop: ['mysql:drop_databases', 'postgresql:drop_databases']
|
||||
task :create => ['db:mysql:build', 'db:postgresql:build']
|
||||
task :drop => ['db:mysql:drop', 'db:postgresql:drop']
|
||||
end
|
||||
|
||||
%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]+/]
|
||||
t.libs << 'test'
|
||||
t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject {
|
||||
|
@ -57,7 +57,8 @@ end
|
|||
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]+/]
|
||||
puts [adapter, adapter_short].inspect
|
||||
(Dir["test/cases/**/*_test.rb"].reject {
|
||||
|
@ -66,6 +67,8 @@ end
|
|||
sh(Gem.ruby, '-w' ,"-Itest", file)
|
||||
end or raise "Failures"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace adapter do
|
||||
task :test => "test_#{adapter}"
|
||||
|
@ -76,8 +79,8 @@ end
|
|||
end
|
||||
|
||||
# Make sure the adapter test evaluates the env setting task
|
||||
task "test_#{adapter}" => "#{adapter}:env"
|
||||
task "isolated_test_#{adapter}" => "#{adapter}:env"
|
||||
task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
|
||||
task "isolated_test_#{adapter}" => ["#{adapter}:env", "test:isolated:#{adapter}"]
|
||||
end
|
||||
|
||||
rule '.sqlite3' do |t|
|
||||
|
@ -89,63 +92,58 @@ task :test_sqlite3 => [
|
|||
'test/fixtures/fixture_database_2.sqlite3'
|
||||
]
|
||||
|
||||
namespace :mysql do
|
||||
namespace :db do
|
||||
namespace :mysql do
|
||||
desc 'Build the MySQL test databases'
|
||||
task :build_databases do
|
||||
task :build do
|
||||
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['arunit2']['username']} -e "create DATABASE #{config['arunit2']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
|
||||
end
|
||||
|
||||
desc 'Drop the MySQL test databases'
|
||||
task :drop_databases do
|
||||
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_databases => [:drop_databases, :build_databases]
|
||||
end
|
||||
task :rebuild => [:drop, :build]
|
||||
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
|
||||
namespace :postgresql do
|
||||
desc 'Build the PostgreSQL test databases'
|
||||
task :build_databases do
|
||||
task :build 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
|
||||
# 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_databases do
|
||||
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_databases => [:drop_databases, :build_databases]
|
||||
task :rebuild => [:drop, :build]
|
||||
end
|
||||
end
|
||||
|
||||
task :build_postgresql_databases => 'postgresql:build_databases'
|
||||
task :drop_postgresql_databases => 'postgresql:drop_databases'
|
||||
task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
|
||||
task :build_mysql_databases => 'db:mysql:build'
|
||||
task :drop_mysql_databases => 'db:mysql:drop'
|
||||
task :rebuild_mysql_databases => 'db:mysql:rebuild'
|
||||
|
||||
|
||||
spec = eval(File.read('activerecord.gemspec'))
|
||||
Gem::PackageTask.new(spec) do |p|
|
||||
p.gem_spec = spec
|
||||
end
|
||||
task :build_postgresql_databases => 'db:postgresql:build'
|
||||
task :drop_postgresql_databases => 'db:postgresql:drop'
|
||||
task :rebuild_postgresql_databases => 'db:postgresql:rebuild'
|
||||
|
||||
task :lines do
|
||||
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}"
|
||||
end
|
||||
|
||||
spec = eval(File.read('activerecord.gemspec'))
|
||||
|
||||
Gem::PackageTask.new(spec) do |p|
|
||||
p.gem_spec = spec
|
||||
end
|
||||
|
||||
# Publishing ------------------------------------------------------
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class Build
|
|||
|
||||
def tasks
|
||||
if activerecord?
|
||||
['mysql:rebuild_databases', "#{adapter}:#{'isolated_' if isolated?}test"]
|
||||
['db:mysql:rebuild', "#{adapter}:#{'isolated_' if isolated?}test"]
|
||||
else
|
||||
["test#{':isolated' if isolated?}"]
|
||||
end
|
||||
|
|
|
@ -265,15 +265,15 @@ This is how you run the Active Record test suite only for SQLite3:
|
|||
|
||||
```bash
|
||||
$ 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
|
||||
|
||||
```bash
|
||||
test_mysql
|
||||
test_mysql2
|
||||
test_postgresql
|
||||
test:mysql
|
||||
test:mysql2
|
||||
test:postgresql
|
||||
```
|
||||
|
||||
Finally,
|
||||
|
|
|
@ -249,7 +249,7 @@ and create the test databases:
|
|||
|
||||
```bash
|
||||
$ 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
|
||||
|
@ -267,7 +267,7 @@ and then create the test databases with
|
|||
|
||||
```bash
|
||||
$ 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
|
||||
|
|
Loading…
Reference in a new issue