From 87bca53c2adb0812764f32935a4bac81a67d8f2c Mon Sep 17 00:00:00 2001 From: louis-antonopoulos Date: Fri, 9 Aug 2024 10:45:27 -0400 Subject: [PATCH] Fix test deprecation warnings (#1018) * Use Pathname.new in install_generator_spec Fix DEPRECATION WARNING: The `exist` matcher overrides one built-in by RSpec; use `expect(Pathname.new(path)).to exist` instead * Disable config.active_record.legacy_connection_handling Fix DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set `legacy_connection_handling` to `false` in your application. * Add #get_migration helper Using `Pathname.new` in tests results in a Hound error because of line length. * Only use legacy_connection_handling false for Rails < 7.1 When using the 7.1 gemfile, we get this complaint: "The `legacy_connection_handling` setter was deprecated in 7.0 and removed in 7.1, but is still defined in your configuration. Please remove this call as it no longer has any effect." This change also sets legacy_connection_handling for Rails versions before 7.1. --------- Co-authored-by: Sara Jackson --- spec/dummy/application.rb | 3 +++ .../clearance/install/install_generator_spec.rb | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/spec/dummy/application.rb b/spec/dummy/application.rb index 03e56572..884e27bc 100644 --- a/spec/dummy/application.rb +++ b/spec/dummy/application.rb @@ -9,6 +9,9 @@ class Application < Rails::Application config.action_controller.perform_caching = false config.action_mailer.default_url_options = { host: "dummy.example.com" } config.action_mailer.delivery_method = :test + if Rails.version.match?(/(6.1|7.0)/) + config.active_record.legacy_connection_handling = false + end config.active_support.deprecation = :stderr config.eager_load = false diff --git a/spec/generators/clearance/install/install_generator_spec.rb b/spec/generators/clearance/install/install_generator_spec.rb index 83ec4b6a..8c50a894 100644 --- a/spec/generators/clearance/install/install_generator_spec.rb +++ b/spec/generators/clearance/install/install_generator_spec.rb @@ -2,6 +2,10 @@ require "generators/clearance/install/install_generator" describe Clearance::Generators::InstallGenerator, :generator do + def get_migration(path) + Pathname.new(migration_file(path)) + end + describe "initializer" do it "is copied to the application" do provide_existing_application_controller @@ -66,7 +70,7 @@ table_does_not_exist(:users) run_generator - migration = migration_file("db/migrate/create_users.rb") + migration = get_migration("db/migrate/create_users.rb") expect(migration).to exist expect(migration).to have_correct_syntax @@ -88,7 +92,7 @@ table_does_not_exist(:users) run_generator - migration = migration_file("db/migrate/create_users.rb") + migration = get_migration("db/migrate/create_users.rb") expect(migration).to exist expect(migration).to have_correct_syntax @@ -102,8 +106,8 @@ provide_existing_application_controller run_generator - create_migration = migration_file("db/migrate/create_users.rb") - add_migration = migration_file("db/migrate/add_clearance_to_users.rb") + create_migration = get_migration("db/migrate/create_users.rb") + add_migration = get_migration("db/migrate/add_clearance_to_users.rb") expect(create_migration).not_to exist expect(add_migration).not_to exist @@ -126,7 +130,7 @@ and_return(existing_indexes) run_generator - migration = migration_file("db/migrate/add_clearance_to_users.rb") + migration = get_migration("db/migrate/add_clearance_to_users.rb") expect(migration).to exist expect(migration).to have_correct_syntax