Repository: rails/rails
File: railties/test/generators/app_generator_test.rb (Ruby)

Code before:
  def test_default_namespace
    assert_match "rails:app", Rails::Generators::AppGenerator.namespace
  end

  def test_file_is_added_for_backwards_compatibility
    action :file, "lib/test_file.rb", "here's test data"
    assert_file "lib/test_file.rb", "here's test data"
  end

  def test_pretend_option
    output = run_generator [File.join(destination_root, "myapp"), "--pretend"]
    assert_no_match(/run  bundle install/, output)
    assert_no_match(/run  git init/, output)
  end

  def test_quiet_option
    output = run_generator [File.join(destination_root, "myapp"), "--quiet"]
    assert_empty output
  end

  def test_quiet_option_quiets_rails_commands
    generator = generator_class.new(
      [File.join(destination_root, "myapp")], ["--quiet"], destination_root: destination_root
    )

    generator.stub :bundle_install?, -> { caller.grep(/run_hotwire/).any? } do
      output = capture(:stdout) { generator.invoke_all }
      assert_empty output
    end
  end

  def test_force_option_overwrites_every_file_except_master_key
    run_generator [File.join(destination_root, "myapp")]
    output = run_generator [File.join(destination_root, "myapp"), "--force"]
    assert_match(/force/, output)
    assert_no_match("force  config/master.key", output)
  end

  def test_application_name_with_spaces
    path = File.join(destination_root, "foo bar")

    # This also applies to MySQL apps but not with SQLite
    run_generator [path, "-d", "postgresql"]

    assert_file "foo bar/config/database.yml", /database: foo_bar_development/
  end

  def test_web_console
    run_generator
    assert_gem "web-console"
  end

Review comment (bug):
Is `run_hotwire` a hard dependency here or is there another native command we can look for?
My concern is just that the name may change or be removed and this test will fail, which is unrelated.

Code after:
  def test_inclusion_of_kamal_storage_volume
    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)
    end
  end

  def test_inclusion_of_kamal_storage_volume_if_only_skip_active_storage_is_given
    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)
    end
  end

  def test_kamal_storage_volume_is_skipped_if_required
    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)
    end
  end

  def test_kamal_deploy_yml_includes_asset_path_for_regular_apps
    generator [destination_root]
    run_generator_instance

    assert_file "config/deploy.yml" do |content|
      assert_match(/asset_path: \/rails\/public\/assets/, content)
    end
  end

  def test_usage_read_from_file
    assert_called(File, :read, returns: "USAGE FROM FILE") do
      assert_equal "USAGE FROM FILE", Rails::Generators::AppGenerator.desc
    end
  end