diff --git a/plugins/providers/virtualbox/model/storage_controller_array.rb b/plugins/providers/virtualbox/model/storage_controller_array.rb index 452acf793..0e86db9fc 100644 --- a/plugins/providers/virtualbox/model/storage_controller_array.rb +++ b/plugins/providers/virtualbox/model/storage_controller_array.rb @@ -27,10 +27,8 @@ module VagrantPlugins # # @return [VagrantPlugins::ProviderVirtualBox::Model::StorageController] def get_primary_controller - ordered = sort { |a, b| a.boot_priority <=> b.boot_priority } - controller = ordered.detect do |c| - c.supported? && c.attachments.any? { |a| hdd?(a) } - end + ordered = find_all(&:supported?).sort_by(&:boot_priority) + controller = ordered.detect { |c| c.attachments.any? { |a| hdd?(a) } } if !controller raise Vagrant::Errors::VirtualBoxDisksNoSupportedControllers, @@ -62,8 +60,8 @@ module VagrantPlugins # # @return [VagrantPlugins::ProviderVirtualBox::Model::StorageController] def get_dvd_controller - ordered = sort { |a, b| a.boot_priority <=> b.boot_priority } - controller = ordered.detect { |c| c.supported? } + ordered = find_all(&:supported?).sort_by(&:boot_priority) + controller = ordered.first if !controller raise Vagrant::Errors::VirtualBoxDisksNoSupportedControllers, supported_types: supported_types.join(" ,") diff --git a/test/unit/plugins/providers/virtualbox/model/storage_controller_array_test.rb b/test/unit/plugins/providers/virtualbox/model/storage_controller_array_test.rb index a0b6d66af..e43c82c85 100644 --- a/test/unit/plugins/providers/virtualbox/model/storage_controller_array_test.rb +++ b/test/unit/plugins/providers/virtualbox/model/storage_controller_array_test.rb @@ -91,7 +91,7 @@ describe VagrantPlugins::ProviderVirtualBox::Model::StorageControllerArray do describe "#get_dvd_controller" do context "with one controller" do - let(:controller) { double("controller", supported?: true) } + let(:controller) { double("controller", supported?: true, boot_priority: 1) } before do subject.replace([controller]) @@ -111,9 +111,10 @@ describe VagrantPlugins::ProviderVirtualBox::Model::StorageControllerArray do context "with multiple controllers" do let(:controller1) { double("controller", supported?: true, boot_priority: 2) } let(:controller2) { double("controller", supported?: true, boot_priority: 1) } + let(:controller3) { double("controller", supported?: false, boot_priority: nil) } before do - subject.replace([controller1, controller2]) + subject.replace([controller1, controller2, controller3]) end it "returns the first supported controller" do