summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2018-05-18 10:27:33 +0100
committerGitHub <noreply@github.com>2018-05-18 10:27:33 +0100
commit7edec65fecd800ba350bbe61f5e195e6ff52c022 (patch)
tree03e6bd321d57bba90c86117adb15e13e5f1e8220
parent2f2336327eb672df18e2b6876a4aa555b7aa5a5e (diff)
parente4ed292f15618d1b556c4ad7081afc4e1f41aa6a (diff)
downloadchef-7edec65fecd800ba350bbe61f5e195e6ff52c022.tar.gz
Merge pull request #7196 from chef/tg/clear_gem_sources_option
Tg/clear gem sources option
-rw-r--r--chef-config/lib/chef-config/config.rb3
-rw-r--r--lib/chef/resource/gem_package.rb2
-rw-r--r--spec/unit/resource/gem_package_spec.rb13
3 files changed, 17 insertions, 1 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index ef792b2db7..612033b30c 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -1087,6 +1087,9 @@ module ChefConfig
# can be set to a string or array of strings for URIs to set as rubygems sources
default :rubygems_url, "https://www.rubygems.org"
+ # globally sets the default of the clear_sources property on the gem_package and chef_gem resources
+ default :clear_gem_sources, false
+
# If installed via an omnibus installer, this gives the path to the
# "embedded" directory which contains all of the software packaged with
# omnibus. This is used to locate the cacert.pem file on windows.
diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb
index ee1262cb47..f2e1867322 100644
--- a/lib/chef/resource/gem_package.rb
+++ b/lib/chef/resource/gem_package.rb
@@ -40,7 +40,7 @@ class Chef
# FIXME? the array form of installing paths most likely does not work?
#
property :source, [ String, Array ]
- property :clear_sources, [ TrueClass, FalseClass ], default: false, desired_state: false
+ property :clear_sources, [ TrueClass, FalseClass ], default: lazy { Chef::Config[:clear_gem_sources] }, desired_state: false
# Sets a custom gem_binary to run for gem commands.
property :gem_binary, String, desired_state: false
diff --git a/spec/unit/resource/gem_package_spec.rb b/spec/unit/resource/gem_package_spec.rb
index 32070e48be..aba6ab1032 100644
--- a/spec/unit/resource/gem_package_spec.rb
+++ b/spec/unit/resource/gem_package_spec.rb
@@ -52,3 +52,16 @@ describe Chef::Resource::GemPackage, "gem_binary" do
expect(resource.gem_binary).to eql("/opt/local/bin/gem")
end
end
+
+describe Chef::Resource::GemPackage, "clear_gem_sources" do
+ let(:resource) { Chef::Resource::GemPackage.new("foo") }
+
+ it "is false by default" do
+ expect(resource.clear_sources).to be false
+ end
+
+ it "sets the default of clear_sources to the config value" do
+ Chef::Config[:clear_gem_sources] = true
+ expect(resource.clear_sources).to be true
+ end
+end