From 24deb48e01d02eefd95acd01b947f67c6bcaba17 Mon Sep 17 00:00:00 2001 From: Bart Vercammen Date: Fri, 26 Jul 2013 15:00:45 +0200 Subject: [PATCH] rackspace - keypairs : redo exception/no-exception logic for ::destroy and ::get functions --- lib/fog/rackspace/models/compute_v2/keypair.rb | 6 ++---- lib/fog/rackspace/models/compute_v2/keypairs.rb | 6 +++++- tests/rackspace/models/compute_v2/keypairs_tests.rb | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/fog/rackspace/models/compute_v2/keypair.rb b/lib/fog/rackspace/models/compute_v2/keypair.rb index ee9c9f940..fbb441257 100644 --- a/lib/fog/rackspace/models/compute_v2/keypair.rb +++ b/lib/fog/rackspace/models/compute_v2/keypair.rb @@ -18,10 +18,8 @@ module Fog end def destroy - begin - service.delete_keypair(identity) - rescue Fog::Compute::RackspaceV2::NotFound - end + requires :identity + service.delete_keypair(identity) true end diff --git a/lib/fog/rackspace/models/compute_v2/keypairs.rb b/lib/fog/rackspace/models/compute_v2/keypairs.rb index ba2f366b0..00fc79320 100644 --- a/lib/fog/rackspace/models/compute_v2/keypairs.rb +++ b/lib/fog/rackspace/models/compute_v2/keypairs.rb @@ -18,7 +18,11 @@ module Fog end def get(key_id) - new(service.get_keypair(key_id).body['keypair']) + begin + new(service.get_keypair(key_id).body['keypair']) + rescue Fog::Compute::RackspaceV2::NotFound + nil + end end end diff --git a/tests/rackspace/models/compute_v2/keypairs_tests.rb b/tests/rackspace/models/compute_v2/keypairs_tests.rb index f1bd316d2..1c2c943a0 100644 --- a/tests/rackspace/models/compute_v2/keypairs_tests.rb +++ b/tests/rackspace/models/compute_v2/keypairs_tests.rb @@ -23,11 +23,11 @@ Shindo.tests('Fog::Compute::RackspaceV2 | keypairs', ['rackspace']) do key == nil end - tests("get unknown").raises(Fog::Compute::RackspaceV2::NotFound) do + tests("get unknown").returns(nil) do service.keypairs.get(Fog::Mock.random_letters(32)) end - tests("delete unknown").returns(true) do + tests("delete unknown").raises(Fog::Compute::RackspaceV2::NotFound) do service.keypairs.destroy(Fog::Mock.random_letters(32)) end