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