diff options
Diffstat (limited to 'railties/test/generators')
6 files changed, 74 insertions, 51 deletions
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 3ef06c7f25..cc0bd53639 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -23,7 +23,7 @@ DEFAULT_APP_FILES = %w( lib lib/tasks log - public/images + app/assets/images script/rails test/fixtures test/functional @@ -39,6 +39,8 @@ DEFAULT_APP_FILES = %w( class AppGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments [destination_root] + + # brings setup, teardown, and some tests include SharedGeneratorTests def default_files @@ -131,6 +133,25 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile", /^gem\s+["']mysql2["']$/ end + def test_config_jdbcmysql_database + run_generator([destination_root, "-d", "jdbcmysql"]) + assert_file "config/database.yml", /jdbcmysql/ + assert_file "Gemfile", /^gem\s+["']activerecord-jdbcmysql-adapter["']$/ + assert_file "Gemfile", /^gem\s+["']jruby-openssl["']$/ if defined?(JRUBY_VERSION) && JRUBY_VERSION < "1.6" + end + + def test_config_jdbcsqlite3_database + run_generator([destination_root, "-d", "jdbcsqlite3"]) + assert_file "config/database.yml", /jdbcsqlite3/ + assert_file "Gemfile", /^gem\s+["']activerecord-jdbcsqlite3-adapter["']$/ + end + + def test_config_jdbcpostgresql_database + run_generator([destination_root, "-d", "jdbcpostgresql"]) + assert_file "config/database.yml", /jdbcpostgresql/ + assert_file "Gemfile", /^gem\s+["']activerecord-jdbcpostgresql-adapter["']$/ + end + def test_generator_if_skip_active_record_is_given run_generator [destination_root, "--skip-active-record"] assert_no_file "config/database.yml" @@ -145,40 +166,41 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end - def test_jquery_and_test_unit_are_added_by_default + def test_creation_of_a_test_directory run_generator - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/ - assert_file "app/assets/javascripts/application.js" - assert_file "vendor/assets/javascripts/jquery.js" - assert_file "vendor/assets/javascripts/jquery_ujs.js" - assert_file "test" + assert_file 'test' end - def test_javascript_is_skipped_if_required - run_generator [destination_root, "--skip-javascript"] - assert_file "config/application.rb", /^\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/ - assert_file "app/assets/javascripts/application.js" - assert_no_file "vendor/assets/javascripts/jquery.js" - assert_no_file "vendor/assets/javascripts/jquery_ujs.js" + def test_jquery_is_the_default_javascript_library + run_generator + assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/ + assert_file "app/assets/javascripts/application.js" do |contents| + assert_match %r{^//= require jquery}, contents + assert_match %r{^//= require jquery_ujs}, contents + end + assert_file 'Gemfile' do |contents| + assert_match /^gem 'jquery-rails'/, contents + end end - def test_config_prototype_javascript_library - run_generator [destination_root, "-j", "prototype"] - assert_file "config/application.rb", /^\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/ - assert_file "app/assets/javascripts/application.js" - assert_file "vendor/assets/javascripts/prototype.js" - assert_file "vendor/assets/javascripts/effects.js" - assert_file "vendor/assets/javascripts/dragdrop.js" - assert_file "vendor/assets/javascripts/controls.js" - assert_file "vendor/assets/javascripts/prototype_ujs.js", /prototype/ + def test_other_javascript_libraries + run_generator [destination_root, '-j', 'prototype'] + assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/ + assert_file "app/assets/javascripts/application.js" do |contents| + assert_match %r{^//= require prototype}, contents + assert_match %r{^//= require prototype_ujs}, contents + end + assert_file 'Gemfile' do |contents| + assert_match /^gem 'prototype-rails'/, contents + end end - def test_config_jquery_javascript_library - run_generator [destination_root, "-j", "jquery"] - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/ - assert_file "app/assets/javascripts/application.js" - assert_file "vendor/assets/javascripts/jquery.js" - assert_file "vendor/assets/javascripts/jquery_ujs.js", /jQuery/ + def test_javascript_is_skipped_if_required + run_generator [destination_root, "--skip-javascript"] + assert_file "config/application.rb", /^\s+# config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/ + assert_file "app/assets/javascripts/application.js" do |contents| + assert_no_match %r{^//=\s+require\s}, contents + end end def test_template_from_dir_pwd @@ -207,9 +229,13 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_test_unit_is_removed_from_frameworks_if_skip_test_unit_is_given run_generator [destination_root, "--skip-test-unit"] - assert_file "config/application.rb" do |file| - assert_match /config.generators.test_framework = false/, file - end + assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ + end + + def test_no_active_record_or_test_unit_if_skips_given + run_generator [destination_root, "--skip-test-unit", "--skip-active-record"] + assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ + assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end def test_new_hash_style diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index e99f0f092a..375632e5bc 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -1,7 +1,7 @@ require 'generators/generators_test_helper' require 'rails/generators/rails/assets/assets_generator' -# FOXME: Silence the 'Could not find task "using_coffee?"' message in tests due to the public stub +# FIXME: Silence the 'Could not find task "using_coffee?"' message in tests due to the public stub class AssetsGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments %w(posts) diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 655d8ad450..2dfc91c683 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -39,8 +39,8 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_invokes_assets run_generator - assert_file "app/assets/javascripts/account.js" - assert_file "app/assets/stylesheets/account.css" + assert_file "app/assets/javascripts/account.js.coffee" + assert_file "app/assets/stylesheets/account.css.scss" end def test_invokes_default_test_framework diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index d61a02d32f..eb56e8d1a4 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -248,7 +248,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_file "test/unit/helpers/test_app/product_lines_helper_test.rb" # Stylesheets - assert_file "public/stylesheets/scaffold.css" + assert_file "app/assets/stylesheets/scaffold.css.scss" end def test_scaffold_on_revoke @@ -279,7 +279,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_no_file "test/unit/helpers/test_app/product_lines_helper_test.rb" # Stylesheets (should not be removed) - assert_file "public/stylesheets/scaffold.css" + assert_file "app/assets/stylesheets/scaffold.css.scss" end def test_scaffold_with_namespace_on_invoke @@ -320,7 +320,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_file "test/unit/helpers/test_app/admin/roles_helper_test.rb" # Stylesheets - assert_file "public/stylesheets/scaffold.css" + assert_file "app/assets/stylesheets/scaffold.css.scss" end def test_scaffold_with_namespace_on_revoke @@ -352,6 +352,6 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_no_file "test/unit/helpers/test_app/admin/roles_helper_test.rb" # Stylesheets (should not be removed) - assert_file "public/stylesheets/scaffold.css" + assert_file "app/assets/stylesheets/scaffold.css.scss" end end diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index d20335ad95..f637a6a17e 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -22,6 +22,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper destination File.join(Rails.root, "tmp/bukkits") arguments [destination_root] + + # brings setup, teardown, and some tests include SharedGeneratorTests def default_files @@ -103,8 +105,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_javascripts_generation run_generator [destination_root, "--mountable"] assert_file "app/assets/javascripts/application.js" - assert_file "vendor/assets/javascripts/jquery.js" - assert_file "vendor/assets/javascripts/jquery_ujs.js" end def test_skip_javascripts @@ -114,16 +114,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_file "vendor/assets/javascripts/jquery_ujs.js" end - def test_config_prototype_javascript_library - run_generator [destination_root, "-j", "prototype", "--mountable"] - assert_file "app/assets/javascripts/application.js" - assert_file "vendor/assets/javascripts/prototype.js" - assert_file "vendor/assets/javascripts/effects.js" - assert_file "vendor/assets/javascripts/dragdrop.js" - assert_file "vendor/assets/javascripts/controls.js" - assert_file "vendor/assets/javascripts/prototype_ujs.js", /prototype/ - end - def test_template_from_dir_pwd FileUtils.cd(Rails.root) assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) @@ -140,13 +130,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--full", "--skip_active_record"] FileUtils.cd destination_root `bundle install` - assert_match(/2 tests, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test`) + assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) end def test_creating_engine_in_full_mode run_generator [destination_root, "--full"] assert_file "app/assets/javascripts" assert_file "app/assets/stylesheets" + assert_file "app/assets/images" assert_file "app/models" assert_file "app/controllers" assert_file "app/views" @@ -162,6 +153,9 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_create_mountable_application_with_mountable_option run_generator [destination_root, "--mountable"] + assert_file "app/assets/javascripts" + assert_file "app/assets/stylesheets" + assert_file "app/assets/images" assert_file "config/routes.rb", /Bukkits::Engine.routes.draw do/ assert_file "lib/bukkits/engine.rb", /isolate_namespace Bukkits/ assert_file "test/dummy/config/routes.rb", /mount Bukkits::Engine => "\/bukkits"/ diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index c9c5d2fad2..03fd64ca38 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -1,3 +1,6 @@ +# +# Tests, setup, and teardown common to the application and plugin generator suites. +# module SharedGeneratorTests def setup Rails.application = TestApp::Application |