diff options
Diffstat (limited to 'railties/test/generators/app_generator_test.rb')
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 84 |
1 files changed, 52 insertions, 32 deletions
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index ffdee3a6b5..ff73014046 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -4,6 +4,7 @@ require "generators/shared_generator_tests" DEFAULT_APP_FILES = %w( .gitignore + .ruby-version README.md Gemfile Rakefile @@ -63,6 +64,7 @@ DEFAULT_APP_FILES = %w( config/routes.rb config/secrets.yml config/spring.rb + config/storage.yml db db/seeds.rb lib @@ -392,6 +394,16 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_default_frameworks_are_required_when_others_are_removed + run_generator [destination_root, "--skip-active-record", "--skip-action-mailer", "--skip-action-cable", "--skip-sprockets", "--skip-test"] + assert_file "config/application.rb", /require\s+["']rails["']/ + assert_file "config/application.rb", /require\s+["']active_model\/railtie["']/ + assert_file "config/application.rb", /require\s+["']active_job\/railtie["']/ + assert_file "config/application.rb", /require\s+["']action_controller\/railtie["']/ + assert_file "config/application.rb", /require\s+["']action_view\/railtie["']/ + assert_file "config/application.rb", /require\s+["']active_storage\/engine["']/ + end + def test_generator_defaults_to_puma_version run_generator [destination_root] assert_gem "puma", "'~> 3.7'" @@ -447,22 +459,26 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_sprockets_is_given run_generator [destination_root, "--skip-sprockets"] + assert_no_file "config/initializers/assets.rb" - assert_file "config/application.rb" do |content| - assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) - end + + assert_file "config/application.rb", /#\s+require\s+["']sprockets\/railtie["']/ + assert_file "Gemfile" do |content| assert_no_match(/sass-rails/, content) assert_no_match(/uglifier/, content) assert_no_match(/coffee-rails/, content) end + assert_file "config/environments/development.rb" do |content| - assert_no_match(/config\.assets\.debug = true/, content) + assert_no_match(/config\.assets\.debug/, content) end + assert_file "config/environments/production.rb" do |content| - assert_no_match(/config\.assets\.digest = true/, content) - assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) - assert_no_match(/config\.assets\.css_compressor = :sass/, content) + assert_no_match(/config\.assets\.digest/, content) + assert_no_match(/config\.assets\.js_compressor/, content) + assert_no_match(/config\.assets\.css_compressor/, content) + assert_no_match(/config\.assets\.compile/, content) end end @@ -471,7 +487,8 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/ assert_no_file "config/cable.yml" assert_no_file "app/assets/javascripts/cable.js" - assert_no_file "app/channels" + assert_no_directory "app/assets/javascripts/channels" + assert_no_directory "app/channels" assert_file "Gemfile" do |content| assert_no_match(/redis/, content) end @@ -484,10 +501,15 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_test_is_given run_generator [destination_root, "--skip-test"] + + assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ + assert_file "Gemfile" do |content| assert_no_match(/capybara/, content) assert_no_match(/selenium-webdriver/, content) end + + assert_no_directory("test") end def test_generator_if_skip_system_test_is_given @@ -496,6 +518,10 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/capybara/, content) assert_no_match(/selenium-webdriver/, content) end + + assert_directory("test") + + assert_no_directory("test/system") end def test_does_not_generate_system_test_files_if_skip_system_test_is_given @@ -521,6 +547,8 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator if defined?(JRUBY_VERSION) assert_gem "therubyrhino" + elsif RUBY_PLATFORM =~ /mingw|mswin/ + assert_gem "duktape" else assert_file "Gemfile", /# gem 'mini_racer', platforms: :ruby/ end @@ -566,6 +594,11 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator([destination_root]) assert_file "package.json", /dependencies/ assert_file "config/initializers/assets.rb", /node_modules/ + + assert_file ".gitignore" do |content| + assert_match(/node_modules/, content) + assert_match(/yarn-error\.log/, content) + end end def test_generator_for_yarn_skipped @@ -650,18 +683,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "lib/test_file.rb", "heres test data" end - def test_tests_are_removed_from_frameworks_if_skip_test_is_given - run_generator [destination_root, "--skip-test"] - assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ - end - - def test_no_active_record_or_tests_if_skips_given - run_generator [destination_root, "--skip-test", "--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["']/ - assert_file "config/application.rb", /\s+require\s+["']active_job\/railtie["']/ - end - def test_pretend_option output = run_generator [File.join(destination_root, "myapp"), "--pretend"] assert_no_match(/run bundle install/, output) @@ -805,6 +826,17 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_inclusion_of_ruby_version + run_generator + + assert_file "Gemfile" do |content| + assert_match(/ruby '#{RUBY_VERSION}'/, content) + end + assert_file ".ruby-version" do |content| + assert_match(/#{RUBY_VERSION}/, content) + end + end + def test_version_control_initializes_git_repo run_generator [destination_root] assert_directory ".git" @@ -881,18 +913,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_directory("test/system") end - def test_system_tests_are_not_generated_on_system_test_skip - run_generator [destination_root, "--skip-system-test"] - - assert_no_directory("test/system") - end - - def test_system_tests_are_not_generated_on_test_skip - run_generator [destination_root, "--skip-test"] - - assert_no_directory("test/system") - end - private def stub_rails_application(root) Rails.application.config.root = root |