From 42e0e7e18dba6d9af7a922524779062f8c69d635 Mon Sep 17 00:00:00 2001 From: Louis Antonopoulos Date: Wed, 8 May 2024 11:51:05 -0400 Subject: [PATCH 1/4] 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 --- .../clearance/install/install_generator_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/generators/clearance/install/install_generator_spec.rb b/spec/generators/clearance/install/install_generator_spec.rb index 83ec4b6a..a82b9772 100644 --- a/spec/generators/clearance/install/install_generator_spec.rb +++ b/spec/generators/clearance/install/install_generator_spec.rb @@ -66,7 +66,7 @@ table_does_not_exist(:users) run_generator - migration = migration_file("db/migrate/create_users.rb") + migration = Pathname.new(migration_file("db/migrate/create_users.rb")) expect(migration).to exist expect(migration).to have_correct_syntax @@ -88,7 +88,7 @@ table_does_not_exist(:users) run_generator - migration = migration_file("db/migrate/create_users.rb") + migration = Pathname.new(migration_file("db/migrate/create_users.rb")) expect(migration).to exist expect(migration).to have_correct_syntax @@ -102,8 +102,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 = Pathname.new(migration_file("db/migrate/create_users.rb")) + add_migration = Pathname.new(migration_file("db/migrate/add_clearance_to_users.rb")) expect(create_migration).not_to exist expect(add_migration).not_to exist @@ -126,7 +126,7 @@ and_return(existing_indexes) run_generator - migration = migration_file("db/migrate/add_clearance_to_users.rb") + migration = Pathname.new(migration_file("db/migrate/add_clearance_to_users.rb")) expect(migration).to exist expect(migration).to have_correct_syntax From 99ae3c1598d886c157b3af2c144940fe6a2f76ca Mon Sep 17 00:00:00 2001 From: Louis Antonopoulos Date: Wed, 8 May 2024 11:59:27 -0400 Subject: [PATCH 2/4] 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. --- spec/dummy/application.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/dummy/application.rb b/spec/dummy/application.rb index 03e56572..d6678c7c 100644 --- a/spec/dummy/application.rb +++ b/spec/dummy/application.rb @@ -9,6 +9,7 @@ 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 + config.active_record.legacy_connection_handling = false config.active_support.deprecation = :stderr config.eager_load = false From 319a081f5a0cc57109a01b077fdb7847c4f53608 Mon Sep 17 00:00:00 2001 From: Louis Antonopoulos Date: Wed, 8 May 2024 13:22:55 -0400 Subject: [PATCH 3/4] Add #get_migration helper Using `Pathname.new` in tests results in a Hound error because of line length. --- .../clearance/install/install_generator_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/generators/clearance/install/install_generator_spec.rb b/spec/generators/clearance/install/install_generator_spec.rb index a82b9772..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 = Pathname.new(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 = Pathname.new(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 = Pathname.new(migration_file("db/migrate/create_users.rb")) - add_migration = Pathname.new(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 = Pathname.new(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 From 4854a87b31dc3e86652321afba8f90a839537c54 Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Fri, 9 Aug 2024 09:46:43 -0400 Subject: [PATCH 4/4] 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. --- spec/dummy/application.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/dummy/application.rb b/spec/dummy/application.rb index d6678c7c..884e27bc 100644 --- a/spec/dummy/application.rb +++ b/spec/dummy/application.rb @@ -9,7 +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 - config.active_record.legacy_connection_handling = false + 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