Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bundler/lib/bundler/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def gemfile_install(gemfile = nil, &inline)

return if definition.dependencies.empty?

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

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

save_plugin(name, spec, optional_plugins.include?(name))
end
Expand Down
6 changes: 6 additions & 0 deletions bundler/lib/bundler/plugin/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def installed?(name)
@plugin_paths[name]
end

def up_to_date?(spec)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to create a new method instead of modifying the installed? one, because installed? is also used in the uninstall method. In this case, we don't care about the version of the plugin, we just want to know whether the plugin name exists in the index.

if index.installed?(name)

path = installed?(spec.name)

path == spec.full_gem_path
end

def installed_plugins
@plugin_paths.keys
end
Expand Down
16 changes: 8 additions & 8 deletions bundler/spec/bundler/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
end

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

it "validates the installed plugin" do
allow(index).to receive(:installed?).
with("new-plugin")
allow(index).to receive(:up_to_date?).
with(spec)
allow(subject).
to receive(:validate_plugin!).with(lib_path("new-plugin")).once

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

it "registers the plugin with index" do
allow(index).to receive(:installed?).
with("new-plugin")
allow(index).to receive(:up_to_date?).
with(spec)
allow(index).to receive(:register_plugin).
with("new-plugin", lib_path("new-plugin").to_s, [lib_path("new-plugin").join("lib").to_s], []).once
subject.install ["new-plugin"], opts
Expand All @@ -102,7 +102,7 @@
end.once

allow(subject).to receive(:validate_plugin!).twice
allow(index).to receive(:installed?).twice
allow(index).to receive(:up_to_date?).twice
allow(index).to receive(:register_plugin).twice
subject.install ["new-plugin", "another-plugin"], opts
end
Expand Down Expand Up @@ -138,7 +138,7 @@
end

before do
allow(index).to receive(:installed?) { nil }
allow(index).to receive(:up_to_date?) { nil }
allow(definition).to receive(:dependencies) { [Bundler::Dependency.new("new-plugin", ">=0"), Bundler::Dependency.new("another-plugin", ">=0")] }
allow(installer).to receive(:install_definition) { plugin_specs }
end
Expand Down
25 changes: 25 additions & 0 deletions bundler/spec/plugins/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,31 @@ def exec(command, args)
plugin_should_be_installed("foo")
end

it "overrides the index with the new plugin version" do
gemfile <<-G
source 'https://gem.repo2'
plugin 'foo', "1.0"
gem 'myrack', "1.0.0"
G

bundle "install"

update_repo2 do
build_plugin "foo", "2.0.0"
end

gemfile <<-G
source 'https://gem.repo2'
plugin 'foo', "2.0"
gem 'myrack', "1.0.0"
G

bundle "install"

expected = local_plugin_gem("foo-2.0.0", "lib").to_s
expect(Bundler::Plugin.index.load_paths("foo")).to eq([expected])
end

it "respects bundler groups" do
gemfile <<-G
source 'https://gem.repo2'
Expand Down