From 397eed285a8ed41fb924b0ad6032c0cacdd70bca Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Thu, 31 Aug 2023 10:31:52 +0200 Subject: [PATCH] Improve test app creation - Remove unneeded libraries Also fixes an issue when running specs against Rails 5.2 / Ruby 2.2 because of a squiggly heredoc in active storage --- Rakefile | 14 +++++++++++++- spec/fixtures/railsapp/config/application.rb | 19 ++++++++++++------- .../config/environments/development.rb | 18 ------------------ .../railsapp/config/initializers/assets.rb | 3 --- 4 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 spec/fixtures/railsapp/config/initializers/assets.rb diff --git a/Rakefile b/Rakefile index 6665e969..4f422057 100644 --- a/Rakefile +++ b/Rakefile @@ -13,10 +13,22 @@ task :default => ['testapp:create', :spec] namespace :testapp do desc 'Create a dummy rails application for testing in /tmp' task :create do + options = %w[ + --skip-action-cable + --skip-action-text + --skip-active-job + --skip-active-storage + --skip-asset-pipeline + --skip-bundle + --skip-git + --skip-javascript + --skip-sprockets + --skip-webpack-install + ] FileUtils.mkdir_p('tmp/aruba') Dir.chdir('tmp') do FileUtils.rm_rf('railsapp') - sh 'rails new railsapp --skip-bundle --skip-javascript --skip-webpack-install --skip-git' + sh "rails new railsapp #{options.join(' ')}" end FileUtils.cp_r('spec/fixtures/railsapp/.', 'tmp/railsapp/') FileUtils.rm('tmp/railsapp/Gemfile') diff --git a/spec/fixtures/railsapp/config/application.rb b/spec/fixtures/railsapp/config/application.rb index b45bceea..6e0234f2 100644 --- a/spec/fixtures/railsapp/config/application.rb +++ b/spec/fixtures/railsapp/config/application.rb @@ -1,17 +1,22 @@ 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_view/railtie" +# require "action_cable/engine" +# require "sprockets/railtie" +# require "rails/test_unit/railtie" -# Require the gems listed in Gemfile, including any gems -# you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Railsapp class Application < Rails::Application - # Initialize configuration defaults for originally generated Rails version. config.active_record.schema_format = :sql - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. end end diff --git a/spec/fixtures/railsapp/config/environments/development.rb b/spec/fixtures/railsapp/config/environments/development.rb index 6d4fb2c5..00adfcf7 100644 --- a/spec/fixtures/railsapp/config/environments/development.rb +++ b/spec/fixtures/railsapp/config/environments/development.rb @@ -12,27 +12,9 @@ # Show full error reports. config.consider_all_requests_local = true - # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false - # 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 - - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - config.assets.debug = true if Rails.version < '7.0' - - # Suppress logger output for asset requests. - config.assets.quiet = true if Rails.version < '7.0' - - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true - - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/spec/fixtures/railsapp/config/initializers/assets.rb b/spec/fixtures/railsapp/config/initializers/assets.rb deleted file mode 100644 index ea9979e6..00000000 --- a/spec/fixtures/railsapp/config/initializers/assets.rb +++ /dev/null @@ -1,3 +0,0 @@ -## this file overrides the default initialization of assets.rb - -Rails.application.config.assets.version = "1.0" if Rails.version < '7.0'