diff options
Diffstat (limited to 'railties/lib')
13 files changed, 74 insertions, 23 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/test/functional/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/controllers/.empty_directory index e69de29bb2..e69de29bb2 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +++ b/railties/lib/rails/generators/rails/app/templates/test/controllers/.empty_directory diff --git a/railties/lib/rails/generators/rails/app/templates/test/integration/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/helpers/.empty_directory index e69de29bb2..e69de29bb2 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +++ b/railties/lib/rails/generators/rails/app/templates/test/helpers/.empty_directory diff --git a/railties/lib/rails/generators/rails/app/templates/test/unit/.empty_directory b/railties/lib/rails/generators/rails/app/templates/test/models/.empty_directory index e69de29bb2..e69de29bb2 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +++ b/railties/lib/rails/generators/rails/app/templates/test/models/.empty_directory diff --git a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb index 20f3bd8965..db99e55e9e 100644 --- a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb +++ b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb @@ -8,7 +8,7 @@ module TestUnit def create_test_files template 'functional_test.rb', - File.join('test/functional', class_path, "#{file_name}_controller_test.rb") + File.join('test/controllers', class_path, "#{file_name}_controller_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb index 4ea80bf7be..d4c287540c 100644 --- a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb +++ b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb @@ -6,7 +6,7 @@ module TestUnit check_class_collision :suffix => "HelperTest" def create_helper_files - template 'helper_test.rb', File.join('test/unit/helpers', class_path, "#{file_name}_helper_test.rb") + template 'helper_test.rb', File.join('test/helpers', class_path, "#{file_name}_helper_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/integration/integration_generator.rb b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb index 32d0fac029..af45998bc1 100644 --- a/railties/lib/rails/generators/test_unit/integration/integration_generator.rb +++ b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb @@ -6,7 +6,7 @@ module TestUnit check_class_collision :suffix => "Test" def create_test_files - template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb") + template 'integration_test.rb', File.join('test/controllers', class_path, "#{file_name}_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb index 1a49286d41..894d24049c 100644 --- a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb +++ b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb @@ -7,7 +7,7 @@ module TestUnit check_class_collision :suffix => "Test" def create_test_files - template "functional_test.rb", File.join('test/functional', class_path, "#{file_name}_test.rb") + template "controller_test.rb", File.join('test/controllers', class_path, "#{file_name}_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/mailer/templates/controller_test.rb index 80ac7f0feb..80ac7f0feb 100644 --- a/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/mailer/templates/controller_test.rb diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb index 609b815683..17c431ae81 100644 --- a/railties/lib/rails/generators/test_unit/model/model_generator.rb +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -9,7 +9,7 @@ module TestUnit check_class_collision :suffix => "Test" def create_test_file - template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") + template 'unit_test.rb', File.join('test/models', class_path, "#{file_name}_test.rb") end hook_for :fixture_replacement diff --git a/railties/lib/rails/generators/test_unit/observer/observer_generator.rb b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb index 6cc1158c21..5db111ec68 100644 --- a/railties/lib/rails/generators/test_unit/observer/observer_generator.rb +++ b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb @@ -6,7 +6,7 @@ module TestUnit check_class_collision :suffix => "ObserverTest" def create_test_files - template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb") + template 'unit_test.rb', File.join('test/observers', class_path, "#{file_name}_observer_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index c0315c7fe6..5d1ac1dde4 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -11,7 +11,7 @@ module TestUnit def create_test_files template 'functional_test.rb', - File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb") + File.join('test/controllers', controller_class_path, "#{controller_file_name}_controller_test.rb") end end end 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 diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 57857fb911..4f34707f53 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -40,7 +40,7 @@ end desc 'Run all unit, functional and integration tests' task :test do - errors = %w(test:units test:functionals test:integration).collect do |task| + errors = %w(test:models test:controllers test:helpers).collect do |task| begin Rake::Task[task].invoke nil @@ -55,8 +55,10 @@ namespace :test do 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) + recent_tests('app/models/**/*.rb', 'test/models', since) + + recent_tests('app/models/**/*_observer.rb', 'test/observers', since) + + recent_tests('app/controllers/**/*.rb', 'test/controllers', since) + + recent_tests('app/helpers/**/*.rb', 'test/helpers', since) t.libs << 'test' t.test_files = touched.uniq @@ -74,35 +76,39 @@ namespace :test do end models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ } + observers = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*_observer\.rb$/ } controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ } + helpers = changed_since_checkin.select { |path| path =~ /app[\\\/]helpers[\\\/].*\.rb$/ } - unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" } - functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" } + model_tests = models.map { |model| "test/models/#{File.basename(model, '.rb')}_test.rb" } + observer_tests = observers.map { |observer| "test/observers/#{File.basename(observer, '.rb')}_test.rb" } + controller_tests = controllers.map { |controller| "test/controllers/#{File.basename(controller, '.rb')}_test.rb" } + helper_tests = helpers.map { |helper| "test/helpers/#{File.basename(helper, '.rb')}_test.rb" } - unit_tests.uniq + functional_tests.uniq + (model_tests + observer_tests + controller_tests + helper_tests).uniq end t.libs << 'test' end Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" - Rake::TestTask.new(:units => "db:test:prepare") do |t| + Rake::TestTask.new(:models => "db:test:prepare") do |t| t.libs << "test" - t.pattern = 'test/unit/**/*_test.rb' + t.pattern = ['test/models/**/*_test.rb', 'test/observers/**/*_test.rb'] end - Rake::Task['test:units'].comment = "Run the unit tests in test/unit" + Rake::Task['test:models'].comment = "Run the unit tests in test/models and test/observers" - Rake::TestTask.new(:functionals => "db:test:prepare") do |t| + Rake::TestTask.new(:controllers => "db:test:prepare") do |t| t.libs << "test" - t.pattern = 'test/functional/**/*_test.rb' + t.pattern = 'test/controllers/**/*_test.rb' end - Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional" + Rake::Task['test:controllers'].comment = "Run the functional and integration tests in test/controllers" - Rake::TestTask.new(:integration => "db:test:prepare") do |t| + Rake::TestTask.new(:helpers => "db:test:prepare") do |t| t.libs << "test" - t.pattern = 'test/integration/**/*_test.rb' + t.pattern = 'test/helpers/**/*_test.rb' end - Rake::Task['test:integration'].comment = "Run the integration tests in test/integration" + Rake::Task['test:helpers'].comment = "Run the unit tests in test/helpers" Rake::TestTask.new(:benchmark => 'db:test:prepare') do |t| t.libs << 'test' |