diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-27 04:38:39 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-27 04:38:39 +0000 |
commit | 985cb441103c79651f12a013326aa15f54fa8182 (patch) | |
tree | 4aa28f1488ba5cdf66e58ed6df0aa448dfdbba0b /railties/lib | |
parent | 1a06d324df43bfb3287293934f0ef34a7c790a34 (diff) | |
download | rails-985cb441103c79651f12a013326aa15f54fa8182.tar.gz rails-985cb441103c79651f12a013326aa15f54fa8182.tar.bz2 rails-985cb441103c79651f12a013326aa15f54fa8182.zip |
Added namespaces to all tasks, so for example load_fixtures is now db:fixtures:load. All the old task names are still valid, they just point to the new namespaced names. "rake -T" will only show the namespaced ones, though [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3680 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/tasks/clear.rake | 29 | ||||
-rw-r--r-- | railties/lib/tasks/databases.rake | 289 | ||||
-rw-r--r-- | railties/lib/tasks/documentation.rake | 141 | ||||
-rw-r--r-- | railties/lib/tasks/framework.rake | 127 | ||||
-rw-r--r-- | railties/lib/tasks/javascripts.rake | 6 | ||||
-rw-r--r-- | railties/lib/tasks/misc.rake | 19 | ||||
-rw-r--r-- | railties/lib/tasks/pre_namespace_aliases.rake | 46 | ||||
-rw-r--r-- | railties/lib/tasks/testing.rake | 74 |
8 files changed, 411 insertions, 320 deletions
diff --git a/railties/lib/tasks/clear.rake b/railties/lib/tasks/clear.rake new file mode 100644 index 0000000000..25769f3088 --- /dev/null +++ b/railties/lib/tasks/clear.rake @@ -0,0 +1,29 @@ +namespace :clear do + desc "Truncates all *.log files in log/ to zero bytes" + task :logs do + FileList["log/*.log"].each do |log_file| + f = File.open(log_file, "w") + f.close + end + end + + desc "Clear session, cache, and socket files from tmp/" + task :tmp => [ "clear:tmp:sesions", "clear:tmp:cache", "clear:tmp:sockets"] + + namespace :tmp do + desc "Clears all files in tmp/sessions" + task :sessions do + FileUtils.rm(Dir['tmp/sessions/[^.]*']) + end + + desc "Clears all files and directories in tmp/cache" + task :cache do + FileUtils.rm_rf(Dir['tmp/cache/[^.]*']) + end + + desc "Clears all ruby_sess.* files in tmp/sessions" + task :sockets do + FileUtils.rm(Dir['tmp/sockets/[^.]*']) + end + end +end
\ No newline at end of file diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 971f9ae461..0925429265 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -1,162 +1,169 @@ -desc "Migrate the database according to the migrate scripts in db/migrate (only supported on PG/MySQL). A specific version can be targetted with VERSION=x" -task :migrate => :environment do - ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) - Rake::Task[:db_schema_dump].invoke if ActiveRecord::Base.schema_format == :ruby -end - -desc "Load fixtures into the current environment's database" -task :load_fixtures => :environment do - require 'active_record/fixtures' - ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) - Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}')).each do |fixture_file| - Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*')) +namespace :db do + desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x" + task :migrate => :environment do + ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) + Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end -end -desc "Create a db/schema.rb file that can be portably used against any DB supported by AR." -task :db_schema_dump => :environment do - require 'active_record/schema_dumper' - File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file| - ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) + namespace :fixtures do + desc "Load fixtures into the current environment's database" + task :load => :environment do + require 'active_record/fixtures' + ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) + Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}')).each do |fixture_file| + Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*')) + end + end end -end - -desc "Import a schema.rb file into the database." -task :db_schema_import => :environment do - file = ENV['SCHEMA'] || "db/schema.rb" - load file -end - -desc "Recreate the test database from the current environment's database schema." -task :clone_schema_to_test => :db_schema_dump do - ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) - Rake::Task[:db_schema_import].invoke -end -desc "Dump the database structure to a SQL file" -task :db_structure_dump => :environment do - abcs = ActiveRecord::Base.configurations - case abcs[RAILS_ENV]["adapter"] - when "mysql", "oci" - ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) - File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } - when "postgresql" - ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"] - ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"] - ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"] - search_path = abcs[RAILS_ENV]["schema_search_path"] - search_path = "--schema=#{search_path}" if search_path - `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}` - when "sqlite", "sqlite3" - dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"] - `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql` - when "sqlserver" - `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r` - `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r` - else - raise "Task not supported by '#{abcs["test"]["adapter"]}'" - end + namespace :schema do + desc "Create a db/schema.rb file that can be portably used against any DB supported by AR" + task :dump => :environment do + require 'active_record/schema_dumper' + File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file| + ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) + end + end - if ActiveRecord::Base.connection.supports_migrations? - File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } + desc "Load a schema.rb file into the database" + task :load => :environment do + file = ENV['SCHEMA'] || "db/schema.rb" + load(file) + end end -end -desc "Recreate the test databases from the development structure" -task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do - abcs = ActiveRecord::Base.configurations - case abcs["test"]["adapter"] - when "mysql" - ActiveRecord::Base.establish_connection(:test) - ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') - IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| - ActiveRecord::Base.connection.execute(table) - end - when "postgresql" - ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] - ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] - ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] - `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` - when "sqlite", "sqlite3" - dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] - `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql` - when "sqlserver" - `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` - when "oci" - ActiveRecord::Base.establish_connection(:test) - IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| - ActiveRecord::Base.connection.execute(ddl) + namespace :structure do + desc "Dump the database structure to a SQL file" + task :dump => :environment do + abcs = ActiveRecord::Base.configurations + case abcs[RAILS_ENV]["adapter"] + when "mysql", "oci" + ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) + File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } + when "postgresql" + ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"] + ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"] + ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"] + search_path = abcs[RAILS_ENV]["schema_search_path"] + search_path = "--schema=#{search_path}" if search_path + `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}` + when "sqlite", "sqlite3" + dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"] + `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql` + when "sqlserver" + `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r` + `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r` + else + raise "Task not supported by '#{abcs["test"]["adapter"]}'" end - else - raise "Task not supported by '#{abcs["test"]["adapter"]}'" - end -end -desc "Empty the test database" -task :purge_test_database => :environment do - abcs = ActiveRecord::Base.configurations - case abcs["test"]["adapter"] - when "mysql" - ActiveRecord::Base.establish_connection(:test) - ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"]) - when "postgresql" - ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] - ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] - ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] - enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"] - `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` - `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` - when "sqlite","sqlite3" - dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] - File.delete(dbfile) if File.exist?(dbfile) - when "sqlserver" - dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-') - `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}` - `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` - when "oci" - ActiveRecord::Base.establish_connection(:test) - ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl| - ActiveRecord::Base.connection.execute(ddl) + if ActiveRecord::Base.connection.supports_migrations? + File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } end - else - raise "Task not supported by '#{abcs["test"]["adapter"]}'" + end end -end - -def prepare_test_database_task - {:sql => :clone_structure_to_test, - :ruby => :clone_schema_to_test}[ActiveRecord::Base.schema_format] -end -def session_table_name - ActiveRecord::Base.pluralize_table_names ? :sessions : :session -end + namespace :test do + desc "Recreate the test database from the current environment's database schema" + task :clone => "db:schema:dump" do + ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) + Rake::Task["db:schema:dump"].invoke + end -desc 'Prepare the test database and load the schema' -task :prepare_test_database => :environment do - Rake::Task[prepare_test_database_task].invoke -end + + desc "Recreate the test databases from the development structure" + task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do + abcs = ActiveRecord::Base.configurations + case abcs["test"]["adapter"] + when "mysql" + ActiveRecord::Base.establish_connection(:test) + ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') + IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| + ActiveRecord::Base.connection.execute(table) + end + when "postgresql" + ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] + ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] + ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] + `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` + when "sqlite", "sqlite3" + dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] + `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql` + when "sqlserver" + `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` + when "oci" + ActiveRecord::Base.establish_connection(:test) + IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| + ActiveRecord::Base.connection.execute(ddl) + end + else + raise "Task not supported by '#{abcs["test"]["adapter"]}'" + end + end -desc "Creates a sessions table for use with CGI::Session::ActiveRecordStore" -task :create_sessions_table => :environment do - raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations? + desc "Empty the test database" + task :purge => :environment do + abcs = ActiveRecord::Base.configurations + case abcs["test"]["adapter"] + when "mysql" + ActiveRecord::Base.establish_connection(:test) + ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"]) + when "postgresql" + ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] + ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] + ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] + enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"] + `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` + `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` + when "sqlite","sqlite3" + dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] + File.delete(dbfile) if File.exist?(dbfile) + when "sqlserver" + dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-') + `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}` + `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` + when "oci" + ActiveRecord::Base.establish_connection(:test) + ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl| + ActiveRecord::Base.connection.execute(ddl) + end + else + raise "Task not supported by '#{abcs["test"]["adapter"]}'" + end + end - ActiveRecord::Base.connection.create_table session_table_name do |t| - t.column :session_id, :string - t.column :data, :text - t.column :updated_at, :datetime + desc 'Prepare the test database and load the schema' + task :prepare => :environment do + Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke + end end - - ActiveRecord::Base.connection.add_index session_table_name, :session_id -end -desc "Drop the sessions table" -task :drop_sessions_table => :environment do - raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations? + namespace :sessions do + desc "Creates a sessions table for use with CGI::Session::ActiveRecordStore" + task :create => :environment do + raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations? + + ActiveRecord::Base.connection.create_table(session_table_name) do |t| + t.column :session_id, :string + t.column :data, :text + t.column :updated_at, :datetime + end - ActiveRecord::Base.connection.drop_table session_table_name + ActiveRecord::Base.connection.add_index(session_table_name, :session_id) + end + + desc "Drop the sessions table" + task :drop => :environment do + raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations? + ActiveRecord::Base.connection.drop_table(session_table_name) + end + + desc "Drop and recreate the session table (much faster than 'DELETE * FROM sessions')" + task :recreate => [ "db:sessions:drop", "db:sessions:create" ] do + end + end end -desc "Drop and recreate the session table (much faster than 'DELETE * FROM sessions')" -task :purge_sessions_table => [ :drop_sessions_table, :create_sessions_table ] do +def session_table_name + ActiveRecord::Base.pluralize_table_names ? :sessions : :session end diff --git a/railties/lib/tasks/documentation.rake b/railties/lib/tasks/documentation.rake index a38a284516..2e5e773141 100644 --- a/railties/lib/tasks/documentation.rake +++ b/railties/lib/tasks/documentation.rake @@ -1,76 +1,81 @@ -desc "Generate documentation for the application" -Rake::RDocTask.new("appdoc") { |rdoc| - rdoc.rdoc_dir = 'doc/app' - rdoc.title = "Rails Application Documentation" - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('doc/README_FOR_APP') - rdoc.rdoc_files.include('app/**/*.rb') -} +namespace :doc do + desc "Generate documentation for the application" + Rake::RDocTask.new("app") { |rdoc| + rdoc.rdoc_dir = 'doc/app' + rdoc.title = "Rails Application Documentation" + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('doc/README_FOR_APP') + rdoc.rdoc_files.include('app/**/*.rb') + } -plugins = FileList['vendor/plugins/**'].map {|plugin| File.basename(plugin)} -# Define doc tasks for each plugin -plugins.each do |plugin| - task :"#{plugin}_plugindoc" => :environment do - plugin_base = "vendor/plugins/#{plugin}" - options = [] - files = Rake::FileList.new - options << "-o doc/plugins/#{plugin}" - options << "--title '#{plugin.titlecase} Plugin Documentation'" - options << '--line-numbers' << '--inline-source' - options << '-T html' + desc "Generate documentation for the Rails framework" + Rake::RDocTask.new("rails") { |rdoc| + rdoc.rdoc_dir = 'doc/api' + rdoc.template = "#{ENV['template']}.rb" if ENV['template'] + rdoc.title = "Rails Framework Documentation" + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG') + rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE') + rdoc.rdoc_files.include('vendor/rails/activerecord/README') + rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG') + rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb') + rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*') + rdoc.rdoc_files.include('vendor/rails/actionpack/README') + rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG') + rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionmailer/README') + rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG') + rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/README') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/CHANGELOG') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/api/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/client/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/container/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/dispatcher/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/protocol/*.rb') + rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/support/*.rb') + rdoc.rdoc_files.include('vendor/rails/activesupport/README') + rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG') + rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb') + } - files.include("#{plugin_base}/lib/**/*.rb") - if File.exists?("#{plugin_base}/README") - files.include("#{plugin_base}/README") - options << "--main '#{plugin_base}/README'" - end - files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG") + plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) } - options << files.to_s + desc "Generate documation for all installed plugins" + task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" } - sh %(rdoc #{options * ' '}) + desc "Remove plugin documentation" + task :clobber_plugins do + rm_rf 'doc/plugins' rescue nil end -end -desc "Generate documation for all installed plugins" -task :plugindoc => plugins.map {|plugin| :"#{plugin}_plugindoc"} + namespace :plugins do + # Define doc tasks for each plugin + plugins.each do |plugin| + task(plugin => :environment) do + plugin_base = "vendor/plugins/#{plugin}" + options = [] + files = Rake::FileList.new + options << "-o doc/plugins/#{plugin}" + options << "--title '#{plugin.titlecase} Plugin Documentation'" + options << '--line-numbers' << '--inline-source' + options << '-T html' + + files.include("#{plugin_base}/lib/**/*.rb") + if File.exists?("#{plugin_base}/README") + files.include("#{plugin_base}/README") + options << "--main '#{plugin_base}/README'" + end + files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG") -desc "Remove plugin documentation" -task :clobber_plugindoc do - rm_rf 'doc/plugins' rescue nil -end + options << files.to_s -desc "Generate documentation for the Rails framework" -Rake::RDocTask.new("apidoc") { |rdoc| - rdoc.rdoc_dir = 'doc/api' - rdoc.template = "#{ENV['template']}.rb" if ENV['template'] - rdoc.title = "Rails Framework Documentation" - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE') - rdoc.rdoc_files.include('vendor/rails/activerecord/README') - rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb') - rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*') - rdoc.rdoc_files.include('vendor/rails/actionpack/README') - rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionmailer/README') - rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/README') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/api/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/client/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/container/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/dispatcher/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/protocol/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/support/*.rb') - rdoc.rdoc_files.include('vendor/rails/activesupport/README') - rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb') -} + sh %(rdoc #{options * ' '}) + end + end + end +end
\ No newline at end of file diff --git a/railties/lib/tasks/framework.rake b/railties/lib/tasks/framework.rake index 59f8f51381..346d7a7e51 100644 --- a/railties/lib/tasks/framework.rake +++ b/railties/lib/tasks/framework.rake @@ -1,71 +1,86 @@ -desc "Lock this application to the current gems (by unpacking them into vendor/rails)" -task :freeze_gems do - deps = %w(actionpack activerecord actionmailer activesupport actionwebservice) - require 'rubygems' +namespace :rails do + namespace :freeze do + desc "Lock this application to the current gems (by unpacking them into vendor/rails)" + task :gems do + deps = %w(actionpack activerecord actionmailer activesupport actionwebservice) + require 'rubygems' - rails = if version = ENV['VERSION'] - Gem.cache.search('rails', "= #{version}").first - else - Gem.cache.search('rails').sort_by { |g| g.version }.last - end - version ||= rails.version + rails = if version = ENV['VERSION'] + Gem.cache.search('rails', "= #{version}").first + else + Gem.cache.search('rails').sort_by { |g| g.version }.last + end + version ||= rails.version - unless rails - puts "No rails gem #{version} is installed. Do 'gem list rails' to see what you have available." - exit - end + unless rails + puts "No rails gem #{version} is installed. Do 'gem list rails' to see what you have available." + exit + end - puts "Freezing to the gems for Rails #{rails.version}" - rm_rf "vendor/rails" - mkdir_p "vendor/rails" + puts "Freezing to the gems for Rails #{rails.version}" + rm_rf "vendor/rails" + mkdir_p "vendor/rails" - rails.dependencies.select { |g| deps.include? g.name }.each do |g| - system "cd vendor/rails; gem unpack -v '#{g.version_requirements}' #{g.name}; mv #{g.name}* #{g.name}" - end - system "cd vendor/rails; gem unpack -v '=#{version}' rails" + rails.dependencies.select { |g| deps.include? g.name }.each do |g| + system "cd vendor/rails; gem unpack -v '#{g.version_requirements}' #{g.name}; mv #{g.name}* #{g.name}" + end + system "cd vendor/rails; gem unpack -v '=#{version}' rails" - FileUtils.mv(Dir.glob("vendor/rails/rails*").first, "vendor/rails/railties") -end + FileUtils.mv(Dir.glob("vendor/rails/rails*").first, "vendor/rails/railties") + end -desc "Lock this application to the Edge Rails (by exporting from Subversion). Defaults to svn HEAD; do 'rake freeze_edge REVISION=1234' to lock to a specific revision." -task :freeze_edge do - $verbose = false - `svn --version` rescue nil - unless !$?.nil? && $?.success? - $stderr.puts "ERROR: Must have subversion (svn) available in the PATH to lock this application to Edge Rails" - exit 1 - end + desc "Lock this application to latest Edge Rails. Lock a specific revision with REVISION=X" + task :edge do + $verbose = false + `svn --version` rescue nil + unless !$?.nil? && $?.success? + $stderr.puts "ERROR: Must have subversion (svn) available in the PATH to lock this application to Edge Rails" + exit 1 + end - rm_rf "vendor/rails" - mkdir_p "vendor/rails" + rm_rf "vendor/rails" + mkdir_p "vendor/rails" - revision_switch = ENV['REVISION'] ? " -r #{ENV['REVISION']}" : '' - for framework in %w( railties actionpack activerecord actionmailer activesupport actionwebservice ) - mkdir_p "vendor/rails/#{framework}" - system "svn export http://dev.rubyonrails.org/svn/rails/trunk/#{framework}/lib vendor/rails/#{framework}/lib #{revision_switch}" + revision_switch = ENV['REVISION'] ? " -r #{ENV['REVISION']}" : '' + for framework in %w( railties actionpack activerecord actionmailer activesupport actionwebservice ) + mkdir_p "vendor/rails/#{framework}" + system "svn export http://dev.rubyonrails.org/svn/rails/trunk/#{framework}/lib vendor/rails/#{framework}/lib #{revision_switch}" + end + end end -end -desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems" -task :unfreeze_rails do - rm_rf "vendor/rails" -end + desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems" + task :unfreeze do + rm_rf "vendor/rails" + end + + desc "Update both scripts and public/javascripts from Rails" + task :update => [ "update:scripts", "update:javascripts" ] -desc "Add new scripts to the application script/ directory" -task :add_new_scripts do - local_base = "script" - edge_base = "#{File.dirname(__FILE__)}/../../bin" + namespace :update do + desc "Add new scripts to the application script/ directory" + task :scripts do + local_base = "script" + edge_base = "#{File.dirname(__FILE__)}/../../bin" - local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) } - edge = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) } + local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) } + edge = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) } - edge.each do |script| - base_name = script[(edge_base.length+1)..-1] - next if base_name == "rails" - next if local.detect { |path| base_name == path[(local_base.length+1)..-1] } - if !File.directory?("#{local_base}/#{File.dirname(base_name)}") - mkdir_p "#{local_base}/#{File.dirname(base_name)}" + edge.each do |script| + base_name = script[(edge_base.length+1)..-1] + next if base_name == "rails" + next if local.detect { |path| base_name == path[(local_base.length+1)..-1] } + if !File.directory?("#{local_base}/#{File.dirname(base_name)}") + mkdir_p "#{local_base}/#{File.dirname(base_name)}" + end + install script, "#{local_base}/#{base_name}", :mode => 0755 + end + end + + desc "Update your javascripts from your current rails install" + task :javascripts do + require 'railties_path' + FileUtils.cp(Dir[RAILTIES_PATH + '/html/javascripts/*.js'], RAILS_ROOT + '/public/javascripts/') end - install script, "#{local_base}/#{base_name}", :mode => 0755 end -end +end
\ No newline at end of file diff --git a/railties/lib/tasks/javascripts.rake b/railties/lib/tasks/javascripts.rake deleted file mode 100644 index 5fc01562e8..0000000000 --- a/railties/lib/tasks/javascripts.rake +++ /dev/null @@ -1,6 +0,0 @@ - -desc "Update your javascripts from your current rails install." -task :update_javascripts do - require 'railties_path' - FileUtils.cp(Dir[RAILTIES_PATH + '/html/javascripts/*.js'], RAILS_ROOT + '/public/javascripts/') -end diff --git a/railties/lib/tasks/misc.rake b/railties/lib/tasks/misc.rake index 60dc2e21d2..02ba886061 100644 --- a/railties/lib/tasks/misc.rake +++ b/railties/lib/tasks/misc.rake @@ -1,19 +1,4 @@ -desc "Run all the tests on a fresh test database" -task :default do - Rake::Task[:test_units].invoke rescue got_error = true - Rake::Task[:test_functional].invoke rescue got_error = true - raise "Test failures" if got_error -end - +task :default => :test task :environment do require(File.join(RAILS_ROOT, 'config', 'environment')) -end - - -desc "Clears all *.log files in log/" -task :clear_logs do - FileList["log/*.log"].each do |log_file| - f = File.open(log_file, "w") - f.close - end -end +end
\ No newline at end of file diff --git a/railties/lib/tasks/pre_namespace_aliases.rake b/railties/lib/tasks/pre_namespace_aliases.rake new file mode 100644 index 0000000000..24005e7772 --- /dev/null +++ b/railties/lib/tasks/pre_namespace_aliases.rake @@ -0,0 +1,46 @@ +# clear +task :clear_logs => "clear:logs" + +# test +task :recent => "test:recent" +task :test_units => "test:units" +task :test_functional => "test:functionals" +task :test_plugins => "test:plugins" + + +# doc +task :appdoc => "doc:app" +task :apidoc => "doc:rails" +task :plugindoc => "doc:plugins" +task :clobber_plugindoc => "doc:clobber_plugins" + +FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }.each do |plugin| + task :"#{plugin}_plugindoc" => "doc:plugins:#{plugin}" +end + + +# rails +task :freeze_gems => "rails:freeze:gems" +task :freeze_edge => "rails:freeze:edge" +task :unfreeze_rails => "rails:unfreeze" +task :add_new_scripts => "rails:update:scripts" +task :update_javascripts => "rails:update:javascripts" + + +# db +task :migrate => "db:migrate" +task :load_fixtures => "db:fixtures:load" + +task :db_schema_dump => "db:schema:dump" +task :db_schema_import => "db:schema:load" + +task :db_structure_dump => "db:structure:dump" + +task :purge_test_database => "db:test:purge" +task :clone_schema_to_test => "db:test:clone" +task :clone_structure_to_test => "db:test:clone_structure" +task :prepare_test_database => "db:test:prepare" + +task :create_sessions_table => "db:sessions:create" +task :drop_sessions_table => "db:sessions:drop" +task :purge_sessions_table => "db:sessions:recreate" diff --git a/railties/lib/tasks/testing.rake b/railties/lib/tasks/testing.rake index 5792f063ac..b4d318da57 100644 --- a/railties/lib/tasks/testing.rake +++ b/railties/lib/tasks/testing.rake @@ -10,41 +10,51 @@ def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) end.compact end -desc 'Test recent changes' -Rake::TestTask.new(:recent => [ :prepare_test_database ]) do |t| - since = TEST_CHANGES_SINCE - touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + - recent_tests('app/models/*.rb', 'test/unit', since) + - recent_tests('app/controllers/*.rb', 'test/functional', since) - - t.libs << 'test' - t.verbose = true - t.test_files = touched.uniq -end -desc "Run the unit tests in test/unit" -Rake::TestTask.new(:test_units => [ :prepare_test_database ]) do |t| - t.libs << "test" - t.pattern = 'test/unit/**/*_test.rb' - t.verbose = true +desc 'Test all units and functionals' +task :test do + Rake::Task["test:units"].invoke rescue got_error = true + Rake::Task["test:functional"].invoke rescue got_error = true + raise "Test failures" if got_error end -desc "Run the functional tests in test/functional" -Rake::TestTask.new(:test_functional => [ :prepare_test_database ]) do |t| - t.libs << "test" - t.pattern = 'test/functional/**/*_test.rb' - t.verbose = true -end +namespace :test do + desc 'Test recent changes' + Rake::TestTask.new(:recent => "db:test:prepare") do |t| + since = TEST_CHANGES_SINCE + touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + + recent_tests('app/models/*.rb', 'test/unit', since) + + recent_tests('app/controllers/*.rb', 'test/functional', since) -desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)" -Rake::TestTask.new(:test_plugins => :environment) do |t| - t.libs << "test" - - if ENV['PLUGIN'] - t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb" - else - t.pattern = 'vendor/plugins/**/test/**/*_test.rb' + t.libs << 'test' + t.verbose = true + t.test_files = touched.uniq end - t.verbose = true -end + desc "Run the unit tests in test/unit" + Rake::TestTask.new(:units => "db:test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/unit/**/*_test.rb' + t.verbose = true + end + + desc "Run the functional tests in test/functional" + Rake::TestTask.new(:functionals => "db:test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/functional/**/*_test.rb' + t.verbose = true + end + + desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)" + Rake::TestTask.new(:plugins => :environment) do |t| + t.libs << "test" + + if ENV['PLUGIN'] + t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb" + else + t.pattern = 'vendor/plugins/**/test/**/*_test.rb' + end + + t.verbose = true + end +end
\ No newline at end of file |