Skip to content

Commit

Permalink
Extend Gem.source_index.refresh! to work correctly with rails 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehuda Katz + Carl Lerche committed Jul 29, 2009
1 parent 7418174 commit cb32fcb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
46 changes: 36 additions & 10 deletions lib/bundler/templates/environment.rb
@@ -1,12 +1,3 @@
module Bundler
def self.rubygems_required
<% spec_files.each do |name, path| %>
Gem.loaded_specs["<%= name %>"] = eval(File.read("<%= path %>"))
Gem.source_index.add_spec(Gem.loaded_specs["<%= name %>"])
<% end %>
end
end
<% unless @system_gems %>
ENV["GEM_HOME"] = "<%= @repository.path %>"
ENV["GEM_PATH"] = "<%= @repository.path %>"
Expand All @@ -17,10 +8,44 @@ def self.rubygems_required
<% load_paths.each do |load_path| %>
$LOAD_PATH.unshift "<%= load_path %>"
<% end %>
<% if @rubygems %>
require "rubygems"
Bundler.rubygems_required
module Bundler
@bundled_specs = {}
<% spec_files.each do |name, path| %>
@bundled_specs["<%= name %>"] = eval(File.read("<%= path %>"))
@bundled_specs["<%= name %>"].loaded_from = "<%= path %>"
<% end %>
def self.add_specs_to_loaded_specs
Gem.loaded_specs.merge! @bundled_specs
if Gem.respond_to?(:loaded_stacks)
@bundled_specs.keys.each { |name| Gem.loaded_stacks[name] = [] }
end
end
def self.add_specs_to_index
@bundled_specs.each do |name, spec|
Gem.source_index.add_spec spec
end
end
add_specs_to_loaded_specs
add_specs_to_index
end
module Gem
def source_index.refresh!
super
Bundler.add_specs_to_index
end
end
<% else %>
$" << "rubygems.rb"
module Kernel
def gem(*)
Expand Down Expand Up @@ -53,4 +78,5 @@ class RemoteSourceException < Exception; end
class VerificationError < Exception; end
class SystemExitException < SystemExit; end
end
<% end %>
29 changes: 29 additions & 0 deletions spec/bundler/manifest_spec.rb
Expand Up @@ -199,6 +199,35 @@ def dep(name, version, options = {})
out = run_in_context "begin ; require 'rake' ; rescue LoadError ; puts('WIN') ; end"
out.should == "WIN"
end

["Running with system gems", "Running without system gems"].each_with_index do |desc, i|
describe desc do
before(:each) do
m = build_manifest <<-Gemfile
sources.clear
source "file://#{gem_repo1}"
gem "very-simple"
#{'disable_system_gems' if i == 1}
Gemfile
m.install
end

it "sets loaded_from on the specs" do
out = run_in_context "puts(Gem.loaded_specs['very-simple'].loaded_from || 'FAIL')"
out.should_not == "FAIL"
end

it "finds the gems in the source_index" do
out = run_in_context "puts Gem.source_index.find_name('very-simple').length"
out.should == "1"
end

it "still finds the gems in the source_index even if refresh! is called" do
out = run_in_context "Gem.source_index.refresh! ; puts Gem.source_index.find_name('very-simple').length"
out.should == "1"
end
end
end
end

describe "environments" do
Expand Down

0 comments on commit cb32fcb

Please sign in to comment.