Skip to content

Commit

Permalink
Update defaults in dummy application
Browse files Browse the repository at this point in the history
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 solidusio#4035
  • Loading branch information
waiting-for-dev committed May 7, 2021
1 parent 7cd6c4d commit 077729e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
50 changes: 22 additions & 28 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,33 @@ 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
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_dispatch.show_exceptions = false
config.active_support.deprecation = :stderr
config.action_mailer.delivery_method = :test
config.active_support.deprecation = :stderr
config.secret_key_base = 'SECRET_TOKEN'

config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" if RAILS_6_OR_ABOVE
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
config.action_mailer.show_previews = true
config.cache_classes = true # mimic production
config.eager_load = false # suite performance
config.public_file_server.enabled = true # as we don't use a web server, let Rails serve them
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # suite performance
config.cache_store = :memory_store # suite performance
config.consider_all_requests_local = true # makes debugging easier
config.action_controller.allow_forgery_protection = false # mimic production
config.action_controller.default_protect_from_forgery = false # mimic production
config.action_controller.perform_caching = true # mimim production
config.action_dispatch.show_exceptions = false # makes debugging easier
config.active_support.deprecation = :stderr # makes debugging easier
config.log_level = :debug # makes debugging easier
config.action_mailer.delivery_method = :test # don't try to send mails
config.secret_key_base = 'SECRET_TOKEN' # no need to use credentials file
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__) # preview path within the dummy app
config.action_mailer.perform_caching = false # mimic production
config.i18n.fallbacks = true # mimic production
config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE
config.active_record.dump_schema_after_migration = false

config.storage_path = Rails.root.join('tmp', 'storage')

# 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
Expand All @@ -96,12 +94,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__)
Expand Down
2 changes: 1 addition & 1 deletion core/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
DatabaseCleaner.clean_with :truncation
end

Expand Down

0 comments on commit 077729e

Please sign in to comment.