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

Handle fixtures with no associated model #1921

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

vinistock
Copy link
Member

Motivation

Some projects use YAML files inside the test/fixtures directory to represent arbitrary data that is not associated to any specific model.

This is a valid use case that Rails allows, but our DSL compiler fails when any fixtures like that are present because it assumes there will be a model.

Implementation

There are essentially two parts to the fix:

  1. Started rescuing the fixture formatting error that gets raised when no model is associated with it and we invoke fh.model_class. We don't want generation to stop because we found one of those fixtures
  2. In addition to not crashing, we also don't want to generate RBI methods for fixtures that don't have an associated model or that contain invalid formatting. So we need to remove them from the list of methods to be created. I started memoizing method_names so that we can remove invalid fixtures

Tests

Added a test that reproduces the crash.

@vinistock vinistock self-assigned this Jun 13, 2024
@vinistock vinistock requested a review from a team as a code owner June 13, 2024 15:27
@vinistock vinistock force-pushed the vs/handle_fixtures_with_no_model branch from 77a4774 to 3d13857 Compare June 13, 2024 17:39
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Thanks!

@vinistock vinistock force-pushed the vs/handle_fixtures_with_no_model branch from 3d13857 to f5c6053 Compare June 13, 2024 19:38
@vinistock
Copy link
Member Author

The build failures are unrelated and are happening on main too. I suspect it's the latest Bundler version since we got a lot of new bundler related failures, which we are trying to investigate in #1922.

I'll go ahead and merge this anyway since the errors are unrelated.

@vinistock vinistock merged commit 9a65f59 into main Jun 14, 2024
16 of 30 checks passed
@vinistock vinistock deleted the vs/handle_fixtures_with_no_model branch June 14, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants