From c1989603be9ccab8b7fb60d3b2ab1312314b1a92 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 23 Jan 2014 15:21:42 -0800 Subject: [PATCH] core: adding from metadata wlil force if specified --- lib/vagrant/action/builtin/box_add.rb | 3 +- .../vagrant/action/builtin/box_add_test.rb | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 66ab23245..45a9f3129 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -124,7 +124,8 @@ module Vagrant # Add the box! box = env[:box_collection].add( - box_url, metadata.name, metadata_version.version) + box_url, metadata.name, metadata_version.version, + force: env[:box_force]) ensure # Make sure we delete the temporary file after we add it, # unless we were interrupted, in which case we keep it around diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index 03aa619b2..c9551be28 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -368,5 +368,45 @@ describe Vagrant::Action::Builtin::BoxAdd do expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAddNoMatchingProvider) end + + it "force adds a box if specified" do + box_path = iso_env.box2_file(:virtualbox) + tf = Tempfile.new("vagrant").tap do |f| + f.write(<<-RAW) + { + "name": "foo/bar", + "versions": [ + { + "version": "0.5" + }, + { + "version": "0.7", + "providers": [ + { + "name": "virtualbox", + "url": "#{box_path}" + } + ] + } + ] + } + RAW + f.close + end + + env[:box_force] = true + env[:box_url] = tf.path + box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(checksum(path)).to eq(checksum(box_path)) + expect(name).to eq("foo/bar") + expect(version).to eq("0.7") + expect(opts[:force]).to be_true + true + end.and_return(box) + + app.should_receive(:call).with(env) + + subject.call(env) + end end end