Revision 35241dd6
Added by Marek Hulán over 8 years ago
test/unit/nics/base_test.rb | ||
---|---|---|
assert nic.host_managed?
|
||
SETTINGS[:unattended] = original
|
||
end
|
||
|
||
context 'there is already an interface with a MAC and IP' do
|
||
let(:host) { FactoryGirl.create(:host, :managed) }
|
||
|
||
describe 'creation of another nic with already used MAC and IP' do
|
||
let(:nic) do
|
||
nic = host.interfaces.build(:mac => host.mac, :managed => true, :type => 'Nic::Managed')
|
||
nic.ip = host.ip
|
||
nic
|
||
end
|
||
|
||
test 'it is invalid because of conflicting mac' do
|
||
refute nic.valid?
|
||
assert nic.errors.has_key?(:mac)
|
||
assert nic.errors.has_key?(:ip)
|
||
end
|
||
|
||
test 'it is valid if conflicting interface is on same host and is marked for destruction' do
|
||
host.primary_interface.mark_for_destruction
|
||
assert nic.valid?
|
||
end
|
||
end
|
||
|
||
describe 'creation of another nic with the same name' do
|
||
let(:nic) { host.interfaces.build(:mac => next_mac(host.mac), :managed => true, :type => 'Nic::Managed') }
|
||
|
||
context 'the domain is different' do
|
||
test 'it is valid' do
|
||
nic.name = host.shortname
|
||
assert_nil nic.domain
|
||
assert nic.valid?
|
||
end
|
||
end
|
||
|
||
context 'the domain is the same' do
|
||
before do
|
||
nic.name = host.name
|
||
nic.domain = host.domain
|
||
end
|
||
|
||
test 'it is invalid because of the name attribute' do
|
||
refute nic.valid?
|
||
assert nic.errors.has_key?(:name)
|
||
end
|
||
|
||
test 'it is valid if conflicting interface is on same host and is marked for destruction' do
|
||
host.primary_interface.mark_for_destruction
|
||
assert nic.valid?
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #11034 - custom uniqueness validations for interface attributes