wycats / bundler

407 stars 30 forks source link

In a rails app, gems with a rails/init.rb file get loaded in all environments regardless of :only or :except options #157

Open myronmarston opened 14 years ago

myronmarston commented 14 years ago

After getting a Rails 2.3.5 app to work with bundler, I've had issues with gem plugins. Any gem that has a rails/init.rb file gets treated as a plugin by Rails. This wouldn't be that big of a deal except for the fact that it winds up being loaded in all environments, regardless of what :only or :except options I've set in my Gemfile.

I've debugged this a bit and the problem seems to be here:

    specs += Gem.loaded_specs.values.select do |spec|
      spec.loaded_from && # prune stubs
        File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
    end

I found this was hit prior to the bundler environment doing all its requires (at which point it would skip particular gems because of only/except). However, Gem.loaded_specs contained all the bundled gems for all environments, and as a result, gems with a rails/init.rb file get selected regardless of the environment. Later in this method, these gems are all loaded.