Sha256: 02f9651c35a98c4baa0eab781b9d01e77dbd4ce7b9ed5cebd018b23d32967aec

Contents?: true

Size: 978 Bytes

Versions: 4

Compression:

Stored size: 978 Bytes

Contents

require 'test_plugin_helper'

class ForemanPluginTemplateTest < ActiveSupport::TestCase
  setup do
    Setting::HostValidation.load_defaults
    disable_orchestration
    User.current = User.find_by_login 'admin'
  end

  test '#validate_name_regex should return regex from setting when no regex is inherited' do
    regex = '^[0-9]+$'
    Setting[:host_name_validation_regex] = regex
    host = FactoryGirl.build(:host, :managed)
    assert_equal regex, host.validate_name_regex
  end

  test 'host should validate when host name matches regex' do
    regex = '^[0-9]+$'
    Setting[:host_name_validation_regex] = regex
    host = Host.new name: '054354'
    assert host.valid?
  end

  test 'host should not validate when host name does not match regex' do
    regex = '^[0-9]+$'
    Setting[:host_name_validation_regex] = regex
    host = Host.new name: 'invalidhostname'
    refute host.valid?
    assert_includes host.errors[:name], "must match regex /#{regex}/"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_host_extra_validator-0.0.4 test/unit/foreman_host_extra_validator_test.rb
foreman_host_extra_validator-0.0.3 test/unit/foreman_host_extra_validator_test.rb
foreman_host_extra_validator-0.0.1 test/unit/foreman_host_extra_validator_test.rb
foreman_host_extra_validator-0.0.2 test/unit/foreman_host_extra_validator_test.rb