Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rails 7.2 in test suite #252

Merged
merged 10 commits into from
Dec 9, 2024
Merged

Support Rails 7.2 in test suite #252

merged 10 commits into from
Dec 9, 2024

Conversation

atomaka
Copy link
Contributor

@atomaka atomaka commented Dec 4, 2024

What is the purpose of this pull request?

What changes did you make? (overview)

Updates the test suite to run the latest Rails 7.2 minor version and corrects test suite issues to allow it to pass.

Is there anything you'd like reviewers to focus on?

  • Replaced rspec matcher with a new customer matcher, be_a_file
  • Rails::VERSION::MAJOR for Rails version compatibility

Checklist

  • I've added tests for this change
  • I've added a Changelog entry
  • I've updated a documentation (Readme)

@@ -0,0 +1,9 @@
RSpec::Matchers.define :exist do |*expected|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea I have in mind is to add String#exists? (only in tests) and rely on the built-in RSpec matcher. This way, we won't need to refactor all the usages.

Or, we can add a custom matcher, say, be_a_file:

expect("some_path.rb").to be_a_file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I favored not patching String but can if you'd prefer a smaller diff. Alternatively, I can pull that change to an independent PR if you'd rather.

@atomaka atomaka changed the title Support Rails 7.2 Support Rails 7.2 in test suite Dec 4, 2024
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

rails_version = '~> 7.0.0'
rails_version = '~> 7.0'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we need to split this gemfile into two, one for ~> 7.0.0 series and one for ~> 7.0, since the differences are significant between 7.0 and 7.2

Copy link
Contributor Author

@atomaka atomaka Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, I'd think it unnecessary but since Logidze has additional exposure from using non-public APIs from Rails, it's a good idea!

@@ -39,6 +39,6 @@
config.append_after(:each, db: true) do |ex|
ActiveRecord::Base.connection.rollback_transaction

raise "Migrations are pending: #{ex.metadata[:location]}" if ActiveRecord::Base.connection.migration_context.needs_migration?
raise "Migrations are pending: #{ex.metadata[:location]}" if ActiveRecord::Base.connection_pool.migration_context.needs_migration?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this change is causing test failures on CI. Could you please take a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. This does pass locally with 7.2.2 and Ruby 3.3.6. Additionally, this isn't a backward compatible change so I'll fix that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still investigating this piece.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last two commits should address this. See https://github.com/atomaka/logidze/actions/runs/12209635303/job/34064707411 (from atomaka#2) for a passing test suite.

Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR! Added some suggestions regarding ammeter tests. (And let's figure out the CI failures)

ActiveRecord::MigrationContext was made a public API in
rails/rails@eb09f59
so let's prefer that when it's available.  Prefered check might be
ActiveRecord.const_defined?(:MigrationContext) but MigrationContext
existed as a private API with a different interface in Rails 6.
Comment on lines +42 to +43
migration_context = if Rails::VERSION::MAJOR >= 7
ActiveRecord::MigrationContext.new("db/migrate")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActiveRecord::MigrationContext was made a public API in rails/rails@eb09f59 released with Rails 7. Prior to that, it was a non-public API (with a different interface)

@atomaka atomaka requested a review from palkan December 7, 2024 03:57
@palkan palkan merged commit 140710b into palkan:master Dec 9, 2024
15 checks passed
@palkan
Copy link
Owner

palkan commented Dec 9, 2024

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants