Let me know if you think it needs more tests.
http://theforeman.org/issues/1716
···
--- app/models/host.rb | 3 +++ test/unit/host_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 0 deletions(-)diff --git a/app/models/host.rb b/app/models/host.rb
index 955a065…0da05d5 100644
— a/app/models/host.rb
+++ b/app/models/host.rb
@@ -668,6 +668,9 @@ class Host < Puppet::Rails::Host
# it and let the validations to produce an error
return if name.empty?
-
Remove whitespace
-
self.name.gsub!(/\s/,’’)
-
if domain.nil? and name.match(/./)
# try to assign the domain automatically based on our existing domains from the host FQDN
self.domain = Domain.all.select{|d| name.match(d.name)}.first rescue nil
diff --git a/test/unit/host_test.rb b/test/unit/host_test.rb
index 57bae56…1c1627c 100644
— a/test/unit/host_test.rb
+++ b/test/unit/host_test.rb
@@ -469,4 +469,11 @@ class HostTest < ActiveSupport::TestCase
assert_equal host.name, host.certname
end -
test “all whitespace should be removed from hostname” do
-
host = Host.create :name => "my host 1 ", :mac => “aabbecddeeff”, :ip => “2.3.4.3”, :hostgroup => hostgroups(:common), :managed => false
-
assert host.valid?
-
assert !host.new_record?
-
assert_equal “myhost1.mydomain.net”, host.name
-
end
end
1.7.7.6
–
Mikael Fridh / www.marinsoftware.com
Sysadmin, Operations / Regus, 8th Floor
Marin Software / M�ster Samuelsgatan 60
Cell: +46-708-174-200 / 111 21 Stockholm