Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5459 - bundler:seg-bundler-plugin-source-api-const-und…
Browse files Browse the repository at this point in the history
…efined, r=indirect

Avoid undefined Bundler::Plugin::API::Source exception

Fixes #5409, with a test!

(cherry picked from commit 02ceb08)
  • Loading branch information
bundlerbot authored and segiddins committed Mar 3, 2017
1 parent 8c34c7e commit fea96dd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/bundler/plugin/api/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ def gem_install_dir
def root
Bundler.root
end

# @private
# Returns true
def bundler_plugin_api_source?
true
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/bundler/rubygems_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def source
attr_writer :full_gem_path unless instance_methods.include?(:full_gem_path=)

def full_gem_path
if source.respond_to?(:path) || source.is_a?(Bundler::Plugin::API::Source)
# this cannot check source.is_a?(Bundler::Plugin::API::Source)
# because that _could_ trip the autoload, and if there are unresolved
# gems at that time, this method could be called inside another require,
# thus raising with that constant being undefined. Better to check a method
if source.respond_to?(:path) || (source.respond_to?(:bundler_plugin_api_source?) && source.bundler_plugin_api_source?)
Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.untaint
else
rg_full_gem_path
Expand Down
20 changes: 20 additions & 0 deletions spec/install/gemfile/gemspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@
expect(@err).not_to match(/ahh/)
end

it "allows the gemspec to activate other gems" do
# see https://github.com/bundler/bundler/issues/5409
#
# issue was caused by rubygems having an unresolved gem during a require,
# so emulate that
system_gems %w(rack-1.0.0 rack-0.9.1 rack-obama-1.0)

build_lib("foo", :path => bundled_app)
gemspec = bundled_app("foo.gemspec").read
bundled_app("foo.gemspec").open("w") do |f|
f.write "#{gemspec.strip}.tap { gem 'rack-obama'; require 'rack-obama' }"
end

install_gemfile! <<-G
gemspec
G

expect(the_bundle).to include_gem "foo 1.0"
end

it "allows conflicts" do
build_lib("foo", :path => tmp.join("foo")) do |s|
s.version = "1.0.0"
Expand Down

0 comments on commit fea96dd

Please sign in to comment.