From 789c2810cc9cea6ac82af3aa9afd67a46cb1cc75 Mon Sep 17 00:00:00 2001 From: elasticspoon Date: Tue, 10 Sep 2024 16:29:07 -0400 Subject: [PATCH] fix: accessible concern Some change in rails 7.2 made drawing of routes in an RSpec test not play well with config.eager_load = true. Thus, in CI these tests would fail. Changed the way routes were dynamically added to fix. --- .../new_framework_defaults_7_2.rb | 70 ------------------- spec/controllers/concerns/accessible_spec.rb | 12 ++-- 2 files changed, 8 insertions(+), 74 deletions(-) delete mode 100644 config/initializers/new_framework_defaults_7_2.rb diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb deleted file mode 100644 index b549c4a258..0000000000 --- a/config/initializers/new_framework_defaults_7_2.rb +++ /dev/null @@ -1,70 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file eases your Rails 7.2 framework defaults upgrade. -# -# Uncomment each configuration one by one to switch to the new default. -# Once your application is ready to run with all new defaults, you can remove -# this file and set the `config.load_defaults` to `7.2`. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. -# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html - -### -# Controls whether Active Job's `#perform_later` and similar methods automatically defer -# the job queuing to after the current Active Record transaction is committed. -# -# Example: -# Topic.transaction do -# topic = Topic.create(...) -# NewTopicNotificationJob.perform_later(topic) -# end -# -# In this example, if the configuration is set to `:never`, the job will -# be enqueued immediately, even though the `Topic` hasn't been committed yet. -# Because of this, if the job is picked up almost immediately, or if the -# transaction doesn't succeed for some reason, the job will fail to find this -# topic in the database. -# -# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter -# will define the behaviour. -# -# Note: Active Job backends can disable this feature. This is generally done by -# backends that use the same database as Active Record as a queue, hence they -# don't need this feature. -#++ -# Rails.application.config.active_job.enqueue_after_transaction_commit = :default - -### -# Adds image/webp to the list of content types Active Storage considers as an image -# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. -# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support -# WebP. Requires imagemagick/libvips built with WebP support. -#++ -# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] - -### -# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError -# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp -# associated with the current time. This is done to prevent forward-dating of migration files, which can -# impact migration generation and other migration commands. -# -# Applications with existing timestamped migrations that do not adhere to the -# expected format can disable validation by setting this config to `false`. -#++ -# Rails.application.config.active_record.validate_migration_timestamps = true - -### -# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries. -# -# Example: -# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date -# -# This query used to return a `String`. -#++ -# Rails.application.config.active_record.postgresql_adapter_decode_dates = true - -### -# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are -# deploying to a memory constrained environment you may want to set this to `false`. -#++ -# Rails.application.config.yjit = true diff --git a/spec/controllers/concerns/accessible_spec.rb b/spec/controllers/concerns/accessible_spec.rb index 8c243e8e12..9bb474233c 100644 --- a/spec/controllers/concerns/accessible_spec.rb +++ b/spec/controllers/concerns/accessible_spec.rb @@ -17,15 +17,19 @@ def no_session_action let(:volunteer) { create(:volunteer) } context "Authenticated user" do - before do - Rails.application.reload_routes! - Rails.application.routes.disable_clear_and_finalize = true + around do |example| Rails.application.routes.draw do get :action, to: "mock#action" get :no_session_action, to: "mock#no_session_action" + + get :mock_admin, to: "admin#mock", as: :authenticated_all_casa_admin_root + get :mock_user, to: "user#mock", as: :authenticated_user_root end + + example.run + + Rails.application.reload_routes! end - after { Rails.application.routes_reloader.reload! } it "should redirect to authenticated casa admin root path" do allow(controller).to receive(:authenticate_user!).and_return(true)