From 28d9e38fe51eba51cc9fdf46acf95570d16a1666 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 13 Oct 2023 15:33:05 +0200 Subject: [PATCH] Upgrade to Rails 7.1 and apply new framework defaults * Remove deprecated options from environments * Remove deprecation warnings for upcoming Rails 7.2 * Dump schema with new defaults * Remove outdated (and erroneous) data attribute in view * Resolve a `NoMethodError` for seeds_spec.rb --- Gemfile | 4 +- Gemfile.lock | 184 +++++++++++------- app/controllers/exercises_controller.rb | 6 +- bin/rails | 2 + bin/setup | 6 +- config/application.rb | 18 +- config/environments/development.rb | 8 +- config/environments/production.rb | 52 ++--- config/environments/test.rb | 17 +- .../initializers/content_security_policy.rb | 6 +- .../initializers/filter_parameter_logging.rb | 6 +- config/initializers/monkey_patches.rb | 8 + config/initializers/permissions_policy.rb | 7 +- db/schema.rb | 2 +- spec/controllers/exercises_controller_spec.rb | 2 +- spec/db/seeds_spec.rb | 5 + 16 files changed, 198 insertions(+), 135 deletions(-) diff --git a/Gemfile b/Gemfile index cea2e5c7..9d36d962 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,9 @@ gem 'proformaxml', '1.0.0' gem 'prometheus_exporter' gem 'puma' gem 'pundit' -gem 'rails', '~> 7.0.8' +# TODO: Temporary switch to Rails 7.1 branch until the next release. +# See https://github.com/rails/rails/pull/49778 +gem 'rails', github: 'rails/rails', branch: '7-1-stable' gem 'rails_admin', '< 4.0.0' gem 'rails-i18n' gem 'rails-timeago' diff --git a/Gemfile.lock b/Gemfile.lock index 1ebb423a..44418b6e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,75 +1,112 @@ -GEM - remote: https://rubygems.org/ +GIT + remote: https://github.com/rails/rails.git + revision: 68c4dd34519b315cee8d4056724148a77b93a695 + branch: 7-1-stable specs: - actioncable (7.0.8) - actionpack (= 7.0.8) - activesupport (= 7.0.8) + actioncable (7.1.1) + actionpack (= 7.1.1) + activesupport (= 7.1.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.8) - actionpack (= 7.0.8) - activejob (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + zeitwerk (~> 2.6) + actionmailbox (7.1.1) + actionpack (= 7.1.1) + activejob (= 7.1.1) + activerecord (= 7.1.1) + activestorage (= 7.1.1) + activesupport (= 7.1.1) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.8) - actionpack (= 7.0.8) - actionview (= 7.0.8) - activejob (= 7.0.8) - activesupport (= 7.0.8) + actionmailer (7.1.1) + actionpack (= 7.1.1) + actionview (= 7.1.1) + activejob (= 7.1.1) + activesupport (= 7.1.1) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.8) - actionview (= 7.0.8) - activesupport (= 7.0.8) - rack (~> 2.0, >= 2.2.4) + rails-dom-testing (~> 2.2) + actionpack (7.1.1) + actionview (= 7.1.1) + activesupport (= 7.1.1) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.8) - actionpack (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.1) + actionpack (= 7.1.1) + activerecord (= 7.1.1) + activestorage (= 7.1.1) + activesupport (= 7.1.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.8) - activesupport (= 7.0.8) + actionview (7.1.1) + activesupport (= 7.1.1) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.8) - activesupport (= 7.0.8) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.1) + activesupport (= 7.1.1) globalid (>= 0.3.6) - activemodel (7.0.8) - activesupport (= 7.0.8) + activemodel (7.1.1) + activesupport (= 7.1.1) + activerecord (7.1.1) + activemodel (= 7.1.1) + activesupport (= 7.1.1) + timeout (>= 0.4.0) + activestorage (7.1.1) + actionpack (= 7.1.1) + activejob (= 7.1.1) + activerecord (= 7.1.1) + activesupport (= 7.1.1) + marcel (~> 1.0) + activesupport (7.1.1) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + rails (7.1.1) + actioncable (= 7.1.1) + actionmailbox (= 7.1.1) + actionmailer (= 7.1.1) + actionpack (= 7.1.1) + actiontext (= 7.1.1) + actionview (= 7.1.1) + activejob (= 7.1.1) + activemodel (= 7.1.1) + activerecord (= 7.1.1) + activestorage (= 7.1.1) + activesupport (= 7.1.1) + bundler (>= 1.15.0) + railties (= 7.1.1) + railties (7.1.1) + actionpack (= 7.1.1) + activesupport (= 7.1.1) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + +GEM + remote: https://rubygems.org/ + specs: activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (7.0.8) - activemodel (= 7.0.8) - activesupport (= 7.0.8) - activestorage (7.0.8) - actionpack (= 7.0.8) - activejob (= 7.0.8) - activerecord (= 7.0.8) - activesupport (= 7.0.8) - marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.8) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) amq-protocol (2.3.2) @@ -80,6 +117,7 @@ GEM erubi (>= 1.0.0) rack (>= 0.9.0) rouge (>= 1.0.0) + bigdecimal (3.1.4) bindex (0.8.1) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) @@ -131,6 +169,8 @@ GEM docker-api (2.2.0) excon (>= 0.47.0) multi_json + drb (2.1.1) + ruby2_keywords erubi (1.12.0) eventmachine (1.2.7) excon (0.104.0) @@ -175,6 +215,10 @@ GEM oauth (>= 0.4.5) rexml influxdb (0.8.1) + io-console (0.6.0) + irb (1.8.3) + rdoc + reline (>= 0.3.8) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) @@ -232,6 +276,7 @@ GEM msgpack (1.7.2) multi_json (1.15.0) multi_xml (0.6.0) + mutex_m (0.1.2) nested_form (0.3.2) net-http-persistent (4.0.2) connection_pool (~> 2.2) @@ -284,6 +329,8 @@ GEM pry (>= 0.13, < 0.15) pry-rails (0.3.9) pry (>= 0.10.4) + psych (5.1.1.1) + stringio public_suffix (5.0.3) puma (6.4.0) nio4r (~> 2.0) @@ -295,22 +342,13 @@ GEM rack (>= 1.2.0) rack-proxy (0.7.7) rack + rack-session (1.0.1) + rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.8) - actioncable (= 7.0.8) - actionmailbox (= 7.0.8) - actionmailer (= 7.0.8) - actionpack (= 7.0.8) - actiontext (= 7.0.8) - actionview (= 7.0.8) - activejob (= 7.0.8) - activemodel (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) - bundler (>= 1.15.0) - railties (= 7.0.8) + rackup (1.0.0) + rack (< 3) + webrick rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -334,13 +372,6 @@ GEM nested_form (~> 0.3) rails (>= 6.0, < 8) turbo-rails (~> 1.0) - railties (7.0.8) - actionpack (= 7.0.8) - activesupport (= 7.0.8) - method_source - rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) ransack (4.1.0) @@ -351,7 +382,11 @@ GEM rb-inotify (0.10.1) ffi (~> 1.0) rbtree (0.4.6) + rdoc (6.5.0) + psych (>= 4.0.0) regexp_parser (2.8.2) + reline (0.3.9) + io-console (~> 0.5) rexml (3.2.6) rouge (4.2.0) rspec-collection_matchers (1.2.1) @@ -470,6 +505,7 @@ GEM sprockets (>= 3.0.0) ssrf_filter (1.1.2) stackprof (0.2.25) + stringio (3.0.8) telegraf (2.1.1) influxdb temple (0.10.3) @@ -565,7 +601,7 @@ DEPENDENCIES puma pundit rack-mini-profiler - rails (~> 7.0.8) + rails! rails-controller-testing rails-i18n rails-timeago diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 86f4e3a2..31aa9ffd 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -10,8 +10,8 @@ class ExercisesController < ApplicationController before_action :handle_file_uploads, only: %i[create update] before_action :set_execution_environments, only: %i[index create edit new update] before_action :set_exercise_and_authorize, - only: MEMBER_ACTIONS + %i[clone implement working_times intervention search run statistics submit reload feedback - requests_for_comments study_group_dashboard export_external_check export_external_confirm + only: MEMBER_ACTIONS + %i[clone implement working_times intervention statistics submit reload feedback + study_group_dashboard export_external_check export_external_confirm external_user_statistics] before_action :collect_set_and_unset_exercise_tags, only: MEMBER_ACTIONS before_action :set_external_user_and_authorize, only: [:external_user_statistics] @@ -43,7 +43,7 @@ class ExercisesController < ApplicationController authorize! @exercises = params[:exercises].values.map do |exercise_params| exercise = Exercise.find(exercise_params.delete(:id)) - exercise.update(exercise_params) + exercise.update(exercise_params.permit(:public)) exercise end render(json: {exercises: @exercises}) diff --git a/bin/rails b/bin/rails index 6fb4e405..da601805 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path('../config/application', __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/bin/setup b/bin/setup index 90700ac4..bc4c78e2 100755 --- a/bin/setup +++ b/bin/setup @@ -1,11 +1,13 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require "fileutils" # path to your application root. APP_ROOT = File.expand_path('..', __dir__) -def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") +def system!(*) + system(*, exception: true) end FileUtils.chdir APP_ROOT do diff --git a/config/application.rb b/config/application.rb index 6117d1be..bb72267f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,12 @@ require_relative '../lib/middleware/web_socket_sentry_headers' module CodeOcean class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.0 + config.load_defaults 7.1 + + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks templates generators middleware]) # Configuration for the application, engines, and railties goes here. # @@ -30,17 +35,6 @@ module CodeOcean # config.i18n.default_locale = :de config.i18n.available_locales = %i[de en] - extra_paths = [ - Rails.root.join('lib'), - ] - - # Add generators, they don't have a module structure that matches their directory structure. - extra_paths << Rails.root.join('lib/generators') - - config.add_autoload_paths_to_load_path = false - config.autoload_paths += extra_paths - config.eager_load_paths += extra_paths - config.relative_url_root = ENV.fetch('RAILS_RELATIVE_URL_ROOT', '/').to_s config.action_cable.mount_path = "#{ENV.fetch('RAILS_RELATIVE_URL_ROOT', '')}/cable" diff --git a/config/environments/development.rb b/config/environments/development.rb index b82b1393..fc8bc03a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -11,7 +11,7 @@ Rails.application.configure do # In the development environment your application's code is reloaded any time # it changes. 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 + config.enable_reloading = true # Eager load code for prometheus exporter config.eager_load = true @@ -61,6 +61,9 @@ Rails.application.configure do # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_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. @@ -85,4 +88,7 @@ Rails.application.configure do # 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 diff --git a/config/environments/production.rb b/config/environments/production.rb index 8b828d7d..1706d7ba 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -6,7 +6,7 @@ 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 @@ -19,10 +19,9 @@ Rails.application.configure do 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). + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true - config.read_encrypted_secrets = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. @@ -52,16 +51,28 @@ Rails.application.configure do # 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. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + 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.ssl_options = {hsts: {preload: true}} - # Include generic and useful information about system operation, but avoid logging too much - # information to avoid inadvertent exposure of personally identifiable information (PII). - config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info').to_sym + if ENV['RAILS_LOG_TO_STDOUT'].present? + # Log to STDOUT by default + config.logger = ActiveSupport::Logger.new($stdout) + .tap {|logger| logger.formatter = Logger::Formatter.new } + .then {|logger| ActiveSupport::TaggedLogging.new(logger) } + end # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid, :request_id ] + config.log_tags = [:request_id] + + # Info include generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -80,22 +91,17 @@ Rails.application.configure do # 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 + # Don't log any deprecations. + config.active_support.report_deprecations = false # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + # 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` + # ] + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 7f29399a..d7f38f07 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -10,13 +10,13 @@ require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # Turn false under Spring and add config.action_view.cache_template_loading = true. - config.cache_classes = true + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false - # Eager loading loads your whole application. When running a single test locally, - # this probably isn't necessary. It's a good idea to do in a continuous integration - # system, or in some way before deploying your code. - # Eager load code for prometheus exporter + # 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 = true # Configure public file server for tests with Cache-Control for performance. @@ -31,7 +31,7 @@ Rails.application.configure do config.cache_store = :memory_store # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false @@ -63,4 +63,7 @@ Rails.application.configure do # Annotate rendered view with file names. config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions + config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 361a1d6e..8d14018d 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -68,10 +68,10 @@ Rails.application.configure do CSP.apply_sentry_settings_for policy if SentryJavascript.active? end - # Generate session nonces for permitted importmap and inline scripts + # Generate session nonces for permitted importmap, inline scripts, and inline styles. # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } - # config.content_security_policy_nonce_directives = %w[script-src] + # config.content_security_policy_nonce_directives = %w[script-src style-src] - # Report violations without enforcing the policy + # Report violations without enforcing the policy. # config.content_security_policy_report_only = true end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 3df77c5b..c416e6a6 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -2,9 +2,9 @@ # Be sure to restart your server when you modify this file. -# Configure parameters to be filtered from the log file. Use this to limit dissemination of -# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported -# notations and behaviors. +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += %i[ passw secret token _key crypt salt certificate otp ssn ] diff --git a/config/initializers/monkey_patches.rb b/config/initializers/monkey_patches.rb index 61c405d5..e9136560 100644 --- a/config/initializers/monkey_patches.rb +++ b/config/initializers/monkey_patches.rb @@ -17,3 +17,11 @@ module WillPaginate end end end + +# Temporary required for Rails 7.1+ and Slim 5.1+. +# TODO: No GitHub issue yet +module ActionView + class OutputBuffer + alias + concat + end +end diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 57e689ba..a174e411 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true +# Be sure to restart your server when you modify this file. + # Define an application-wide HTTP permissions policy. For further -# information see https://developers.google.com/web/updates/2018/06/feature-policy +# information see: https://developers.google.com/web/updates/2018/06/feature-policy # TODO: Feature-Policy has been renamed to Permissions-Policy. The Permissions-Policy is # not yet supported by Rails (even though the new name is already used for the method) Rails.application.config.permissions_policy do |policy| @@ -19,8 +21,5 @@ Rails.application.config.permissions_policy do |policy| policy.payment :none policy.picture_in_picture :none # The `speaker` directive is used for selection of non-default audio output devices - policy.speaker :none policy.usb :none - policy.vibrate :none - policy.vr :none end diff --git a/db/schema.rb b/db/schema.rb index 757c91f5..29b6abbb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_13_194635) do +ActiveRecord::Schema[7.1].define(version: 2023_10_13_194635) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "pgcrypto" diff --git a/spec/controllers/exercises_controller_spec.rb b/spec/controllers/exercises_controller_spec.rb index f06b4e40..d591a422 100644 --- a/spec/controllers/exercises_controller_spec.rb +++ b/spec/controllers/exercises_controller_spec.rb @@ -14,7 +14,7 @@ RSpec.describe ExercisesController do end describe 'PUT #batch_update' do - let(:attributes) { {public: 'true'} } + let(:attributes) { ActionController::Parameters.new(public: 'true').permit! } let(:perform_request) { proc { put :batch_update, params: {exercises: {0 => attributes.merge(id: exercise.id)}} } } before { perform_request.call } diff --git a/spec/db/seeds_spec.rb b/spec/db/seeds_spec.rb index acfd95cd..7a7b20e4 100644 --- a/spec/db/seeds_spec.rb +++ b/spec/db/seeds_spec.rb @@ -8,6 +8,11 @@ RSpec.describe 'seeds' do before do CodeOcean::Application.load_tasks + # We need to migrate the test database before seeding + # Otherwise, Rails 7.1+ will throw an `NoMethodError`: `pending_migrations.any?` + # See ActiveRecord gem, file `lib/active_record/railties/databases.rake` + Rake::Task['db:migrate'].invoke + # We want to execute the seeds for the dev environment against the test database # rubocop:disable Rails/Inquiry allow(Rails).to receive(:env) { 'development'.inquiry }