From 19eac9f58688461190bfd41a686f251b20fff66d Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Wed, 6 Nov 2024 09:22:13 +1030 Subject: [PATCH] Add CI Gemfiles for Rails 8.0 (#58) --- .github/workflows/rspec.yml | 4 + gemfiles/rails-7.2-propshaft.gemfile | 2 +- gemfiles/rails-7.2.gemfile | 2 +- gemfiles/rails-8.0-propshaft.gemfile | 17 +++ gemfiles/rails-8.0.gemfile | 17 +++ spec/dummy/config/environments/development.rb | 59 ++++----- spec/dummy/config/environments/production.rb | 117 ++++++------------ spec/dummy/config/environments/test.rb | 61 ++++----- 8 files changed, 124 insertions(+), 155 deletions(-) create mode 100644 gemfiles/rails-8.0-propshaft.gemfile create mode 100644 gemfiles/rails-8.0.gemfile diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index a58c402..3326023 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -28,6 +28,10 @@ jobs: ruby: '3.3' - gemfile: rails-7.2-propshaft ruby: '3.3' + - gemfile: rails-8.0 + ruby: '3.3' + - gemfile: rails-8.0-propshaft + ruby: '3.3' runs-on: ubuntu-latest env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile diff --git a/gemfiles/rails-7.2-propshaft.gemfile b/gemfiles/rails-7.2-propshaft.gemfile index 8502266..a3b7f78 100644 --- a/gemfiles/rails-7.2-propshaft.gemfile +++ b/gemfiles/rails-7.2-propshaft.gemfile @@ -7,7 +7,7 @@ group :test do gem "capybara" end -gem "rails", "~> 7.2.0.rc1" +gem "rails", "~> 7.2.0" gem "propshaft" gem "sqlite3", "~> 1.4" gem "devise" diff --git a/gemfiles/rails-7.2.gemfile b/gemfiles/rails-7.2.gemfile index bd86c96..ef656df 100644 --- a/gemfiles/rails-7.2.gemfile +++ b/gemfiles/rails-7.2.gemfile @@ -7,7 +7,7 @@ group :test do gem "capybara" end -gem "rails", "~> 7.2.0.rc1" +gem "rails", "~> 7.2.0" gem "sprockets-rails" gem "sqlite3", "~> 1.4" gem "devise" diff --git a/gemfiles/rails-8.0-propshaft.gemfile b/gemfiles/rails-8.0-propshaft.gemfile new file mode 100644 index 0000000..f113d9d --- /dev/null +++ b/gemfiles/rails-8.0-propshaft.gemfile @@ -0,0 +1,17 @@ +source 'https://rubygems.org' + +group :test do + gem "rspec-rails" + + gem "coveralls_reborn", require: false + gem "capybara" +end + +gem "rails", github: "rails/rails", branch: "8-0-stable" +gem "propshaft" +gem "sqlite3" +gem "devise" + +gem "trestle", github: "TrestleAdmin/trestle" + +gemspec path: "../" diff --git a/gemfiles/rails-8.0.gemfile b/gemfiles/rails-8.0.gemfile new file mode 100644 index 0000000..8ebe9e8 --- /dev/null +++ b/gemfiles/rails-8.0.gemfile @@ -0,0 +1,17 @@ +source 'https://rubygems.org' + +group :test do + gem "rspec-rails" + + gem "coveralls_reborn", require: false + gem "capybara" +end + +gem "rails", github: "rails/rails", branch: "8-0-stable" +gem "sprockets-rails" +gem "sqlite3" +gem "devise" + +gem "trestle", github: "TrestleAdmin/trestle" + +gemspec path: "../" diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index c5c94de..67b8af3 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -1,10 +1,10 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + # Make code changes take effect immediately without server restart. + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -12,29 +12,21 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable/disable caching. By default caching is disabled. - # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + # Enable server timing. + config.server_timing = true + + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. + if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true - - config.cache_store = :memory_store - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" - } + config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false - - config.cache_store = :null_store end - # 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 - - # config.action_mailer.perform_caching = false + # Change to :null_store to avoid any caching. + config.cache_store = :memory_store # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -45,18 +37,21 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # 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 - - # Suppress logger output for asset requests. - config.assets.quiet = true + # Append comments with runtime information tags to SQL queries in logs. + if config.active_record.respond_to?(:query_log_tags_enabled=) + config.active_record.query_log_tags_enabled = true + end # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # config.i18n.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 + # Annotate rendered view with file names. + if config.respond_to?(:annotate_rendered_view_with_filenames=) + config.action_view.annotate_rendered_view_with_filenames = true + end + + # Raise error when a before_action's only/except options reference missing actions. + if ActionController::Base.respond_to?(:raise_on_missing_callback_actions) + config.action_controller.raise_on_missing_callback_actions = true + end end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index f729adc..4ea4599 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -1,112 +1,67 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both threaded web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). config.eager_load = true - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] - # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). - # config.require_master_key = true - - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + # Full error reports are disabled. + config.consider_all_requests_local = false - # Compress CSS using a preprocessor. - # config.assets.css_compressor = :sass + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' - - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # 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 - - # Mount Action Cable outside main process or domain. - # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } - # Prepend all log lines with the following tags. + # Log to STDOUT with the current request id as a default log tag. config.log_tags = [ :request_id ] + config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) - # Use a different cache store in production. - # config.cache_store = :mem_cache_store + # Change to "debug" to log everything (including potentially personally-identifiable information!) + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") - # Use a real queuing backend for Active Job (and separate queues per environment). - # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "dummy_production" + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = "/up" - # config.action_mailer.perform_caching = false + # Don't log any deprecations. + config.active_support.report_deprecations = false - # 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 + # Replace the default in-process memory cache store with a durable alternative. + # config.cache_store = :mem_cache_store # 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 - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - - # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. + # 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 + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 5ddfce0..99b71ad 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -1,64 +1,45 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false - if ENV["CI"] || ENV["TEST_EAGER_LOAD"] - config.eager_load = true - else - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false - end + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. if config.respond_to?(:public_file_server) config.public_file_server.enabled = true - config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=3600' - } + config.public_file_server.headers = { "cache-control" => "public, max-age=3600" } else config.serve_static_files = true config.static_cache_control = 'public, max-age=3600' end - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = :all + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable # 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 - - # config.action_mailer.perform_caching = false - - # 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 - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - unless ENV["CI"] - config.assets.digest = false - config.assets.debug = true - end - # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true end