Skip to content

Commit

Permalink
[rubygems/rubygems] Fix funding metadata not being printed in some si…
Browse files Browse the repository at this point in the history
…tuations

Namely, when a gem has not previously been installed, and Bundler is
using the compact index API, fund metadata was not getting printed
because the proper delegation was not implemented in the specification
class used by the compact index.

rubygems/rubygems@9ef5139f60
  • Loading branch information
deivid-rodriguez authored and matzbot committed Jun 14, 2024
1 parent 6a474ef commit 4d73f3f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
11 changes: 11 additions & 0 deletions lib/bundler/endpoint_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ def extensions
end
end

# needed for `bundle fund`
def metadata
if @remote_specification
@remote_specification.metadata
elsif _local_specification
_local_specification.metadata
else
super
end
end

def _local_specification
return unless @loaded_from && File.exist?(local_specification_path)
eval(File.read(local_specification_path), nil, local_specification_path).tap do |spec|
Expand Down
42 changes: 21 additions & 21 deletions spec/bundler/install/gems/fund_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

context "when gems include a fund URI" do
it "displays the plural fund message after installing" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo2"
gem 'has_funding_and_other_metadata'
gem 'has_funding'
gem 'rack-obama'
Expand All @@ -42,8 +42,8 @@
end

it "displays the singular fund message after installing" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo2"
gem 'has_funding'
gem 'rack-obama'
G
Expand All @@ -58,8 +58,8 @@
end

it "does not display the plural fund message after installing" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo2"
gem 'has_funding_and_other_metadata'
gem 'has_funding'
gem 'rack-obama'
Expand All @@ -69,8 +69,8 @@
end

it "does not display the singular fund message after installing" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo2"
gem 'has_funding'
gem 'rack-obama'
G
Expand All @@ -81,8 +81,8 @@

context "when gems do not include fund messages" do
it "does not display any fund messages" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo2"
gem "activesupport"
G

Expand All @@ -92,8 +92,8 @@

context "when a dependency includes a fund message" do
it "does not display the fund message" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo2"
gem 'gem_with_dependent_funding'
G

Expand All @@ -110,8 +110,8 @@
"funding_uri" => "https://example.com/also_has_funding/funding",
}
end
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo1"
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}'
G

Expand All @@ -124,8 +124,8 @@
"funding_uri" => "https://example.com/also_has_funding/funding",
}
end
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo1"
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}'
G

Expand All @@ -134,8 +134,8 @@
"funding_uri" => "https://example.com/also_has_funding/funding",
}
end
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
install_gemfile <<-G, artifice: "compact_index"
source "https://gem.repo1"
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.1")}'
G

Expand All @@ -149,14 +149,14 @@
}
end
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "https://gem.repo1"
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}'
G

bundle :install
bundle :install, artifice: "compact_index"
expect(out).to include("1 installed gem you directly depend on is looking for funding.")

bundle :install
bundle :install, artifice: "compact_index"
expect(out).to include("1 installed gem you directly depend on is looking for funding.")
end
end
Expand Down

0 comments on commit 4d73f3f

Please sign in to comment.