Don't warn about double loading SERVICE_CODE_PREFIX if cache_classes is ... #205
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.
This fixes #200 by using #require instead of #load if cache_classes is false.
The root of the problem is in engine.rb which is calling #constantize on the calculator classes on line 34. This triggers auto-loading of Spree::Calculator::Shipping::Usps::Base since express_mail.rb subclasses from it. This initializes the SERVICE_CODE_PREFIX constant the first time.
But then on line 12 of engine.rb the calculator base classes get loaded (unless we're running in production mode). This results in the base class being evaluated again and a warning being displayed (in dev or test mode) due to the SERVICE_CODE_PREFIX being initialized a second time.
Another way to fix this would be to use #require instead of #load regardless of the Rails environment being loaded, but I wasn't sure of the implications of doing that so I opted for a less dramatic change.