mirror of https://github.com/rails/rails
Merge pull request #49679 from zzak/railties-quiet
🤫 Quiet down railties tests
This commit is contained in:
commit
64d5f8ba0e
|
@ -89,6 +89,7 @@ module ApplicationTests
|
|||
def restore_default_config
|
||||
FileUtils.rm_rf("#{app_path}/config/environments")
|
||||
FileUtils.mv("#{app_path}/config/__environments__", "#{app_path}/config/environments")
|
||||
remove_from_env_config "production", "config.log_level = :error"
|
||||
end
|
||||
|
||||
test "Rails.env does not set the RAILS_ENV environment variable which would leak out into rake tasks" do
|
||||
|
|
|
@ -168,19 +168,18 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "#{app_moved_root}/config/environment.rb", /Rails\.application\.initialize!/
|
||||
end
|
||||
|
||||
def test_new_application_load_defaults
|
||||
def test_app_update
|
||||
run_generator
|
||||
assert_file "config/application.rb", /\s+config\.load_defaults #{Rails::VERSION::STRING.to_f}/
|
||||
end
|
||||
|
||||
def test_app_update_create_new_framework_defaults
|
||||
defaults_path = "config/initializers/new_framework_defaults_#{Rails::VERSION::MAJOR}_#{Rails::VERSION::MINOR}.rb"
|
||||
|
||||
run_generator
|
||||
assert_no_file defaults_path
|
||||
assert_no_file "config/initializers/cors.rb"
|
||||
|
||||
run_app_update
|
||||
|
||||
assert_file defaults_path
|
||||
assert_no_file "config/initializers/cors.rb"
|
||||
end
|
||||
|
||||
def test_app_update_supports_skip
|
||||
|
@ -211,13 +210,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_app_update_does_not_create_rack_cors
|
||||
run_generator
|
||||
run_app_update
|
||||
|
||||
assert_no_file "config/initializers/cors.rb"
|
||||
end
|
||||
|
||||
def test_app_update_does_not_remove_rack_cors_if_already_present
|
||||
run_generator
|
||||
FileUtils.touch("#{destination_root}/config/initializers/cors.rb")
|
||||
|
@ -244,14 +236,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_no_file "app/assets/config/manifest.js"
|
||||
end
|
||||
|
||||
def test_app_update_does_not_generate_manifest_config_when_propshaft_is_used
|
||||
run_generator [destination_root, "-a", "propshaft"]
|
||||
run_app_update
|
||||
|
||||
assert_file "config/initializers/assets.rb"
|
||||
assert_no_file "app/assets/config/manifest.js"
|
||||
end
|
||||
|
||||
def test_app_update_does_not_generate_action_cable_contents_when_skip_action_cable_is_given
|
||||
run_generator [destination_root, "--skip-action-cable"]
|
||||
run_app_update
|
||||
|
@ -328,8 +312,8 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_app_update_preserves_propshaft
|
||||
run_generator [destination_root, "-a", "propshaft"]
|
||||
def test_app_update_preserves_sprockets
|
||||
run_generator [destination_root, "-a", "sprockets"]
|
||||
|
||||
FileUtils.cd(destination_root) do
|
||||
config = "config/environments/production.rb"
|
||||
|
@ -339,23 +323,9 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_gem_for_active_storage
|
||||
run_generator
|
||||
assert_file "Gemfile", /^# gem "image_processing"/
|
||||
end
|
||||
|
||||
def test_gem_for_active_storage_when_skip_active_storage_is_given
|
||||
run_generator [destination_root, "--skip-active-storage"]
|
||||
|
||||
assert_no_gem "image_processing"
|
||||
|
||||
assert_file "Dockerfile" do |content|
|
||||
assert_no_match(/libvips/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_app_update_does_not_generate_active_storage_contents_when_skip_active_storage_is_given
|
||||
run_generator [destination_root, "--skip-active-storage"]
|
||||
|
||||
run_app_update
|
||||
|
||||
assert_file "config/environments/development.rb" do |content|
|
||||
|
@ -397,31 +367,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailbox\/engine["']/
|
||||
end
|
||||
|
||||
def test_generator_skips_action_mailbox_when_skip_active_record_is_given
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailbox\/engine["']/
|
||||
end
|
||||
|
||||
def test_generator_skips_action_mailbox_when_skip_active_storage_is_given
|
||||
run_generator [destination_root, "--skip-active-storage"]
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailbox\/engine["']/
|
||||
end
|
||||
|
||||
def test_generator_skips_action_text_when_skip_action_text_is_given
|
||||
run_generator [destination_root, "--skip-action-text"]
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_text\/engine["']/
|
||||
end
|
||||
|
||||
def test_generator_skips_action_text_when_skip_active_record_is_given
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_text\/engine["']/
|
||||
end
|
||||
|
||||
def test_generator_skips_action_text_when_skip_active_storage_is_given
|
||||
run_generator [destination_root, "--skip-active-storage"]
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_text\/engine["']/
|
||||
end
|
||||
|
||||
def test_app_update_does_not_change_config_target_version
|
||||
run_generator
|
||||
|
||||
|
@ -660,21 +610,30 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_inclusion_of_kamal_files
|
||||
run_generator_and_bundler [destination_root]
|
||||
generator [destination_root]
|
||||
run_generator_instance
|
||||
|
||||
assert_file "config/deploy.yml"
|
||||
assert_file ".env.erb"
|
||||
end
|
||||
|
||||
def test_kamal_files_are_skipped_if_required
|
||||
run_generator_and_bundler [destination_root, "--skip-kamal"]
|
||||
generator [destination_root], ["--skip-kamal"]
|
||||
run_generator_instance
|
||||
|
||||
assert_empty @bundle_commands.grep("binstubs kamal")
|
||||
assert_empty @bundle_commands.grep("exec kamal init")
|
||||
|
||||
assert_no_file "config/deploy.yml"
|
||||
assert_no_file ".env.erb"
|
||||
end
|
||||
|
||||
def test_inclusion_of_kamal_storage_volume
|
||||
run_generator_and_bundler [destination_root]
|
||||
generator [destination_root]
|
||||
run_generator_instance
|
||||
|
||||
assert_equal 1, @bundle_commands.count("binstubs kamal")
|
||||
assert_equal 1, @bundle_commands.count("exec kamal init")
|
||||
|
||||
assert_file "config/deploy.yml" do |content|
|
||||
assert_match(%r{storage:/rails/storage}, content)
|
||||
|
@ -682,7 +641,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_inclusion_of_kamal_storage_volume_if_only_skip_active_storage_is_given
|
||||
run_generator_and_bundler [destination_root, "--skip-active-storage"]
|
||||
generator [destination_root], ["--skip-active-storage"]
|
||||
run_generator_instance
|
||||
|
||||
assert_equal 1, @bundle_commands.count("binstubs kamal")
|
||||
assert_equal 1, @bundle_commands.count("exec kamal init")
|
||||
|
||||
assert_file "config/deploy.yml" do |content|
|
||||
assert_match(%r{storage:/rails/storage}, content)
|
||||
|
@ -690,11 +653,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_kamal_storage_volume_is_skipped_if_required
|
||||
run_generator_and_bundler [
|
||||
destination_root,
|
||||
"--skip-active-storage",
|
||||
"--database=postgresql"
|
||||
]
|
||||
generator [destination_root], ["--skip-active-storage", "--database=postgresql"]
|
||||
run_generator_instance
|
||||
|
||||
assert_equal 1, @bundle_commands.count("binstubs kamal")
|
||||
assert_equal 1, @bundle_commands.count("exec kamal init")
|
||||
|
||||
assert_file "config/deploy.yml" do |content|
|
||||
assert_no_match(%r{storage:/rails/storage}, content)
|
||||
|
@ -793,14 +756,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_equal 1, @bundle_commands.count("binstubs bundler")
|
||||
end
|
||||
|
||||
def test_skip_active_record_option
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
|
||||
assert_file ".gitattributes" do |content|
|
||||
assert_no_match(/schema.rb/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_skip_active_job_option
|
||||
run_generator [destination_root, "--skip-active-job"]
|
||||
|
||||
|
@ -814,15 +769,10 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
def test_skip_javascript_option
|
||||
generator([destination_root], skip_javascript: true)
|
||||
|
||||
command_check = -> command, *_ do
|
||||
if command == "importmap:install"
|
||||
flunk "`importmap:install` expected to not be called."
|
||||
end
|
||||
end
|
||||
run_generator_instance
|
||||
|
||||
generator.stub(:rails_command, command_check) do
|
||||
run_generator_instance
|
||||
end
|
||||
assert_not_includes @rails_commands, "importmap:install", "`importmap:install` expected to not be called."
|
||||
assert_not_includes @rails_commands, "turbo:install stimulus:install", "`turbo:install stimulus:install` expected to not be called."
|
||||
|
||||
assert_no_gem "importmap-rails"
|
||||
assert_no_gem "jsbundling-rails"
|
||||
|
@ -840,19 +790,9 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
def test_webpack_option
|
||||
generator([destination_root], javascript: "webpack")
|
||||
|
||||
webpack_called = 0
|
||||
command_check = -> command, *_ do
|
||||
case command
|
||||
when "javascript:install:webpack"
|
||||
webpack_called += 1
|
||||
end
|
||||
end
|
||||
run_generator_instance
|
||||
|
||||
generator.stub(:rails_command, command_check) do
|
||||
run_generator_instance
|
||||
end
|
||||
|
||||
assert_equal 1, webpack_called, "`javascript:install:webpack` expected to be called once, but was called #{webpack_called} times."
|
||||
assert_includes @rails_commands, "javascript:install:webpack", "`javascript:install:webpack` expected to be called, but wasn't."
|
||||
assert_gem "jsbundling-rails"
|
||||
assert_node_files
|
||||
end
|
||||
|
@ -860,19 +800,9 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
def test_esbuild_option
|
||||
generator([destination_root], javascript: "esbuild")
|
||||
|
||||
esbuild_called = 0
|
||||
command_check = -> command, *_ do
|
||||
case command
|
||||
when "javascript:install:esbuild"
|
||||
esbuild_called += 1
|
||||
end
|
||||
end
|
||||
run_generator_instance
|
||||
|
||||
generator.stub(:rails_command, command_check) do
|
||||
run_generator_instance
|
||||
end
|
||||
|
||||
assert_equal 1, esbuild_called, "`javascript:install:esbuild` expected to be called once, but was called #{esbuild_called} times."
|
||||
assert_includes @rails_commands, "javascript:install:esbuild", "`javascript:install:esbuild` expected to be called, but wasn't."
|
||||
assert_gem "jsbundling-rails"
|
||||
assert_node_files
|
||||
end
|
||||
|
@ -895,19 +825,9 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
def test_bun_option
|
||||
generator([destination_root], javascript: "bun")
|
||||
|
||||
bun_called = 0
|
||||
command_check = -> command, *_ do
|
||||
case command
|
||||
when "javascript:install:bun"
|
||||
bun_called += 1
|
||||
end
|
||||
end
|
||||
run_generator_instance
|
||||
|
||||
generator.stub(:rails_command, command_check) do
|
||||
run_generator_instance
|
||||
end
|
||||
|
||||
assert_equal 1, bun_called, "`javascript:install:bun` expected to be called once, but was called #{bun_called} times."
|
||||
assert_includes @rails_commands, "javascript:install:bun", "`javascript:install:bun` expected to be called, but wasn't."
|
||||
assert_gem "jsbundling-rails"
|
||||
end
|
||||
|
||||
|
@ -948,20 +868,20 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_hotwire
|
||||
run_generator_and_bundler [destination_root]
|
||||
generator [destination_root]
|
||||
run_generator_instance
|
||||
|
||||
assert_includes @rails_commands, "turbo:install stimulus:install", "`turbo:install stimulus:install` expected to be called, but wasn't."
|
||||
assert_gem "turbo-rails"
|
||||
assert_gem "stimulus-rails"
|
||||
assert_file "app/views/layouts/application.html.erb" do |content|
|
||||
assert_match(/data-turbo-track/, content)
|
||||
end
|
||||
assert_file "app/javascript/application.js" do |content|
|
||||
assert_match(/turbo/, content)
|
||||
assert_match(/controllers/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_skip_hotwire
|
||||
run_generator [destination_root, "--skip-hotwire"]
|
||||
generator [destination_root], ["--skip-hotwire"]
|
||||
run_generator_instance
|
||||
|
||||
assert_no_gem "turbo-rails"
|
||||
assert_file "app/views/layouts/application.html.erb" do |content|
|
||||
|
@ -971,11 +891,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_css_option_with_asset_pipeline_tailwind
|
||||
run_generator_and_bundler [destination_root, "--asset-pipeline=sprockets", "--css=tailwind"]
|
||||
generator [destination_root], ["--css=tailwind"]
|
||||
run_generator_instance
|
||||
|
||||
assert_includes @rails_commands, "tailwindcss:install", "`tailwindcss:install` expected to be called, but wasn't."
|
||||
assert_gem "tailwindcss-rails"
|
||||
assert_file "app/views/layouts/application.html.erb" do |content|
|
||||
assert_match(/tailwind/, content)
|
||||
end
|
||||
assert_no_node_files
|
||||
end
|
||||
|
||||
|
@ -986,9 +906,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_css_option_with_asset_pipeline_sass
|
||||
run_generator_and_bundler [destination_root, "--asset-pipeline=sprockets", "--css=sass"]
|
||||
generator [destination_root], ["--css=sass"]
|
||||
run_generator_instance
|
||||
|
||||
assert_includes @rails_commands, "dartsass:install", "`dartsass:install` expected to be called, but wasn't."
|
||||
assert_gem "dartsass-rails"
|
||||
assert_file "app/assets/stylesheets/application.scss"
|
||||
assert_no_node_files
|
||||
end
|
||||
|
||||
|
@ -999,9 +921,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_css_option_with_cssbundling_gem
|
||||
run_generator_and_bundler [destination_root, "--asset-pipeline=sprockets", "--css=postcss"]
|
||||
generator [destination_root], ["--css=postcss"]
|
||||
run_generator_instance
|
||||
|
||||
assert_includes @rails_commands, "css:install:postcss", "`css:install:postcss` expected to be called, but wasn't."
|
||||
assert_gem "cssbundling-rails"
|
||||
assert_file "app/assets/stylesheets/application.postcss.css"
|
||||
assert_node_files
|
||||
end
|
||||
|
||||
|
@ -1011,6 +935,16 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_gem "importmap-rails"
|
||||
end
|
||||
|
||||
def test_default_generator_executes_all_rails_commands
|
||||
generator [destination_root]
|
||||
run_generator_instance
|
||||
|
||||
expected_commands = [
|
||||
"credentials:diff --enroll", "importmap:install", "turbo:install stimulus:install"
|
||||
]
|
||||
assert_equal expected_commands, @rails_commands
|
||||
end
|
||||
|
||||
def test_skip_dev_gems
|
||||
run_generator [destination_root, "--skip-dev-gems"]
|
||||
assert_no_gem "web-console"
|
||||
|
@ -1499,6 +1433,36 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
private
|
||||
def assert_load_defaults
|
||||
assert_file "config/application.rb", /\s+config\.load_defaults #{Rails::VERSION::STRING.to_f}/
|
||||
end
|
||||
|
||||
def assert_gem_for_active_storage
|
||||
assert_file "Gemfile", /^# gem "image_processing"/
|
||||
end
|
||||
|
||||
def assert_frameworks_are_not_required_when_active_storage_is_skipped
|
||||
super
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailbox\/engine["']/
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_text\/engine["']/
|
||||
end
|
||||
|
||||
def assert_dockerfile_when_active_storage_is_skipped
|
||||
assert_file "Dockerfile" do |content|
|
||||
assert_no_match(/libvips/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_gems_when_active_storage_is_skipped
|
||||
assert_no_gem "image_processing"
|
||||
end
|
||||
|
||||
def assert_gitattributes_does_not_have_schema_file
|
||||
assert_file ".gitattributes" do |content|
|
||||
assert_no_match(/schema.rb/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_node_files
|
||||
assert_file ".node-version" do |content|
|
||||
assert_match %r/\d+\.\d+\.\d+/, content
|
||||
|
@ -1519,20 +1483,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def run_generator_and_bundler(args)
|
||||
option_args, positional_args = args.partition { |arg| arg.start_with?("--") }
|
||||
option_args << "--no-skip-bundle"
|
||||
generator(positional_args, option_args)
|
||||
|
||||
# Stub `rails_gemfile_entry` so that Bundler resolves `gem "rails"` to the
|
||||
# current repository instead of searching for an invalid version number
|
||||
# (for a version that hasn't been released yet).
|
||||
rails_gemfile_entry = Rails::Generators::AppBase::GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH)
|
||||
generator.stub(:rails_gemfile_entry, -> { rails_gemfile_entry }) do
|
||||
quietly { run_generator_instance }
|
||||
end
|
||||
end
|
||||
|
||||
def run_app_update(app_root = destination_root, flags: "--force")
|
||||
Dir.chdir(app_root) do
|
||||
gemfile_contents = File.read("Gemfile")
|
||||
|
|
|
@ -247,13 +247,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "Gemfile", /mysql/
|
||||
end
|
||||
|
||||
def test_skip_database_dependency
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
assert_file "Gemfile" do |contents|
|
||||
assert_no_match(/sqlite/, contents)
|
||||
end
|
||||
end
|
||||
|
||||
def test_ensure_that_skip_active_record_option_is_passed_to_app_generator
|
||||
run_generator [destination_root, "--skip_active_record"]
|
||||
assert_file "test/test_helper.rb" do |contents|
|
||||
|
|
|
@ -50,7 +50,7 @@ module SharedGeneratorTests
|
|||
assert_match %r/conflicting option/i, error.message
|
||||
end
|
||||
|
||||
def test_skeleton_is_created
|
||||
def test_codebase_is_created
|
||||
run_generator
|
||||
|
||||
generated_files_and_folders = []
|
||||
|
@ -78,6 +78,25 @@ module SharedGeneratorTests
|
|||
assert_equal generated_files_and_folders.sort, default_files, "The expected list of generated files is not alphabetical"
|
||||
|
||||
default_files.each { |path| assert_file path }
|
||||
|
||||
assert_file "#{application_path}/config/application.rb", /\s+require\s+["']rails\/all["']/
|
||||
|
||||
assert_file "#{application_path}/config/environments/development.rb" do |content|
|
||||
assert_match(/config\.action_mailer\.raise_delivery_errors = false/, content)
|
||||
assert_match(/config\.active_storage/, content)
|
||||
end
|
||||
assert_file "#{application_path}/config/environments/test.rb" do |content|
|
||||
assert_match(/config\.action_mailer\.delivery_method = :test/, content)
|
||||
assert_match(/config\.active_storage/, content)
|
||||
end
|
||||
assert_file "#{application_path}/config/environments/production.rb" do |content|
|
||||
assert_match(/# config\.action_mailer\.raise_delivery_errors = false/, content)
|
||||
assert_match(/^ # config\.require_master_key = true/, content)
|
||||
assert_match(/config\.active_storage/, content)
|
||||
end
|
||||
|
||||
assert_load_defaults
|
||||
assert_gem_for_active_storage
|
||||
end
|
||||
|
||||
def test_plugin_new_generate_pretend
|
||||
|
@ -223,59 +242,51 @@ module SharedGeneratorTests
|
|||
assert_file "#{application_path}/config/application.rb", /^require\s+["']rails\/test_unit\/railtie["']/
|
||||
end
|
||||
|
||||
def test_generator_without_skips
|
||||
run_generator
|
||||
assert_file "#{application_path}/config/application.rb", /\s+require\s+["']rails\/all["']/
|
||||
assert_file "#{application_path}/config/environments/development.rb" do |content|
|
||||
assert_match(/config\.action_mailer\.raise_delivery_errors = false/, content)
|
||||
end
|
||||
assert_file "#{application_path}/config/environments/test.rb" do |content|
|
||||
assert_match(/config\.action_mailer\.delivery_method = :test/, content)
|
||||
end
|
||||
assert_file "#{application_path}/config/environments/production.rb" do |content|
|
||||
assert_match(/# config\.action_mailer\.raise_delivery_errors = false/, content)
|
||||
assert_match(/^ # config\.require_master_key = true/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_if_skip_active_record_is_given
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
assert_no_directory "#{application_path}/db/"
|
||||
assert_no_file "#{application_path}/config/database.yml"
|
||||
assert_no_file "#{application_path}/app/models/application_record.rb"
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
|
||||
|
||||
assert_file "#{application_path}/config/application.rb" do |content|
|
||||
assert_match(/#\s+require\s+["']active_record\/railtie["']/, content)
|
||||
assert_match(/#\s+require\s+["']active_storage\/engine["']/, content)
|
||||
assert_match(/#\s+require\s+["']action_mailbox\/engine["']/, content)
|
||||
assert_match(/#\s+require\s+["']action_text\/engine["']/, content)
|
||||
end
|
||||
|
||||
assert_file "test/test_helper.rb" do |helper_content|
|
||||
assert_no_match(/fixtures :all/, helper_content)
|
||||
end
|
||||
assert_file "#{application_path}/bin/setup" do |setup_content|
|
||||
assert_no_match(/db:prepare/, setup_content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_for_active_storage
|
||||
run_generator([destination_root])
|
||||
|
||||
assert_file "#{application_path}/config/environments/development.rb" do |content|
|
||||
assert_match(/config\.active_storage/, content)
|
||||
assert_no_match(/config\.active_storage/, content)
|
||||
end
|
||||
|
||||
assert_file "#{application_path}/config/environments/production.rb" do |content|
|
||||
assert_match(/config\.active_storage/, content)
|
||||
assert_no_match(/config\.active_storage/, content)
|
||||
end
|
||||
|
||||
assert_file "#{application_path}/config/environments/test.rb" do |content|
|
||||
assert_match(/config\.active_storage/, content)
|
||||
assert_no_match(/config\.active_storage/, content)
|
||||
end
|
||||
|
||||
assert_file "#{application_path}/config/storage.yml"
|
||||
assert_directory "#{application_path}/storage"
|
||||
assert_directory "#{application_path}/tmp/storage"
|
||||
assert_no_file "#{application_path}/config/storage.yml"
|
||||
|
||||
assert_gitattributes_does_not_have_schema_file
|
||||
|
||||
assert_file "Gemfile" do |contents|
|
||||
assert_no_match(/sqlite/, contents)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_if_skip_active_storage_is_given
|
||||
run_generator [destination_root, "--skip-active-storage"]
|
||||
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/
|
||||
assert_frameworks_are_not_required_when_active_storage_is_skipped
|
||||
|
||||
assert_file "#{application_path}/config/environments/development.rb" do |content|
|
||||
assert_no_match(/config\.active_storage/, content)
|
||||
|
@ -290,26 +301,9 @@ module SharedGeneratorTests
|
|||
end
|
||||
|
||||
assert_no_file "#{application_path}/config/storage.yml"
|
||||
end
|
||||
|
||||
def test_generator_does_not_generate_active_storage_contents_if_skip_active_record_is_given
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/
|
||||
|
||||
assert_file "#{application_path}/config/environments/development.rb" do |content|
|
||||
assert_no_match(/config\.active_storage/, content)
|
||||
end
|
||||
|
||||
assert_file "#{application_path}/config/environments/production.rb" do |content|
|
||||
assert_no_match(/config\.active_storage/, content)
|
||||
end
|
||||
|
||||
assert_file "#{application_path}/config/environments/test.rb" do |content|
|
||||
assert_no_match(/config\.active_storage/, content)
|
||||
end
|
||||
|
||||
assert_no_file "#{application_path}/config/storage.yml"
|
||||
assert_gems_when_active_storage_is_skipped
|
||||
assert_dockerfile_when_active_storage_is_skipped
|
||||
end
|
||||
|
||||
def test_generator_does_not_create_storage_dir_if_skip_active_storage_is_given_and_not_using_sqlite
|
||||
|
@ -405,6 +399,25 @@ module SharedGeneratorTests
|
|||
end
|
||||
|
||||
private
|
||||
def assert_load_defaults
|
||||
end
|
||||
|
||||
def assert_gem_for_active_storage
|
||||
end
|
||||
|
||||
def assert_frameworks_are_not_required_when_active_storage_is_skipped
|
||||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/
|
||||
end
|
||||
|
||||
def assert_gems_when_active_storage_is_skipped
|
||||
end
|
||||
|
||||
def assert_dockerfile_when_active_storage_is_skipped
|
||||
end
|
||||
|
||||
def assert_gitattributes_does_not_have_schema_file
|
||||
end
|
||||
|
||||
def fixtures_root
|
||||
File.expand_path("../fixtures", __dir__)
|
||||
end
|
||||
|
@ -413,8 +426,13 @@ module SharedGeneratorTests
|
|||
@bundle_commands = []
|
||||
@bundle_command_stub ||= -> (command, *) { @bundle_commands << command }
|
||||
|
||||
@rails_commands = []
|
||||
@rails_command_stub ||= -> (command, *_) { @rails_commands << command }
|
||||
|
||||
generator.stub(:bundle_command, @bundle_command_stub) do
|
||||
super
|
||||
generator.stub(:rails_command, @rails_command_stub) do
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -145,6 +145,7 @@ module TestHelpers
|
|||
add_to_env_config :development, "config.action_view.annotate_rendered_view_with_filenames = false"
|
||||
|
||||
remove_from_env_config("development", "config.generators.apply_rubocop_autocorrect_after_generate!")
|
||||
add_to_env_config :production, "config.log_level = :error"
|
||||
end
|
||||
|
||||
def teardown_app
|
||||
|
@ -262,7 +263,7 @@ module TestHelpers
|
|||
@app.config.eager_load = false
|
||||
@app.config.session_store :cookie_store, key: "_myapp_session"
|
||||
@app.config.active_support.deprecation = :log
|
||||
@app.config.log_level = :info
|
||||
@app.config.log_level = :error
|
||||
@app.config.secret_key_base = "b3c631c314c0bbca50c1b2843150fe33"
|
||||
|
||||
yield @app if block_given?
|
||||
|
|
Loading…
Reference in New Issue