From a0dc6755db71b33aebccdb95fd0dd7097c934c04 Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Mon, 29 Mar 2010 09:52:33 +0430 Subject: Reorganized app/test directory. [#3057 state:resolved] Run 'rake update:test_directory' to reorganize your already generated apps. test/functional -> test/controllers test/functional -> test/controllers test/unit/helpers -> test/helpers test/unit/**/*_observer_test.rb -> test/observers test/unit -> test/models --- railties/lib/rails/tasks/framework.rake | 47 ++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/tasks') diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 738f7f5301..a3109a9243 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -17,7 +17,7 @@ namespace :rails do end desc "Update both configs, scripts and public/javascripts from Rails" - task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ] + task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller", "update:test_directory" ] desc "Applies the template supplied by LOCATION=/path/to/template" task :template do @@ -72,5 +72,50 @@ namespace :rails do puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary" end end + + desc "Move test directories to new locations" + task :test_directory do + if File.exists?(Rails.root.join('test')) + FileUtils.mkdir(Rails.root.join('test/controllers')) unless File.exists?(Rails.root.join('test/controllers')) + [Rails.root.join('test/functional'), Rails.root.join('test/integration')].each do |controller_test_dir| + if File.exists?(controller_test_dir) + puts "#{controller_test_dir} exists" + FileUtils.mv(Dir["#{controller_test_dir}/**/*"], Rails.root.join('test/controllers'), :force => true) + FileUtils.rm_rf(controller_test_dir) + end + end + + if File.exists?(Rails.root.join('test/unit/helpers')) + FileUtils.mkdir(Rails.root.join('test/helpers')) unless File.exists?(Rails.root.join('test/helpers')) + FileUtils.mv(Dir[Rails.root.join('test/unit/helpers/**/*')], Rails.root.join('test/helpers'), :force => true) + else + unless File.exists?(Rails.root.join('test/helpers')) + FileUtils.mkdir(Rails.root.join('test/helpers')) + end + end + + if File.exists?(Rails.root.join('test/unit')) + observer_tests = "#{Rails.root}/test/unit/**/*_observer_test.rb" + unless observer_tests.empty? + FileUtils.mkdir(Rails.root.join('test/observers')) unless File.exists?(Rails.root.join('test/observers')) + FileUtils.mv(observer_tests, Rails.root.join('test/observers'), :force => true) + end + FileUtils.mkdir(Rails.root.join('test/models')) unless File.exists?(Rails.root.join('test/models')) + FileUtils.mv(Dir[Rails.root.join('test/unit/*')], Rails.root.join('test/models'), :force => true) + FileUtils.rm_rf(Rails.root.join('test/unit')) + end + end + + puts <<-TEST + + All test directories have been updated: + + test/functional -> test/controllers + test/functional -> test/controllers + test/unit/helpers -> test/helpers + test/unit/**/*_observer_test.rb -> test/observers + test/unit -> test/models + TEST + end end end -- cgit v1.2.3