Sha256: 7ff986062b59d268294039ebe21f97ccb8d4c2cd2f62355702142c7853f32bc1
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
require 'test_plugin_helper' class ForemanHostExtraValidatorTest < ActiveSupport::TestCase setup do disable_orchestration User.current = FactoryBot.build(:user, :admin) end context 'with validation regex' do setup do Setting[:host_name_validation_regex] = '^[0-9]+$' @host = FactoryBot.build(:host) end test 'host should validate from settings' do @host.name = '054354' assert_valid @host end test 'host should not validate when host name does not match regex' do @host.name = 'invalidhostname' refute_valid @host assert_includes @host.errors[:name], "must match regex /#{Setting[:host_name_validation_regex]}/" end test 'host should validate from hostgroup parameter' do hostgroup = FactoryBot.create(:hostgroup) @host.hostgroup = hostgroup FactoryBot.create(:hostgroup_parameter, :name => 'host_name_validation_regex', :value => '^[a-z]+$', :hostgroup => hostgroup) assert_equal '^[a-z]+$', @host.send(:validate_name_regex) @host.hostname = 'abcdef' assert_valid @host @host.hostname = '1234' refute_valid @host assert_includes @host.errors[:name], "must match regex /^[a-z]+$/" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
foreman_host_extra_validator-0.2.2 | test/unit/foreman_host_extra_validator_test.rb |
foreman_host_extra_validator-0.2.1 | test/unit/foreman_host_extra_validator_test.rb |