diff options
Diffstat (limited to 'railties/test/generators')
7 files changed, 161 insertions, 79 deletions
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 018c2fa6bf..3ef06c7f25 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -8,6 +8,8 @@ DEFAULT_APP_FILES = %w( Gemfile Rakefile config.ru + app/assets/javascripts + app/assets/stylesheets app/controllers app/helpers app/mailers @@ -22,8 +24,6 @@ DEFAULT_APP_FILES = %w( lib/tasks log public/images - public/javascripts - public/stylesheets script/rails test/fixtures test/functional @@ -31,11 +31,9 @@ DEFAULT_APP_FILES = %w( test/performance test/unit vendor + vendor/assets vendor/plugins - tmp/sessions - tmp/sockets tmp/cache - tmp/pids ) class AppGeneratorTest < Rails::Generators::TestCase @@ -49,8 +47,9 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_application_controller_and_layout_files run_generator - assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag :all/ - assert_no_file "public/stylesheets/application.css" + assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag\s+"application"/ + assert_file "app/views/layouts/application.html.erb", /javascript_include_tag\s+"application"/ + assert_file "app/assets/stylesheets/application.css" end def test_invalid_application_name_raises_an_error @@ -146,43 +145,40 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end - def test_prototype_and_test_unit_are_added_by_default + def test_jquery_and_test_unit_are_added_by_default run_generator - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(jquery rails\)/ - assert_file "public/javascripts/application.js" - assert_file "public/javascripts/prototype.js" - assert_file "public/javascripts/rails.js" - assert_file "public/javascripts/controls.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/effects.js" + 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" 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 "public/javascripts/application.js" - assert_no_file "public/javascripts/prototype.js" - assert_no_file "public/javascripts/rails.js" + assert_file "app/assets/javascripts/application.js" + assert_no_file "vendor/assets/javascripts/jquery.js" + assert_no_file "vendor/assets/javascripts/jquery_ujs.js" 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\(jquery rails\)/ - assert_file "public/javascripts/application.js" - assert_file "public/javascripts/prototype.js" - assert_file "public/javascripts/controls.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/effects.js" - assert_file "public/javascripts/rails.js", /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/ 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\(jquery rails\)/ - assert_file "public/javascripts/application.js" - assert_file "public/javascripts/jquery.js" - assert_file "public/javascripts/rails.js", /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/ end def test_template_from_dir_pwd @@ -216,6 +212,24 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_new_hash_style + run_generator [destination_root] + assert_file "config/initializers/session_store.rb" do |file| + if RUBY_VERSION < "1.9" + assert_match /config.session_store :cookie_store, :key => '_.+_session'/, file + else + assert_match /config.session_store :cookie_store, key: '_.+_session'/, file + end + end + end + + def test_force_old_style_hash + run_generator [destination_root, "--old-style-hash"] + assert_file "config/initializers/session_store.rb" do |file| + assert_match /config.session_store :cookie_store, :key => '_.+_session'/, file + end + end + protected def action(*args, &block) diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb new file mode 100644 index 0000000000..e99f0f092a --- /dev/null +++ b/railties/test/generators/assets_generator_test.rb @@ -0,0 +1,26 @@ +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 +class AssetsGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + arguments %w(posts) + + def test_assets + run_generator + assert_file "app/assets/javascripts/posts.js.coffee" + assert_file "app/assets/stylesheets/posts.css.scss" + end + + def test_skipping_assets + content = run_generator ["posts", "--no-stylesheets", "--no-javascripts"] + assert_no_file "app/assets/javascripts/posts.js.coffee" + assert_no_file "app/assets/stylesheets/posts.css.scss" + end + + def test_vanilla_assets + run_generator ["posts", "--no-javascript-engine", "--no-stylesheet-engine"] + assert_file "app/assets/javascripts/posts.js" + assert_file "app/assets/stylesheets/posts.css" + end +end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index be99dc068d..655d8ad450 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -37,6 +37,12 @@ class ControllerGeneratorTest < Rails::Generators::TestCase assert_no_file "test/unit/helpers/account_helper_test.rb" end + def test_invokes_assets + run_generator + assert_file "app/assets/javascripts/account.js" + assert_file "app/assets/stylesheets/account.css" + end + def test_invokes_default_test_framework run_generator assert_file "test/functional/account_controller_test.rb" diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 3c11c8dbaf..d20335ad95 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -95,41 +95,33 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_skipping_javascripts_without_mountable_option run_generator - assert_no_file "public/javascripts/prototype.js" - assert_no_file "public/javascripts/rails.js" - assert_no_file "public/javascripts/controls.js" - assert_no_file "public/javascripts/dragdrop.js" - assert_no_file "public/javascripts/dragdrop.js" - assert_no_file "public/javascripts/application.js" + assert_no_file "app/assets/javascripts/application.js" + assert_no_file "vendor/assets/javascripts/jquery.js" + assert_no_file "vendor/assets/javascripts/jquery_ujs.js" end def test_javascripts_generation run_generator [destination_root, "--mountable"] - assert_file "public/javascripts/rails.js" - assert_file "public/javascripts/prototype.js" - assert_file "public/javascripts/controls.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/application.js" + 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 run_generator [destination_root, "--skip-javascript", "--mountable"] - assert_no_file "public/javascripts/prototype.js" - assert_no_file "public/javascripts/rails.js" - assert_no_file "public/javascripts/controls.js" - assert_no_file "public/javascripts/dragdrop.js" - assert_no_file "public/javascripts/dragdrop.js" + assert_no_file "app/assets/javascripts/application.js" + assert_no_file "vendor/assets/javascripts/jquery.js" + assert_no_file "vendor/assets/javascripts/jquery_ujs.js" end - def test_ensure_that_javascript_option_is_passed_to_app_generator - run_generator [destination_root, "--javascript", "jquery"] - assert_file "test/dummy/public/javascripts/jquery.js" - end - - def test_ensure_that_skip_javascript_option_is_passed_to_app_generator - run_generator [destination_root, "--skip_javascript"] - assert_no_file "test/dummy/public/javascripts/prototype.js" + 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 @@ -153,6 +145,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase 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/models" + assert_file "app/controllers" + assert_file "app/views" + assert_file "app/helpers" assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ @@ -227,3 +225,4 @@ protected silence(:stdout){ generator.send(*args, &block) } end end + diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index d55ed22975..c7f45a807d 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -122,4 +122,22 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase ensure Unknown::Generators.send :remove_const, :ActiveModel end + + def test_new_hash_style + run_generator + assert_file "app/controllers/users_controller.rb" do |content| + if RUBY_VERSION < "1.9" + assert_match /\{ render :action => "new" \}/, content + else + assert_match /\{ render action: "new" \}/, content + end + end + end + + def test_force_old_style_hash + run_generator ["User", "--old-style-hash"] + assert_file "app/controllers/users_controller.rb" do |content| + assert_match /\{ render :action => "new" \}/, content + end + end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index df787f61ba..4b07f8bcbe 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -79,8 +79,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/helpers/product_lines_helper.rb" assert_file "test/unit/helpers/product_lines_helper_test.rb" - # Stylesheets - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/javascripts/product_lines.js.coffee" + assert_file "app/assets/stylesheets/product_lines.css.scss" end def test_scaffold_on_revoke @@ -110,8 +112,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "app/helpers/product_lines_helper.rb" assert_no_file "test/unit/helpers/product_lines_helper_test.rb" - # Stylesheets (should not be removed) - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_no_file "app/assets/javascripts/product_lines.js.coffee" + assert_no_file "app/assets/stylesheets/product_lines.css.scss" end def test_scaffold_with_namespace_on_invoke @@ -184,8 +188,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/helpers/admin/roles_helper.rb" assert_file "test/unit/helpers/admin/roles_helper_test.rb" - # Stylesheets - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_file "app/assets/javascripts/admin/roles.js.coffee" + assert_file "app/assets/stylesheets/admin/roles.css.scss" end def test_scaffold_with_namespace_on_revoke @@ -216,8 +222,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "app/helpers/admin/roles_helper.rb" assert_no_file "test/unit/helpers/admin/roles_helper_test.rb" - # Stylesheets (should not be removed) - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/javascripts/admin/roles.js.coffee" + assert_no_file "app/assets/stylesheets/admin/roles.css.scss" end def test_scaffold_generator_on_revoke_does_not_mutilate_legacy_map_parameter @@ -235,6 +243,34 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/ end + def test_scaffold_generator_no_assets + run_generator [ "posts", "--no-assets" ] + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/javascripts/posts.js.coffee" + assert_no_file "app/assets/stylesheets/posts.css.scss" + end + + def test_scaffold_generator_no_stylesheets + run_generator [ "posts", "--no-stylesheets" ] + assert_no_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/javascripts/posts.js.coffee" + assert_no_file "app/assets/stylesheets/posts.css.scss" + end + + def test_scaffold_generator_no_javascripts + run_generator [ "posts", "--no-javascripts" ] + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/javascripts/posts.js.coffee" + assert_file "app/assets/stylesheets/posts.css.scss" + end + + def test_scaffold_generator_no_negines + run_generator [ "posts", "--no-javascript-engine", "--no-stylesheet-engine" ] + assert_file "app/assets/stylesheets/scaffold.css" + assert_file "app/assets/javascripts/posts.js" + assert_file "app/assets/stylesheets/posts.css" + end + def test_scaffold_generator_outputs_error_message_on_missing_attribute_type content = capture(:stderr) { run_generator ["post", "title:string", "body"]} assert_match(/Missing type for attribute 'body'/, content) diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb deleted file mode 100644 index aaeb686daa..0000000000 --- a/railties/test/generators/stylesheets_generator_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/stylesheets/stylesheets_generator' - -class StylesheetsGeneratorTest < Rails::Generators::TestCase - include GeneratorsTestHelper - - def test_copy_stylesheets - run_generator - assert_file "public/stylesheets/scaffold.css" - end - - def test_stylesheets_are_not_deleted_on_revoke - run_generator - run_generator [], :behavior => :revoke - assert_file "public/stylesheets/scaffold.css" - end -end |