Skip to content

Regenerate dummy Rails app with minimum config; Refactor tests #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions test/dummy/app/jobs/application_job.rb

This file was deleted.

4 changes: 0 additions & 4 deletions test/dummy/app/mailers/application_mailer.rb

This file was deleted.

3 changes: 0 additions & 3 deletions test/dummy/app/models/application_record.rb

This file was deleted.

13 changes: 0 additions & 13 deletions test/dummy/app/views/layouts/mailer.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion test/dummy/app/views/layouts/mailer.text.erb

This file was deleted.

8 changes: 0 additions & 8 deletions test/dummy/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ FileUtils.chdir APP_ROOT do
puts "== Installing dependencies =="
system("bundle check") || system!("bundle install")

# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
# end

puts "\n== Preparing database =="
system! "bin/rails db:prepare"

puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"

Expand Down
19 changes: 17 additions & 2 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
require_relative "boot"

require "rails/all"
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
# require "active_job/railtie"
# require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand All @@ -23,6 +35,9 @@ class Application < Rails::Application
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

config.eager_load = false if config.eager_load.nil?
config.eager_load = false

# Don't generate system test files.
config.generators.system_tests = nil
end
end
10 changes: 0 additions & 10 deletions test/dummy/config/cable.yml

This file was deleted.

39 changes: 0 additions & 39 deletions test/dummy/config/database.yml

This file was deleted.

27 changes: 0 additions & 27 deletions test/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,15 @@
# Change to :null_store to avoid any caching.
config.cache_store = :memory_store

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Make template changes take effect immediately.
config.action_mailer.perform_caching = false

# Set localhost to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {host: "localhost", port: 3000}

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Append comments with runtime information tags to SQL queries in logs.
config.active_record.query_log_tags_enabled = true

# Highlight code that enqueued background job in logs.
config.active_job.verbose_enqueue_logs = true

# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

# Annotate rendered view with file names.
config.action_view.annotate_rendered_view_with_filenames = true

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
end
28 changes: 0 additions & 28 deletions test/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Assume all access to the app is happening through a SSL-terminating reverse proxy.
config.assume_ssl = true

Expand All @@ -49,35 +46,10 @@
# Replace the default in-process memory cache store with a durable alternative.
# config.cache_store = :mem_cache_store

# Replace the default in-process and non-durable queuing backend for Active Job.
# config.active_job.queue_adapter = :resque

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {host: "example.com"}

# Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit.
# config.action_mailer.smtp_settings = {
# user_name: Rails.application.credentials.dig(:smtp, :user_name),
# password: Rails.application.credentials.dig(:smtp, :password),
# address: "smtp.example.com",
# port: 587,
# authentication: :plain
# }

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

# Only use :id for inspections in production.
config.active_record.attributes_for_inspect = [:id]

# Enable DNS rebinding protection and other `Host` header attacks.
# config.hosts = [
# "example.com", # Allow requests from example.com
Expand Down
11 changes: 0 additions & 11 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {host: "example.com"}

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

Expand Down
34 changes: 0 additions & 34 deletions test/dummy/config/storage.yml

This file was deleted.

2 changes: 0 additions & 2 deletions test/env_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
module EnvHelpers
private

DEFAULT_RAILS_ENV = "development"

def with_rails_env(env, &block)
Rails.instance_variable_set :@_env, nil
switch_env "RAILS_ENV", env do
Expand Down
4 changes: 1 addition & 3 deletions test/features/console_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
module ConsoleHelpers
private

DUMMY_RAILS = File.expand_path "../../dummy/bin/rails", __FILE__

def with_pty
PTY.open do |primary, replica|
@primary, @replica = primary, replica
Expand All @@ -27,7 +25,7 @@ def spawn_console(options, wait_for_prompt: true, env: {})

pid = Process.spawn(
env,
"#{DUMMY_RAILS} console #{options}",
"#{DUMMY_ROOT}/bin/rails console #{options}",
in: @replica, out: @replica, err: @replica
)

Expand Down
8 changes: 4 additions & 4 deletions test/features/credentials_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require_relative "../test_helper"
require_relative "runner_helper"
require_relative "file_helper"
require_relative "runner_helpers"
require_relative "file_helpers"

module Rails::AppEnv::FeaturesTest
class CredentialsTest < ActiveSupport::TestCase
include RunnerHelper
include FileHelper
include RunnerHelpers
include FileHelpers

CREDENTIALS_PATH_TEST_CASES = {
"is {APP_ENV}.yml.enc when both APP_ENV and RAILS_ENV are present": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FileHelper
module FileHelpers
private

def with_file(path, &block)
Expand Down
4 changes: 2 additions & 2 deletions test/features/info_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require_relative "../test_helper"
require_relative "runner_helper"
require_relative "runner_helpers"

module Rails::AppEnv::FeaturesTest
class InfoTest < ActiveSupport::TestCase
include RunnerHelper
include RunnerHelpers

TEST_CASES = {
"is APP_ENV when both APP_ENV and RAILS_ENV are present": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
require_relative "../env_helpers"

module RunnerHelper
include EnvHelpers

module RunnerHelpers
private

DUMMY_RAILS = File.expand_path "../../dummy/bin/rails", __FILE__

def assert_runner_puts(expected, subject, env: {})
env = env.with_defaults({"APP_ENV" => nil, "RAILS_ENV" => nil, "SECRET_KEY_BASE_DUMMY" => "1"})

stdout, status = Open3.capture2(env, DUMMY_RAILS, "runner", "puts #{subject}")
stdout, status = Open3.capture2(env, "#{DUMMY_ROOT}/bin/rails", "runner", "puts #{subject}")

assert_predicate status, :success?
assert_equal expected.to_s, stdout.chomp
Expand Down
5 changes: 4 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
ENV["RAILS_ENV"] = "test"

require_relative "../test/dummy/config/environment"
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
require "rails/test_help"

# Load fixtures from the engine
Expand All @@ -12,3 +11,7 @@
ActiveSupport::TestCase.file_fixture_path = File.expand_path("fixtures", __dir__) + "/files"
ActiveSupport::TestCase.fixtures :all
end

DEFAULT_RAILS_ENV = "development"

DUMMY_ROOT = File.expand_path "../dummy", __FILE__
Loading