Skip to content

Commit

Permalink
Fix delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Oct 27, 2017
1 parent cebde55 commit 12184cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/lib/y2partitioner/widgets/delete_disk_partition_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ def validate_partition_table

# Deletes the indicated device
#
# @note When the device is a partitionable, all its partitions are deleted.
# @note When the device has a partition table, all its partitions are deleted.
#
# @note Shadowing for BtrFS subvolumes is always refreshed.
# @see Y2Storage::Filesystems::Btrfs.refresh_subvolumes_shadowing
#
# @param device [Y2Storage::BlkDevice]
def delete_device(device)
if device.is?(:partitionable)
log.info "deleting partitions for #{device}"
device.partition_table.delete_all_partitions unless device.partition_table.nil?
UIState.instance.select_row(device)
else
if device.is?(:partition)
log.info "deleting partition #{device}"
partitionable = device.partitionable
partitionable.partition_table.delete_partition(device)
UIState.instance.select_row(partitionable)
else
log.info "deleting partitions for #{device}"
device.partition_table.delete_all_partitions unless device.partition_table.nil?
UIState.instance.select_row(device)
end

device_graph = DeviceGraphs.instance.current
Expand Down
24 changes: 21 additions & 3 deletions test/y2partitioner/widgets/delete_disk_partition_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,27 @@
context "when the confirm message is accepted" do
let(:accept) { true }

it "deletes the device" do
subject.handle
expect(Y2Storage::BlkDevice.find_by_name(device_graph, device_name)).to be_nil
context "and the device is a partition" do
let(:device_name) { "/dev/sda2" }

it "deletes the partition" do
subject.handle
expect(Y2Storage::BlkDevice.find_by_name(device_graph, device_name)).to be_nil
end
end

context "and the device is not a partition" do
let(:device_name) { "/dev/sda" }

before do
allow(Yast::UI).to receive(:UserInput).and_return(:yes)
end

it "deletes all its partitions" do
expect(device.partitions).to_not be_empty
subject.handle
expect(device.partitions).to be_empty
end
end

it "refresh btrfs subvolumes shadowing" do
Expand Down

0 comments on commit 12184cf

Please sign in to comment.