Skip to content

Commit

Permalink
Do not validate whether an interface name exists if not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 2, 2019
1 parent 13567d3 commit 35213cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 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

0 comments on commit 35213cd

Please sign in to comment.