Skip to content

Commit 488634d

Browse files
dfop02hsbt
authored andcommitted
Fix upgrade/downgrade bug and Add more tests
1 parent 8f844f3 commit 488634d

4 files changed

Lines changed: 77 additions & 8 deletions

File tree

bundler/lib/bundler/plugin.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ def gemfile_install(gemfile = nil, &inline)
114114
return if definition.dependencies.empty?
115115

116116
plugins = definition.dependencies.map(&:name).reject {|p| index.installed? p }
117-
118-
return if plugins.empty?
119-
120117
installed_specs = Installer.new.install_definition(definition)
121118

122119
save_plugins plugins, installed_specs, builder.inferred_plugins

bundler/lib/bundler/plugin/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def command_plugin(command)
112112
end
113113

114114
# Plugin cannot be installed and updating to install
115-
def cannot_install?(name, version)
115+
def version_already_installed?(name, version)
116116
installed?(name) && !updating?(name, version)
117117
end
118118

bundler/lib/bundler/plugin/installer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def install_from_specs(specs)
100100
paths = {}
101101

102102
specs.each do |spec|
103-
next if cannot_install?(spec.name, spec.version)
103+
next if version_already_installed?(spec.name, spec.version)
104104

105105
spec.source.install spec
106106
paths[spec.name] = spec
@@ -109,14 +109,14 @@ def install_from_specs(specs)
109109
paths
110110
end
111111

112-
# Check if the Plugin is already installed or has a diff version to install
112+
# Check if the Plugin version is already installed or has a diff version to install
113113
#
114114
# @param [String] name of the plugin gem to search in the source
115115
# @param [String] version of the gem to install
116116
#
117117
# @return [Boolean] true if installed or not updating plugin
118-
def cannot_install?(plugin, version)
119-
Index.new.cannot_install?(plugin, version)
118+
def version_already_installed?(plugin, version)
119+
Index.new.version_already_installed?(plugin, version)
120120
end
121121
end
122122
end

bundler/spec/plugins/install_spec.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,78 @@ def exec(command, args)
232232
plugin_should_be_installed("foo")
233233
end
234234

235+
it "upgrade plugins version listed in gemfile" do
236+
update_repo2 do
237+
build_plugin "foo", "1.4.0"
238+
build_plugin "foo", "1.5.0"
239+
end
240+
241+
gemfile <<-G
242+
source '#{file_uri_for(gem_repo2)}'
243+
plugin 'foo', "1.4.0"
244+
gem 'rack', "1.0.0"
245+
G
246+
247+
bundle "install"
248+
249+
expect(out).to include("Installing foo 1.4.0")
250+
expect(out).to include("Installed plugin foo")
251+
expect(out).to include("Bundle complete!")
252+
253+
expect(the_bundle).to include_gems("rack 1.0.0")
254+
plugin_should_be_installed("foo")
255+
256+
gemfile <<-G
257+
source '#{file_uri_for(gem_repo2)}'
258+
plugin 'foo', "1.5.0"
259+
gem 'rack', "1.0.0"
260+
G
261+
262+
bundle "install"
263+
264+
expect(out).to include("Installing foo 1.5.0")
265+
expect(out).to include("Bundle complete!")
266+
267+
expect(the_bundle).to include_gems("rack 1.0.0")
268+
plugin_should_be_installed("foo")
269+
end
270+
271+
it "downgrade plugins version listed in gemfile" do
272+
update_repo2 do
273+
build_plugin "foo", "1.4.0"
274+
build_plugin "foo", "1.5.0"
275+
end
276+
277+
gemfile <<-G
278+
source '#{file_uri_for(gem_repo2)}'
279+
plugin 'foo', "1.5.0"
280+
gem 'rack', "1.0.0"
281+
G
282+
283+
bundle "install"
284+
285+
expect(out).to include("Installing foo 1.5.0")
286+
expect(out).to include("Installed plugin foo")
287+
expect(out).to include("Bundle complete!")
288+
289+
expect(the_bundle).to include_gems("rack 1.0.0")
290+
plugin_should_be_installed("foo")
291+
292+
gemfile <<-G
293+
source '#{file_uri_for(gem_repo2)}'
294+
plugin 'foo', "1.4.0"
295+
gem 'rack', "1.0.0"
296+
G
297+
298+
bundle "install"
299+
300+
expect(out).to include("Installing foo 1.4.0")
301+
expect(out).to include("Bundle complete!")
302+
303+
expect(the_bundle).to include_gems("rack 1.0.0")
304+
plugin_should_be_installed("foo")
305+
end
306+
235307
it "install only plugins not installed yet listed in gemfile" do
236308
gemfile <<-G
237309
source '#{file_uri_for(gem_repo2)}'

0 commit comments

Comments
 (0)