Skip to content

Commit

Permalink
Fix test deprecation warnings (#1018)
Browse files Browse the repository at this point in the history
* 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 <csara@thoughtbot.com>
  • Loading branch information
louis-antonopoulos and sej3506 authored Aug 9, 2024
1 parent 0398217 commit 87bca53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions spec/dummy/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions spec/generators/clearance/install/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 87bca53

Please sign in to comment.