Revision 8fd3c579
Added by Dominic Cleal over 8 years ago
app/models/concerns/host_common.rb | ||
---|---|---|
lookup_values_attributes.each_value do |attribute|
|
||
attr = attribute.dup
|
||
if id = attr.delete(:id)
|
||
lookup_value = self.lookup_values.to_a.select{|i| i.id == id}.first
|
||
lookup_value = self.lookup_values.to_a.find {|i| i.id.to_i == id.to_i }
|
||
if lookup_value
|
||
mark_for_destruction = ActiveRecord::ConnectionAdapters::Column.value_to_boolean attr.delete(:_destroy)
|
||
lookup_value.attributes = attr
|
test/unit/host_test.rb | ||
---|---|---|
end
|
||
end
|
||
|
||
test "lookup_values_attributes= updates existing lookup values" do
|
||
host = FactoryGirl.create(:host, :with_puppetclass)
|
||
lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :puppetclass => host.classes.first, :overrides => {"fqdn=#{host.name}" => 'old value'})
|
||
lval = host.lookup_values.first
|
||
|
||
host.lookup_values_attributes = {'0' => {'lookup_key_id' => lkey.id.to_s, 'value' => 'new value', '_destroy' => 'false', 'id' => lval.id.to_s}}.with_indifferent_access
|
||
assert_equal 'old value', LookupValue.find(lval.id).value
|
||
|
||
host.save!
|
||
assert_equal 'new value', LookupValue.find(lval.id).value
|
||
end
|
||
|
||
test "same works for destruction of lookup keys" do
|
||
host = FactoryGirl.create(:host, :lookup_values_attributes => {"new_123456" => {"lookup_key_id" => lookup_keys(:complex).id, "value"=>"some_value", "match" => "fqdn=abc.mydomain.net"}})
|
||
lookup_value = host.lookup_values.first
|
Also available in: Unified diff
fixes #11807 - update existing lookup value when changed from nested host form