Project

General

Profile

« Previous | Next » 

Revision e476ae3a

Added by Dominic Cleal over 8 years ago

fixes #11375, #11782 - validate a host's lookup_values

Enabling validation ensures the casting and validation within
LookupValue runs during host/hostgroup save. Tweaks to hostgroup
cloning ensure that the newly cloned hostgroup now passes validation
when it has associated lookup values.

Don't show any LookupValue#match errors in the host/hostgroup forms
as the value is autogenerated by the nested attribute setter.

(cherry picked from commit 003359564b4ab5fa8198cc9b035df405e7e600cd)

View differences:

test/unit/host_test.rb
assert_equal '80', lookup_value.value
end
test "should be able to update complex YAML lookup value" do
host = FactoryGirl.create(:host)
lookup_key = FactoryGirl.create(:lookup_key, :is_param, :key_type => 'yaml')
lookup_value = FactoryGirl.create(:lookup_value, :lookup_key_id => lookup_key.id,
:match => "fqdn=#{host.fqdn}", :value => YAML.dump(:foo => :bar))
host.reload
assert_difference('LookupValue.count', 0) do
assert host.update_attributes!(:lookup_values_attributes => {'0' =>
{:lookup_key_id => lookup_key.id.to_s, :value => YAML.dump(:updated => :value),
:match => "fqdn=#{host.fqdn}",
:id => lookup_value.id.to_s, :_destroy => 'false'}})
end
lookup_value.reload
assert_equal({:updated => :value}, lookup_value.value)
end
test "should raise nested lookup value validation errors" do
lookup_key = FactoryGirl.create(:lookup_key, :is_param, :key_type => 'hash')
host = FactoryGirl.build(:host)
host.attributes = {:lookup_values_attributes => {'0' =>
{:lookup_key_id => lookup_key.id.to_s, :value => '{"a":',
:match => "fqdn=#{host.fqdn}",
:_destroy => 'false'}}}
assert host.lookup_values.first.present?
refute_valid host, :'lookup_values.value', /invalid hash/
end
test "should import facts from json stream" do
h=Host.new(:name => "sinn1636.lan")
h.disk = "!" # workaround for now

Also available in: Unified diff