diff options
author | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-07-29 15:16:28 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-07-29 15:16:28 -0700 |
commit | cb32fcb8e78bb11ccbd4a604d4654edca37833a5 (patch) | |
tree | c1f3328fb9aa56d6de56c0531ca3237faa2f8a38 | |
parent | 741817402161cc08713b48456578bc92ea278020 (diff) | |
download | bundler-cb32fcb8e78bb11ccbd4a604d4654edca37833a5.tar.gz |
Extend Gem.source_index.refresh! to work correctly with rails 2.3
-rw-r--r-- | lib/bundler/templates/environment.rb | 46 | ||||
-rw-r--r-- | spec/bundler/manifest_spec.rb | 29 |
2 files changed, 65 insertions, 10 deletions
diff --git a/lib/bundler/templates/environment.rb b/lib/bundler/templates/environment.rb index 2534974ddb..fc6c4f37e6 100644 --- a/lib/bundler/templates/environment.rb +++ b/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 %>" @@ -17,10 +8,44 @@ ENV["RUBYOPT"] = "-r#{__FILE__} #{ENV["RUBYOPT"]}" <% 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(*) @@ -53,4 +78,5 @@ module Gem class VerificationError < Exception; end class SystemExitException < SystemExit; end end + <% end %>
\ No newline at end of file diff --git a/spec/bundler/manifest_spec.rb b/spec/bundler/manifest_spec.rb index 3c3952be91..c2bf8977f4 100644 --- a/spec/bundler/manifest_spec.rb +++ b/spec/bundler/manifest_spec.rb @@ -199,6 +199,35 @@ describe "Bundler::Manifest" do 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 |