Skip to content

Commit

Permalink
Merge pull request #933 from yast/network-ng-fix-name-validation
Browse files Browse the repository at this point in the history
network ng: fix name validation
  • Loading branch information
imobachgs authored Sep 2, 2019
2 parents 3346718 + 4726b55 commit 3370888
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/lib/y2network/widgets/interface_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize(settings)
textdomain "network"

@settings = settings
@old_name = @settings.name
end

def label
Expand Down Expand Up @@ -57,7 +58,7 @@ def items
end

def validate
if @settings.name_exists?(value)
if @old_name != value && @settings.name_exists?(value)
Yast::Popup.Error(
format(_("Configuration name %s already exists.\nChoose a different one."), value)
)
Expand Down
24 changes: 19 additions & 5 deletions test/y2network/widgets/interface_name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,26 @@
expect(subject.validate).to be false
end

it "fails for already used names" do
allow(subject).to receive(:value).and_return valid_name
allow(Yast::NetworkInterfaces).to receive(:List).and_return [valid_name]
context "when the name is already used" do
before do
allow(subject).to receive(:value).and_return valid_name
allow(Yast::NetworkInterfaces).to receive(:List).and_return [valid_name]
end

expect(Yast::UI).to receive(:SetFocus)
expect(subject.validate).to be false
context "if the name was changed" do
let(:valid_name) { "eth1" }

it "fails" do
expect(Yast::UI).to receive(:SetFocus)
expect(subject.validate).to be false
end
end

context "if the name was not changed" do
it "passes" do
expect(subject.validate).to eq(true)
end
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion test/y2network/widgets/interface_naming_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
let(:builder) do
instance_double(
Y2Network::InterfaceConfigBuilder,
interface: interface
interface: interface,
name: "eth0"
)
end

Expand Down

0 comments on commit 3370888

Please sign in to comment.