From 8b8a961f2e7791a8110a89b9d2ba1d5df669f01f Mon Sep 17 00:00:00 2001 From: Nick Osborn Date: Mon, 2 Dec 2013 13:44:14 +0000 Subject: [PATCH] [vcloud_director] Fix medias#create - issue #2440 --- .../vcloud_director/models/compute/medias.rb | 2 +- .../models/compute/media_tests.rb | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/fog/vcloud_director/models/compute/medias.rb b/lib/fog/vcloud_director/models/compute/medias.rb index d5e75094f..b50e944d3 100644 --- a/lib/fog/vcloud_director/models/compute/medias.rb +++ b/lib/fog/vcloud_director/models/compute/medias.rb @@ -23,7 +23,7 @@ module Fog # Perhaps this would be better implemented as media#upload. - file = response.body[:Files][:File] + file = response.body[:Files][:File].first file[:Link] = [file[:Link]] if file[:Link].is_a?(Hash) link = file[:Link].detect {|l| l[:rel] == 'upload:default'} diff --git a/tests/vcloud_director/models/compute/media_tests.rb b/tests/vcloud_director/models/compute/media_tests.rb index 23dae7382..2c70039de 100644 --- a/tests/vcloud_director/models/compute/media_tests.rb +++ b/tests/vcloud_director/models/compute/media_tests.rb @@ -4,8 +4,17 @@ Shindo.tests('Compute::VcloudDirector | media', ['vclouddirector']) do pending if Fog.mocking? medias = vdc.medias - pending if medias.all.empty? - media = medias.first + media_name = VcloudDirector::Compute::Helper.test_name + + tests('Compute::VcloudDirector | media', ['create']) do + tests('#create').returns(Fog::Compute::VcloudDirector::Media) do + File.open(VcloudDirector::Compute::Helper.fixture('test.iso'), 'rb') do |iso| + medias.create(media_name, iso).class + end + end + end + + media = medias.get_by_name(media_name) tests('Compute::VcloudDirector | media') do tests('#href').returns(String) { media.href.class } @@ -21,9 +30,9 @@ Shindo.tests('Compute::VcloudDirector | media', ['vclouddirector']) do end tests('Compute::VcloudDirector | media', ['load on demand']) do - tests("#description is not loaded yet").returns(NonLoaded) { media.attributes[:description] } - tests("#description is loaded on demand").returns(String) { media.description.class } - tests("#description is now loaded").returns(true) { media.attributes[:description] != NonLoaded } + tests('#description is not loaded yet').returns(NonLoaded) { media.attributes[:description] } + tests('#description is loaded on demand').returns(String) { media.description.class } + tests('#description is now loaded').returns(true) { media.attributes[:description] != NonLoaded } end tests('Compute::VcloudDirector | media', ['lazy load attrs']) do @@ -42,4 +51,8 @@ Shindo.tests('Compute::VcloudDirector | media', ['vclouddirector']) do tests('#get_by_name').returns(media.name) { medias.get_by_name(media.name).name } tests('#get').returns(media.id) { medias.get(media.id).id } end + + tests('Compute::VcloudDirector | media', ['destroy']) do + tests('#destroy').returns(true) { media.destroy } + end end