Revision 6f9e04c9
Added by Joseph Magen over 11 years ago
- ID 6f9e04c913856c3adbc02010ce7a9e187ed2682b
test/unit/organization_test.rb | ||
---|---|---|
organization = Organization.new :name => "organization1"
|
||
assert organization.to_s == "Organization1"
|
||
end
|
||
|
||
test 'organization is invalid without any taxable_taxonomies' do
|
||
# no taxable_taxonomies in fixtures
|
||
# no ignore_types in fixtures
|
||
organization = taxonomies(:organization1)
|
||
assert !organization.valid?
|
||
end
|
||
|
||
test 'organization is valid if ignore all types' do
|
||
organization = taxonomies(:organization1)
|
||
organization.location_ids = [taxonomies(:location1).id]
|
||
organization.ignore_types = ["Domain", "Hostgroup", "Environment", "User", "Medium", "Subnet", "SmartProxy", "ConfigTemplate", "ComputeResource"]
|
||
assert organization.valid?
|
||
end
|
||
|
||
test 'organization is valid after fixture mismatches' do
|
||
organization = taxonomies(:organization1)
|
||
Taxonomy.all_import_missing_ids
|
||
assert organization.valid?
|
||
end
|
||
|
||
test 'it should return array of used ids by hosts' do
|
||
organization = taxonomies(:organization1)
|
||
# run used_ids method
|
||
used_ids = organization.used_ids
|
||
# get results from Host object
|
||
environment_ids = Host.where(:organization_id => organization.id).pluck(:environment_id).compact.uniq
|
||
hostgroup_ids = Host.where(:organization_id => organization.id).pluck(:hostgroup_id).compact.uniq
|
||
subnet_ids = Host.where(:organization_id => organization.id).pluck(:subnet_id).compact.uniq
|
||
domain_ids = Host.where(:organization_id => organization.id).pluck(:domain_id).compact.uniq
|
||
medium_ids = Host.where(:organization_id => organization.id).pluck(:medium_id).compact.uniq
|
||
compute_resource_ids = Host.where(:organization_id => organization.id).pluck(:compute_resource_id).compact.uniq
|
||
user_ids = Host.where(:organization_id => organization.id).where(:owner_type => 'User').pluck(:owner_id).compact.uniq
|
||
smart_proxy_ids = Host.where(:organization_id => organization.id).map {|host| host.smart_proxies.map(&:id)}.flatten.compact.uniq
|
||
config_template_ids = Host.where("organization_id = #{organization.id} and operatingsystem_id > 0").map {|host| host.configTemplate.try(:id)}.compact.uniq
|
||
# match to above retrieved data
|
||
assert_equal used_ids[:environment_ids], environment_ids
|
||
assert_equal used_ids[:hostgroup_ids], hostgroup_ids
|
||
assert_equal used_ids[:subnet_ids], subnet_ids
|
||
assert_equal used_ids[:domain_ids], domain_ids
|
||
assert_equal used_ids[:medium_ids], medium_ids
|
||
assert_equal used_ids[:compute_resource_ids], compute_resource_ids
|
||
assert_equal used_ids[:user_ids].sort, user_ids.sort
|
||
assert_equal used_ids[:smart_proxy_ids].sort, smart_proxy_ids.sort
|
||
assert_equal used_ids[:config_template_ids], config_template_ids
|
||
# match to raw fixtures data
|
||
assert_equal used_ids[:environment_ids].sort, Array(environments(:production).id).sort
|
||
assert_equal used_ids[:hostgroup_ids].sort, Array.new
|
||
assert_equal used_ids[:subnet_ids].sort, Array(subnets(:one).id).sort
|
||
assert_equal used_ids[:domain_ids].sort, Array(domains(:mydomain).id).sort
|
||
assert_equal used_ids[:medium_ids].sort, Array.new
|
||
assert_equal used_ids[:compute_resource_ids].sort, Array(compute_resources(:one).id).sort
|
||
assert_equal used_ids[:user_ids], Array.new
|
||
assert_equal used_ids[:smart_proxy_ids].sort, Array([smart_proxies(:one).id, smart_proxies(:two).id, smart_proxies(:three).id, smart_proxies(:puppetmaster).id]).sort
|
||
assert_equal used_ids[:config_template_ids].sort, Array(config_templates(:mystring2).id).sort
|
||
end
|
||
|
||
test 'it should return selected_ids array of selected values only (when types are not ignored)' do
|
||
organization = taxonomies(:organization1)
|
||
#fixtures for taxable_taxonomies don't work, on has_many :through polymorphic
|
||
# so I created assocations here.
|
||
organization.subnet_ids = Array(subnets(:one).id)
|
||
organization.smart_proxy_ids = Array(smart_proxies(:puppetmaster).id)
|
||
# run selected_ids method
|
||
selected_ids = organization.selected_ids
|
||
# get results from taxable_taxonomies
|
||
environment_ids = organization.environments.pluck(:id)
|
||
hostgroup_ids = organization.hostgroups.pluck(:id)
|
||
subnet_ids = organization.subnets.pluck(:id)
|
||
domain_ids = organization.domains.pluck(:id)
|
||
medium_ids = organization.media.pluck(:id)
|
||
user_ids = organization.users.pluck(:id)
|
||
smart_proxy_ids = organization.smart_proxies.pluck(:id)
|
||
config_template_ids = organization.config_templates.pluck(:id)
|
||
compute_resource_ids = organization.compute_resources.pluck(:id)
|
||
# check if they match
|
||
assert_equal selected_ids[:environment_ids], environment_ids
|
||
assert_equal selected_ids[:hostgroup_ids], hostgroup_ids
|
||
assert_equal selected_ids[:subnet_ids], subnet_ids
|
||
assert_equal selected_ids[:domain_ids], domain_ids
|
||
assert_equal selected_ids[:medium_ids], medium_ids
|
||
assert_equal selected_ids[:user_ids], user_ids
|
||
assert_equal selected_ids[:smart_proxy_ids], smart_proxy_ids
|
||
assert_equal selected_ids[:config_template_ids], config_template_ids
|
||
assert_equal selected_ids[:compute_resource_ids], compute_resource_ids
|
||
# match to manually generated taxable_taxonomies
|
||
assert_equal selected_ids[:environment_ids], Array.new
|
||
assert_equal selected_ids[:hostgroup_ids], Array.new
|
||
assert_equal selected_ids[:subnet_ids].sort, Array(subnets(:one).id)
|
||
assert_equal selected_ids[:domain_ids], Array.new
|
||
assert_equal selected_ids[:medium_ids], Array.new
|
||
assert_equal selected_ids[:user_ids], Array.new
|
||
assert_equal selected_ids[:smart_proxy_ids].sort, Array(smart_proxies(:puppetmaster).id)
|
||
assert_equal selected_ids[:config_template_ids], Array.new
|
||
assert_equal selected_ids[:compute_resource_ids], Array.new
|
||
end
|
||
|
||
test 'it should return selected_ids array of ALL values (when types are ignored)' do
|
||
organization = taxonomies(:organization1)
|
||
# ignore all types
|
||
organization.ignore_types = ["Domain", "Hostgroup", "Environment", "User", "Medium", "Subnet", "SmartProxy", "ConfigTemplate", "ComputeResource"]
|
||
# run selected_ids method
|
||
selected_ids = organization.selected_ids
|
||
# should return empty [] for array
|
||
assert_equal selected_ids[:environment_ids], Array.new
|
||
assert_equal selected_ids[:hostgroup_ids], Array.new
|
||
assert_equal selected_ids[:subnet_ids], Array.new
|
||
assert_equal selected_ids[:domain_ids], Array.new
|
||
assert_equal selected_ids[:medium_ids], Array.new
|
||
assert_equal selected_ids[:user_ids], Array.new
|
||
assert_equal selected_ids[:smart_proxy_ids], Array.new
|
||
assert_equal selected_ids[:config_template_ids], Array.new
|
||
assert_equal selected_ids[:compute_resource_ids], Array.new
|
||
end
|
||
|
||
end
|
Also available in: Unified diff
changes to taxonomies_controller