Project

General

Profile

« Previous | Next » 

Revision c6b76367

Added by Partha Aji about 8 years ago

Fixes #14166 - Host facet attributes handling updated

Basically added code to include handling of host facets in hosts where
no form attributes belonging to that facet are set.

(cherry picked from commit 5d64eef2cba8e56ad39510c3bd1d724bd52762eb)

View differences:

app/models/concerns/facets/managed_host_extensions.rb
def register_facet_relation(klass, facet_config)
klass.class_eval do
has_one facet_config.name, :class_name => facet_config.model.name, :foreign_key => :host_id, :inverse_of => :host
accepts_nested_attributes_for facet_config.name, :update_only => true
accepts_nested_attributes_for facet_config.name, :update_only => true, :reject_if => :all_blank
alias_method "#{facet_config.name}_attributes", facet_config.name
attr_accessible "#{facet_config.name}_attributes"
test/unit/facet_test.rb
assert_not_nil attributes["test_facet_attributes"]
end
end
test 'facets are updated without specifying id explicitly' do
saved_host = FactoryGirl.create(:host)
saved_host.build_test_facet
saved_host.save!
context "managed host facet behavior" do
setup do
TestFacet.class_eval do
def my_attribute
end
......
attr_accessible :my_attribute
end
saved_host.attributes = {'test_facet_attributes' => { 'my_attribute' => 'my_value'}}
Facets.register TestFacet
end
test 'facets are updated without specifying id explicitly' do
saved_host = FactoryGirl.create(:host)
saved_host.build_test_facet
saved_host.save!
saved_host.attributes = {'test_facet_attributes' => { 'my_attribute' => 'my_value'}}
assert_not_nil saved_host.test_facet.id
end
test 'facets do not get created for nil attributes and viceversa' do
saved_host = FactoryGirl.build(:host)
saved_host.update_attributes({'test_facet_attributes' => { 'my_attribute' => nil}})
assert_nil saved_host.test_facet
saved_host.update_attributes({'test_facet_attributes' => { 'my_attribute' => "val"}})
assert_not_nil saved_host.test_facet
end
end
end

Also available in: Unified diff