From ca0603d85ae76e4f0ae68e02816f464ccdfd1e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Wed, 5 May 2021 05:36:32 +0200 Subject: [PATCH] Update defaults in dummy application Here it's a description of the reason for each change. Keep in mind that CI test against Rails 5.2 as the minimal version: - serve_static_assets: Removed it. It's [not available since Rails 5.0](https://guides.rubyonrails.org/5_0_release_notes.html#railties-removals). - public_file_server.enabled: Set explicitly to `true`. Even if it was already `true`, a [real Rails application will default it to `false` in the production environment unless a env variable `RAILS_SERVE_STATIC_FILES` is present](https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt#L27). This way it's less surprising. - whiny_nils: Removed. It's [not available since Rails 4.1](https://guides.rubyonrails.org/4_1_release_notes.html#railties-removals). - action_controller.allow_forgery_protection: Set to true to mimic production. - action_controller.default_protect_from_forgery: Set to true to mimic production. - action_controller.perform_caching: Set to true to mimic production. - active_support.deprecation: Remove duplicated entry. - action_mailer.delivery_job: Removed because `load_defaults` take care of it. - storage_path: Removed. It wasn't a Rails setting, but used as a convenience. It was confusing. - action_controller.include_all_helpers: Removed as it's already the default. - log_level: Added. It already defaulted to `:debug`, but a real Rails app will default to `:info` in production. To make things less surprising let's be explicit. - action_mailer.perform_caching: Added to mimic production. - i18n.fallbacks: Added to mimic production. - active_record.dump_schema_after_migration: Added to mimic production and for better performance. - assets: No need to check whether it's a method on `config`. See #4035 --- core/lib/spree/testing_support/dummy_app.rb | 46 ++++++++++++--------- core/spec/rails_helper.rb | 2 +- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index a1f95b9dc45..607cd0fc048 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -47,35 +47,47 @@ def self.setup(gem_root:, lib_name:, auto_migrate: true) class Application < ::Rails::Application config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}") - config.eager_load = false + # Make the test environment more production-like: config.cache_classes = true - config.cache_store = :memory_store - config.serve_static_assets = true - config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } - config.whiny_nils = true - config.consider_all_requests_local = true config.action_controller.allow_forgery_protection = false config.action_controller.default_protect_from_forgery = false - config.action_controller.perform_caching = false + config.action_controller.perform_caching = true + config.action_mailer.perform_caching = false + config.i18n.fallbacks = true + + # Make debugging easier: + config.consider_all_requests_local = true config.action_dispatch.show_exceptions = false config.active_support.deprecation = :stderr + config.log_level = :debug + + # Improve test suite performance: + config.eager_load = false + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } + config.cache_store = :memory_store + + # We don't use a web server, so we let Rails serve assets. + config.public_file_server.enabled = true + + # We don't want to send email in the test environment. config.action_mailer.delivery_method = :test - config.active_support.deprecation = :stderr + + # No need to use credentials file in a test environment. config.secret_key_base = 'SECRET_TOKEN' - config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" if RAILS_6_OR_ABOVE + # Set the preview path within the dummy app: config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__) - config.action_mailer.show_previews = true - config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE - config.storage_path = Rails.root.join('tmp', 'storage') + config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE + config.active_record.dump_schema_after_migration = false + # Configure active storage to use storage within tmp folder unless ENV['DISABLE_ACTIVE_STORAGE'] initializer 'solidus.active_storage' do config.active_storage.service_configurations = { test: { service: 'Disk', - root: config.storage_path + root: Rails.root.join('tmp', 'storage') } } config.active_storage.service = :test @@ -96,12 +108,8 @@ class Application < ::Rails::Application config.paths['db/migrate'] = migration_dirs ActiveRecord::Migrator.migrations_paths = migration_dirs - config.action_controller.include_all_helpers = false - - if config.respond_to?(:assets) - config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__) - config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__) - end + config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__) + config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__) config.paths["config/database"] = File.expand_path('dummy_app/database.yml', __dir__) config.paths['app/views'] = File.expand_path('dummy_app/views', __dir__) diff --git a/core/spec/rails_helper.rb b/core/spec/rails_helper.rb index a296ff4e281..226c9633f5d 100644 --- a/core/spec/rails_helper.rb +++ b/core/spec/rails_helper.rb @@ -37,7 +37,7 @@ config.use_transactional_fixtures = true config.before :suite do - FileUtils.rm_rf(Rails.configuration.storage_path) + FileUtils.rm_rf(Rails.configuration.active_storage.service_configurations[:test][:root]) unless ENV['DISABLE_ACTIVE_STORAGE'] DatabaseCleaner.clean_with :truncation end