Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#1107

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.

Reported by Steven Parkes · September 24th, 2008 @ 11:40 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Steven Parkes
    Steven Parkes

    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.

    September 25th, 2008 @ 12:20 AM

  2. Mislav
    Mislav

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

    October 7th, 2008 @ 08:43 PM

  3. Mislav
  4. Steven Parkes
  5. Pratik
    Pratik
    • State changed from new to duplicate

    January 18th, 2009 @ 06:49 AM