Skip to content

Commit

Permalink
Improve the mountby selector
Browse files Browse the repository at this point in the history
Using symbols instead of strings for its items key.
  • Loading branch information
dgdavid committed May 20, 2020
1 parent b57087b commit becf436
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/lib/autoinstall/widgets/storage/filesystem_attrs.rb
Expand Up @@ -89,7 +89,7 @@ def values
"filesystem" => filesystem_widget.value,
"label" => label_widget.value,
"mount" => mount_point_widget.value,
"mountby" => mountby_widget.value&.to_sym,
"mountby" => mountby_widget.value,
"fstab_options" => fstab_options_widget.value,
"mkfs_options" => mkfs_options_widget.value
}
Expand Down
13 changes: 2 additions & 11 deletions src/lib/autoinstall/widgets/storage/mountby.rb
Expand Up @@ -40,19 +40,10 @@ def label
# @macro seeComboBox
def items
@items ||= [
["", ""],
*Y2Storage::Filesystems::MountByType.all.map { |i| [i.to_s, i.to_human_string] }
[nil, ""],
*Y2Storage::Filesystems::MountByType.all.map { |i| [i.to_sym, i.to_human_string] }
]
end

# Returns selected type
#
# @return [String, nil] selected type; nil if none
def value
result = super

result.to_s.empty? ? nil : result
end
end
end
end
Expand Down
32 changes: 16 additions & 16 deletions test/lib/widgets/storage/mountby_test.rb
Expand Up @@ -24,33 +24,33 @@
describe Y2Autoinstallation::Widgets::Storage::Mountby do
subject(:widget) { described_class.new }

include_examples "CWM::ComboBox"

let(:items) { widget.items.map { |i| i[0] } }
include_examples "CWM::AbstractWidget"

describe "#items" do
let(:items) { widget.items.map { |i| i[0] } }

it "includes an empty option" do
expect(items).to include("")
expect(items).to include(nil)
end

it "includes 'device'" do
expect(items).to include("device")
it "includes :device" do
expect(items).to include(:device)
end

it "includes 'label'" do
expect(items).to include("label")
it "includes :label" do
expect(items).to include(:label)
end

it "includes 'uuid'" do
expect(items).to include("uuid")
it "includes :uuid" do
expect(items).to include(:uuid)
end

it "includes 'path'" do
expect(items).to include("path")
it "includes :path" do
expect(items).to include(:path)
end

it "includes 'id'" do
expect(items).to include("id")
it "includes :id" do
expect(items).to include(:id)
end
end

Expand All @@ -61,15 +61,15 @@
end

describe "when none is selected" do
let(:selected_value) { "" }
let(:selected_value) { nil }

it "returns nil" do
expect(widget.value).to be_nil
end
end

describe "when any is selected" do
let(:selected_value) { "path" }
let(:selected_value) { :path }

it "returns selected value" do
expect(widget.value).to eq(selected_value)
Expand Down

0 comments on commit becf436

Please sign in to comment.