Revision 647b971f
Added by Ondřej Pražák about 8 years ago
app/models/host/managed.rb | ||
---|---|---|
def apply_inherited_attributes(attributes, initialized = true)
|
||
return nil unless attributes
|
||
#don't change the source to minimize side effects.
|
||
attributes = hash_clone(attributes)
|
||
attributes = hash_clone(attributes).with_indifferent_access
|
||
|
||
new_hostgroup_id = attributes['hostgroup_id'] || attributes['hostgroup_name']
|
||
new_hostgroup_id = attributes['hostgroup_id'] || attributes['hostgroup_name'] || attributes['hostgroup'].try(:id)
|
||
#hostgroup didn't change, no inheritance needs update.
|
||
return attributes if new_hostgroup_id.blank?
|
||
|
test/factories/host_related.rb | ||
---|---|---|
association :parent, :factory => :hostgroup
|
||
end
|
||
|
||
trait :with_environment do
|
||
environment
|
||
end
|
||
|
||
trait :with_puppetclass do
|
||
environment
|
||
puppetclasses { [ FactoryGirl.create(:puppetclass, :environments => [environment]) ] }
|
test/unit/host_test.rb | ||
---|---|---|
|
||
assert_equal actual_attr['zzz_id'], 1111
|
||
end
|
||
|
||
test 'should add inherited attributes when hostgroup in attributes' do
|
||
hg = FactoryGirl.create(:hostgroup, :with_environment)
|
||
host = Host.new(:name => "test-host", :hostgroup => hg)
|
||
assert host.environment
|
||
end
|
||
end
|
||
|
||
describe 'rendering interface' do
|
Also available in: Unified diff
Fixes #12936 - Host inherits attributes when hostgroup is AR object
(cherry picked from commit d7110d54ad51a85eadde8283606e88cf01de8b19)