This project is archived and is in readonly mode.

#1107 ✓duplicate
Steven Parkes

Vendor'd rails gems can't be "depended"

Reported by Steven Parkes | September 24th, 2008 @ 11:40 PM | in 2.x

If a gem depends on a rails gem, e.g., activesupport, if the vendor'd version is not also in the system repository, an error occurs.

For example, right now I have 2-1-stable vendor'd, which reports its gem version as 2.1.2. If I config.gem thoughtbot-factory_girl, script/console errors out with


/usr/lib64/ruby/site_ruby/1.8/rubygems.rb:150:in `activate':Gem::Exception: can't activate activesupport (>= 1.0, runtime), already activated activesupport-2.1.2

In initalizer.rb, rails bashes gem's Gem.loaded_specs[stub] so that it knows activesupport is loaded. However, when trying to do the version matching, this isn't enough to get gem to consider the vendor'd rails version as possibility.

Changing


stubs.each do |stub|
  Gem.loaded_specs[stub] = Gem::Specification.new do |s|
    s.name = stub
    s.version = Rails::VERSION::STRING
  end
end

to


stubs.each do |stub|
  Gem.loaded_specs[stub] = Gem::Specification.new do |s|
    s.name = stub
    s.version = Rails::VERSION::STRING
  end
  Gem.source_index.add_spec(Gem.loaded_specs[stub])
end

makes the vendor'd version a valid candidate and fixes the problem. This doesn't force the vendor'd version to be okay: it's still checked against the requiring gem's spec and will still error out if the vendor'd version doesn't meet the requirements.

Comments and changes to this ticket

  • Steven Parkes

    Steven Parkes September 25th, 2008 @ 12:20 AM

    Well, the principle may be right, but the patch is a little light. For other functions (e.g., rake spec), gem is now going to want spec.loaded_from to be something other than nil for the stub specs

    Setting it to "", i.e.,

    
    stubs.each do |stub|
      Gem.loaded_specs[stub] = Gem::Specification.new do |s|
        s.name = stub
        s.version = Rails::VERSION::STRING
        s.loaded_from = ""
      end
      Gem.source_index.add_spec(Gem.loaded_specs[stub])
    end
    

    is certainly not right, but I'm not sure what is. Gem wants the gem to be in a repository and vendor/rails doesn't have gem repository layout.

    In any case, its enough to get gem to be able to continue.

  • Mislav

    Mislav October 7th, 2008 @ 08:43 PM

    I believe this is fixed with latest gem dependencies updates, can you check?

  • Mislav

    Mislav October 7th, 2008 @ 09:35 PM

    Yes, #1128 definitely fixes this issue for us.

  • Steven Parkes

    Steven Parkes October 7th, 2008 @ 10:08 PM

    Yup; the latest #1128 patch works for me.

  • Pratik

    Pratik January 18th, 2009 @ 06:49 AM

    • State changed from “new” to “duplicate”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages