Revision bd3f3260
Added by Marek Hulán over 8 years ago
app/models/host/base.rb | ||
---|---|---|
def uniq_interfaces_identifiers
|
||
success = true
|
||
identifiers = []
|
||
self.interfaces.each do |interface|
|
||
relevant_interfaces = self.interfaces.select { |i| !i.marked_for_destruction? }
|
||
relevant_interfaces.each do |interface|
|
||
next if interface.identifier.blank?
|
||
if identifiers.include?(interface.identifier)
|
||
interface.errors.add :identifier, :taken
|
test/unit/host_test.rb | ||
---|---|---|
end
|
||
end
|
||
|
||
describe 'interface identifiers validation' do
|
||
let(:host) { FactoryGirl.build(:host, :managed) }
|
||
let(:additional_interface) { host.interfaces.build }
|
||
|
||
context 'additional interface has different identifier' do
|
||
test 'host is valid' do
|
||
assert host.valid?
|
||
end
|
||
end
|
||
|
||
context 'additional interface has same identifier' do
|
||
before { additional_interface.identifier = host.primary_interface.identifier }
|
||
|
||
test 'host is valid' do
|
||
refute host.valid?
|
||
end
|
||
|
||
test 'validation ignores interfaces marked for destruction' do
|
||
additional_interface.mark_for_destruction
|
||
assert host.valid?
|
||
end
|
||
end
|
||
end
|
||
|
||
private
|
||
|
||
def parse_json_fixture(relative_path)
|
Also available in: Unified diff
Fixes #11031 - ignore identifiers of interfaces being destroyed
(cherry picked from commit 1e7822a586b6e4f288823df0b9419ef2749d6b8c)