Skip to content

Commit

Permalink
Fix Vbd destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
plribeiro3000 committed Sep 5, 2014
1 parent 7c66a43 commit 4db98f3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/fog/compute/xen_server/models/vbd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def destroy
unplug
vdi.destroy
end
service.destroy_record(reference, provider_class)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/compute/xen_server/models/vdi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def can_be_destroyed?
end

def destroy
return service.destroy_vdi(reference) if can_be_destroyed?
return service.destroy_record(reference, provider_class) if can_be_destroyed?
false
end
end
Expand Down
17 changes: 14 additions & 3 deletions spec/fog/compute/xen_server/models/vbd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,11 @@ def service.unplug_vbd(reference); true end
vbd.type = 'Disk'
def vbd.unplug; @plugged = false; end
def vdi.destroy; @destroyed = true; end
def service.destroy_record(reference, provider_class); @destroyed = true end
vbd.stub(:vdi, vdi) do
vbd.destroy
vbd.stub(:service, service) do
vbd.destroy
end
end
end

Expand All @@ -186,15 +189,23 @@ def vdi.destroy; @destroyed = true; end
it 'should destroy the vdi' do
vdi.instance_variable_get(:@destroyed).must_equal(true)
end

it 'should destroy the vbd' do
service.instance_variable_get(:@destroyed).must_equal(true)
end
end

describe 'on a cd' do
before :each do
def service.destroy_record(reference, provider_class); @destroyed = true end
vbd.type = 'CD'
vbd.stub(:service, service) do
vbd.destroy
end
end

it 'should return nil' do
vbd.destroy.must_equal(nil)
it 'should destroy the vbd' do
service.instance_variable_get(:@destroyed).must_equal(true)
end
end
end
Expand Down
11 changes: 6 additions & 5 deletions spec/fog/compute/xen_server/models/vdi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,18 @@ def self.read_identity
end

describe '#destroy' do
describe "when it can be unplugged" do
describe 'when it can be destroyed' do
before :each do
def vdi.can_be_destroyed?; true end
def service.destroy_vdi(reference); true end
end

it 'should return true' do
def service.destroy_record(reference, provider_class); @destroyed = true end
vdi.stub(:service, service) do
vdi.destroy.must_equal(true)
end
end

it 'should destroy it' do
service.instance_variable_get(:@destroyed).must_equal(true)
end
end

describe 'when can not be destroyed' do
Expand Down

0 comments on commit 4db98f3

Please sign in to comment.