Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Don't warn about double loading SERVICE_CODE_PREFIX if cache_classes is ...#205

Open
pelargir wants to merge 1 commit into
spree-contrib:2-3-stablefrom
CandleScience:fix-double-load
Open

Don't warn about double loading SERVICE_CODE_PREFIX if cache_classes is ...#205
pelargir wants to merge 1 commit into
spree-contrib:2-3-stablefrom
CandleScience:fix-double-load

Conversation

@pelargir

Copy link
Copy Markdown

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.

@jspizziri

Copy link
Copy Markdown
Member

@pelargir, please rebase

@jspizziri

Copy link
Copy Markdown
Member

@pelargir, are you going to be able to rebase this?

@pelargir

Copy link
Copy Markdown
Author

Yes, I just rebased from 2-3-stable

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants