From b252c5d2e915cd66f613e20b4f5c1854be55c092 Mon Sep 17 00:00:00 2001 From: Peter Bui Date: Thu, 4 Mar 2010 00:03:59 -0800 Subject: [PATCH] Generating rails app without activerecord will no longer use fixtures in tests. --- railties/lib/generators/rails/app/app_generator.rb | 11 ++++++++++- .../rails/app/templates/test/test_helper.rb | 2 ++ railties/test/generators/app_generator_test.rb | 13 +++++++++++++ 3 files changed, 25 insertions(+), 1 deletions(-) diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb index 92e0d37..496e9d5 100644 --- a/railties/lib/generators/rails/app/app_generator.rb +++ b/railties/lib/generators/rails/app/app_generator.rb @@ -154,7 +154,16 @@ module Rails::Generators def create_test_files return if options[:skip_testunit] - directory "test" + empty_directory "test" + + inside "test" do + template "test_helper.rb" + directory "fixtures" if !options[:skip_activerecord] + directory "functional" + directory "integration" + directory "performance" + directory "unit" + end end def create_tmp_files diff --git a/railties/lib/generators/rails/app/templates/test/test_helper.rb b/railties/lib/generators/rails/app/templates/test/test_helper.rb index 8bf1192..3d3cd0b 100644 --- a/railties/lib/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/generators/rails/app/templates/test/test_helper.rb @@ -3,11 +3,13 @@ require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase +<% if !options[:skip_activerecord] -%> # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all +<% end -%> # Add more helper methods to be used by all tests here... end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 4120340..38e889a 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -98,6 +98,19 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end + def test_fixtures_not_added_if_skip_activerecord_is_given + run_generator [destination_root, "--skip-activerecord"] + assert_no_file "test/fixtures" + assert_file "test/test_helper.rb", %Q[ENV["RAILS_ENV"] = "test" +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Add more helper methods to be used by all tests here... +end +] + end + def test_prototype_and_test_unit_are_added_by_default run_generator assert_file "public/javascripts/prototype.js" -- 1.6.6