-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Prevent "Unable to autoload constant" error in tests #5422
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
350896c
to
dda0761
Compare
When running these tests, under certain conditions, we get a warning followed by an error: ``` activesupport-6.1.7.7/lib/active_support/dependencies.rb:502: warning: already initialized constant ActiveStorage::Representations activesupport-6.1.7.7/lib/active_support/dependencies.rb:502: warning: previous definition of Representations was here Failure/Error: raise LoadError, "Unable to autoload constant '#{qualified_name}', expected #{file_path} to define it" LoadError: Unable to autoload constant ActiveStorage::Representations::RedirectController, expected activestorage-6.1.7.7/app/controllers/active_storage/representations/redirect_controller.rb to define it ``` The error seems to take place when we request a page in a test that loads two (or more) ActiveStorage images if ActiveStorage hasn't loaded yet, although it's a flaky error and so the test doesn't always behave like this. We've tested that switching to zeitwerk solves the issue but, since we aren't switching to zeitwerk in version 2.1.1 and we'd like this version to run all tests correctly, for now we're changing the tests so they don't load two records with images. On of these tests ("Polls Index Polls can be listed") fails on my machine when run individually. I haven't been able to consistently reproduce the other ones.
Creating records after starting the browser with the `visit` method sometimes results in database corruption and failing tests on our CI. Splitting some tests or merging them together solves the issue.
This way we avoid variables starting with underscores, which we don't use almost anywhere else.
taitus
approved these changes
Mar 18, 2024
This test is failing often due to an "Unable to autoload constant" error, that will be fixed after switching to zeitwerk. Just like it happened in the the "Polls can be listed" test, the reason seems to be accessing a page containing several ActiveStorage attachments. However, since this test only makes sense when two or more images are displayed on the page, we can't change the test so create just one image. So, for now, we're commenting the test, and we'll uncomment it again when we enable zeitwerk in version 2.2.0.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
References
Background
When running these tests, under certain conditions, we get a warning followed by an error:
Objectives
Notes
The error seems to take place when we request a page in a test that loads two (or more) ActiveStorage images if ActiveStorage hasn't loaded yet, although it's a flaky error and so the test doesn't always behave like this.
We've tested that switching to zeitwerk solves the issue but, since we aren't switching to zeitwerk in version 2.1.1 and we'd like this version to run all tests correctly, for now we're changing the tests so they don't load two records with images.
On of these tests ("Polls Index Polls can be listed") fails on my machine when run individually. I haven't been able to consistently reproduce the other ones.