From abe7830421d58a2c43a15285885aa8f700c2e7cc Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 11 Sep 2013 14:58:21 -0500 Subject: [PATCH] core: fix NoMethodError in Vagrant.has_plugin? [GH-1736] --- CHANGELOG.md | 1 + lib/vagrant.rb | 2 +- test/unit/vagrant_test.rb | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 648e6db8d..110d3fb76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ IMPROVEMENTS: BUG FIXES: + - core: Fix NoMethodError in the new `Vagrant.has_plugin?` method [GH-1736] - hosts/arch: NFS exporting works properly, no exceptions. [GH-2161] - hosts/fedora: Fix host detection encoding issues. [GH-1977] - hosts/linux: Fix NFS export problems with `no_subtree_check`. [GH-2156] diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 966fb2934..9dfdac559 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -133,7 +133,7 @@ module Vagrant # be used from the Vagrantfile to easily branch based on plugin # availability. def self.has_plugin?(name) - plugin("2").registered.include?(name) + plugin("2").manager.registered.any? { |plugin| plugin.name == name } end # Returns a superclass to use when creating a plugin for Vagrant. diff --git a/test/unit/vagrant_test.rb b/test/unit/vagrant_test.rb index d92a232d1..84340f840 100644 --- a/test/unit/vagrant_test.rb +++ b/test/unit/vagrant_test.rb @@ -53,4 +53,22 @@ describe Vagrant do to raise_error(Vagrant::Errors::PluginLoadFailed) end end + + describe "has_plugin?" do + after(:each) do + described_class.plugin('2').manager.reset! + end + + it "should return true if the plugin is installed" do + plugin = Class.new(described_class.plugin('2')) do + name "i_am_installed" + end + + described_class.has_plugin?("i_am_installed").should be_true + end + + it "should return false if the plugin is not installed" do + described_class.has_plugin?("i_dont_exist").should be_false + end + end end