maxio-com / chargify2

Chargify API V2 Ruby Wrapper
MIT License
13 stars 6 forks source link

Rails class caching causes uninitialized constant Chargify2::Client #1

Closed shayfrendt closed 12 years ago

shayfrendt commented 13 years ago

Any time you require 'chargify2' in a rails environment with config.cache_classes = true, the chargify2 gem will throw the following error:

/var/www/apps/sample_app/shared/bundle/ruby/1.9.1/gems/chargify2-0.2.0/lib/chargify2/resource.rb:10:in `<class:Resource>': uninitialized constant Chargify2::Client (NameError)
from /var/www/apps/sample_app/shared/bundle/ruby/1.9.1/gems/chargify2-0.2.0/lib/chargify2/resource.rb:7:in `<module:Chargify2>'
from /var/www/apps/sample_app/shared/bundle/ruby/1.9.1/gems/chargify2-0.2.0/lib/chargify2/resource.rb:1:in `<top (required)>'
from /var/www/apps/sample_app/shared/bundle/ruby/1.9.1/gems/chargify2-0.2.0/lib/chargify2.rb:6:in `block in <top (required)>'
from /var/www/apps/sample_app/shared/bundle/ruby/1.9.1/gems/chargify2-0.2.0/lib/chargify2.rb:6:in `each'
from /var/www/apps/sample_app/shared/bundle/ruby/1.9.1/gems/chargify2-0.2.0/lib/chargify2.rb:6:in `<top (required)>'

In the chargify2.rb file, the following line is requiring each of the files in the gem:

https://github.com/chargify/chargify2/blob/d45dc91ebda58b2e86f0d5ed218767d356a1e9d6/lib/chargify2.rb#L6

If the load order for these files is wrong, it will throw the "uninitialized constant Chargify2::Client" error from the following line:

https://github.com/chargify/chargify2/blob/3b49c01b129b9adc797ba402a42e5de298d0b2ea/lib/chargify2/resource.rb#L10

I'll try to get a failing test going, and probably will list out an explicit load order in chargify2.rb like:

require 'chargify2/utils'
require 'chargify2/client'
require 'chargify2/resource'

This should prevent load order problems when the gem is required.

shayfrendt commented 12 years ago

This issue was fixed by commit cadd6493cd690beae61 - closing this out.