-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fix Zeitwerk loading EmailAlertAPI constant #1346
Conversation
Do we not have any tests that cover the autoloader? |
We can get caught out with the differences in loading behaviour between test environments and production. When production starts it eager loads all the classes where this error can occur. Whereas in test we avoid eager loading the whole application and as this constant gets loaded by something else: email-alert-api/config/application.rb Line 37 in 5864d58
( This situation is actually one of the ones that the publishing-e2e-tests suite can catch as it runs the application in a production environment, which makes it good for catching the parts of code that the test suite doesn't exercise but are essential for basic functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough!
I'd assumed that the feature tests would cover this (as they run the entry point of the application), but I guess they don't because config.eager_load
is false in all test environments, even feature tests.
Feels like it would be nice for the test suite of the app to cover "won't even start in production", but if that's not easy to do I'm happy to merge this with no regression test.
Thanks @richardTowers, I was busy editing my earlier reply as I learnt more from digging further. It's probably easier to just write a fresh reply (and a reminder that I should probably slow down 😅 ) So the issue wasn't actually that it fails to autoload the class we want, it's actually that when the new Zeitwerk autoloader runs it expects to find a constant with the name There's a couple of smells about this to look into further. This |
This resolves a problem where the Email Alert API application was not starting when using the Zeitwerk autoloader. The application wasn't starting because it expected that the `lib/email_alert_api/config` directory would define a constant EmailAlertApi::Config and when it didn't it raised an error. ``` /Users/kevindew/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:392:in `const_get': uninitialized constant EmailAlertApi::Config (NameError) ``` This was a problem that only affects the production environment because this is the only environment that has config.eager_load set to true. In other environments classes are autoloaded when needed.
f4d2f45
to
4ae3bb9
Compare
This resolves a problem where the Email Alert API application was not
starting when using the Zeitwerk autoloader. The application wasn't
starting because it couldn't find the EmailAlertAPI constant and was
triggering this error:
The autoloader would expect to find a class named EmailAlertApi rather
than EmailAlertAPI at the location of email_alert_api.