Skip to content

Commit f57af84

Browse files
Edouard-chinmatzbot
authored andcommitted
[ruby/rubygems] Fix plugin new version not registering:
- ### Problem When a plugin in the Gemfile is updated to a new version, it will be downloaded but will not be registered. The old version of the plugin will be loaded when Bundler is invoked. ### Context The problem is in the `Index#installed?` method that only checks for the plugin name in the index. If it finds one, it skips the registration. ### Solution Check whether the registed plugin load paths matche the new plugin one. If not, register the new plugin which will override the previous one in the index. ruby/rubygems@ac65001055
1 parent 115b4c6 commit f57af84

4 files changed

Lines changed: 41 additions & 10 deletions

File tree

lib/bundler/plugin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def gemfile_install(gemfile = nil, &inline)
113113

114114
return if definition.dependencies.empty?
115115

116-
plugins = definition.dependencies.map(&:name).reject {|p| index.installed? p }
116+
plugins = definition.dependencies.map(&:name)
117117
installed_specs = Installer.new.install_definition(definition)
118118

119119
save_plugins plugins, installed_specs, builder.inferred_plugins
@@ -258,7 +258,7 @@ def save_plugins(plugins, specs, optional_plugins = [])
258258
# It's possible that the `plugin` found in the Gemfile don't appear in the specs. For instance when
259259
# calling `BUNDLE_WITHOUT=default bundle install`, the plugins will not get installed.
260260
next if spec.nil?
261-
next if index.installed?(name)
261+
next if index.up_to_date?(spec)
262262

263263
save_plugin(name, spec, optional_plugins.include?(name))
264264
end

lib/bundler/plugin/index.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ def installed?(name)
119119
@plugin_paths[name]
120120
end
121121

122+
def up_to_date?(spec)
123+
path = installed?(spec.name)
124+
125+
path == spec.full_gem_path
126+
end
127+
122128
def installed_plugins
123129
@plugin_paths.keys
124130
end

spec/bundler/bundler/plugin_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
end
6666

6767
it "passes the name and options to installer" do
68-
allow(index).to receive(:installed?).
69-
with("new-plugin")
68+
allow(index).to receive(:up_to_date?).
69+
with(spec)
7070
allow(installer).to receive(:install).with(["new-plugin"], opts) do
7171
{ "new-plugin" => spec }
7272
end.once
@@ -75,17 +75,17 @@
7575
end
7676

7777
it "validates the installed plugin" do
78-
allow(index).to receive(:installed?).
79-
with("new-plugin")
78+
allow(index).to receive(:up_to_date?).
79+
with(spec)
8080
allow(subject).
8181
to receive(:validate_plugin!).with(lib_path("new-plugin")).once
8282

8383
subject.install ["new-plugin"], opts
8484
end
8585

8686
it "registers the plugin with index" do
87-
allow(index).to receive(:installed?).
88-
with("new-plugin")
87+
allow(index).to receive(:up_to_date?).
88+
with(spec)
8989
allow(index).to receive(:register_plugin).
9090
with("new-plugin", lib_path("new-plugin").to_s, [lib_path("new-plugin").join("lib").to_s], []).once
9191
subject.install ["new-plugin"], opts
@@ -102,7 +102,7 @@
102102
end.once
103103

104104
allow(subject).to receive(:validate_plugin!).twice
105-
allow(index).to receive(:installed?).twice
105+
allow(index).to receive(:up_to_date?).twice
106106
allow(index).to receive(:register_plugin).twice
107107
subject.install ["new-plugin", "another-plugin"], opts
108108
end
@@ -138,7 +138,7 @@
138138
end
139139

140140
before do
141-
allow(index).to receive(:installed?) { nil }
141+
allow(index).to receive(:up_to_date?) { nil }
142142
allow(definition).to receive(:dependencies) { [Bundler::Dependency.new("new-plugin", ">=0"), Bundler::Dependency.new("another-plugin", ">=0")] }
143143
allow(installer).to receive(:install_definition) { plugin_specs }
144144
end

spec/bundler/plugins/install_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,31 @@ def exec(command, args)
265265
plugin_should_be_installed("foo")
266266
end
267267

268+
it "overrides the index with the new plugin version" do
269+
gemfile <<-G
270+
source 'https://gem.repo2'
271+
plugin 'foo', "1.0"
272+
gem 'myrack', "1.0.0"
273+
G
274+
275+
bundle "install"
276+
277+
update_repo2 do
278+
build_plugin "foo", "2.0.0"
279+
end
280+
281+
gemfile <<-G
282+
source 'https://gem.repo2'
283+
plugin 'foo', "2.0"
284+
gem 'myrack', "1.0.0"
285+
G
286+
287+
bundle "install"
288+
289+
expected = local_plugin_gem("foo-2.0.0", "lib").to_s
290+
expect(Bundler::Plugin.index.load_paths("foo")).to eq([expected])
291+
end
292+
268293
it "respects bundler groups" do
269294
gemfile <<-G
270295
source 'https://gem.repo2'

0 commit comments

Comments
 (0)