spree-contrib / spree_active_shipping

Spree integration for Shopify's active_shipping gem.
http://guides.spreecommerce.org
134 stars 207 forks source link

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

Open pelargir opened 9 years ago

pelargir commented 9 years ago

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 commented 9 years ago

@pelargir, please rebase

jspizziri commented 9 years ago

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

pelargir commented 9 years ago

Yes, I just rebased from 2-3-stable