foreman/test/unit/domain_test.rb @ 783fb4aa
950ddeb3 | Ohad Levy | require 'test_helper'
|
|
class DomainTest < ActiveSupport::TestCase
|
|||
f111e0da | José Luis Escalante | def setup
|
|
43c4bd72 | Marek Hulan | disable_orchestration
|
|
9fd7478e | Paul Kelly | User.current = users(:admin)
|
|
f111e0da | José Luis Escalante | @new_domain = Domain.new
|
|
06823dc7 | Ohad Levy | @domain = domains(:mydomain)
|
|
ae4998bc | Tomer Brisker | Domain.all.each do |d| #because we load from fixtures, counters aren't updated
|
|
Domain.reset_counters(d.id,:hostgroups)
|
|||
end
|
|||
f111e0da | José Luis Escalante | end
|
|
c6eee281 | Ohad Levy | test "should not save without a name" do
|
|
f111e0da | José Luis Escalante | assert !@new_domain.save
|
|
end
|
|||
test "should exists a unique name" do
|
|||
06823dc7 | Ohad Levy | other_domain = Domain.new(:name => "mydomain.net")
|
|
f111e0da | José Luis Escalante | assert !other_domain.save
|
|
end
|
|||
test "should exists a unique fullname" do
|
|||
@domain.fullname = "full_name"
|
|||
@domain.save
|
|||
other_domain = Domain.new(:name => "otherDomain", :fullname => "full_name")
|
|||
assert !other_domain.save
|
|||
end
|
|||
test "when cast to string should return the name" do
|
|||
s = @domain.to_s
|
|||
assert_equal @domain.name, s
|
|||
end
|
|||
4717b0ea | Ori Rabin | test "should remove leading and trailing dot from name" do
|
|
other_domain = Domain.new(:name => ".otherDomain.", :fullname => "full_name")
|
|||
assert other_domain.valid?
|
|||
other_domain.save
|
|||
assert_equal "otherDomain", other_domain.name
|
|||
end
|
|||
9fd7478e | Paul Kelly | test "should not destroy if it contains hosts" do
|
|
a6f4f5f7 | Ohad Levy | disable_orchestration
|
|
06823dc7 | Ohad Levy | host = create_a_host
|
|
assert host.save
|
|||
f111e0da | José Luis Escalante | ||
9fd7478e | Paul Kelly | domain = host.domain
|
|
assert !domain.destroy
|
|||
assert_match /is used by/, domain.errors.full_messages.join("\n")
|
|||
end
|
|||
f111e0da | José Luis Escalante | ||
9fd7478e | Paul Kelly | test "should not destroy if it contains subnets" do
|
|
fc2ddea7 | David Swift | @domain.subnets.clear
|
|
feacea35 | Amos Benari | assert @domain.subnets.empty?
|
|
@domain.subnets << Subnet.first
|
|||
9fd7478e | Paul Kelly | assert !@domain.destroy
|
|
assert_match /is used by/, @domain.errors.full_messages.join("\n")
|
|||
f111e0da | José Luis Escalante | end
|
|
10139fde | José Luis Escalante | ||
611f5bff | Amos Benari | test "domain can be assigned to locations" do
|
|
location1 = Location.create :name => "Zurich"
|
|||
assert location1.save!
|
|||
location2 = Location.create :name => "Switzerland"
|
|||
assert location2.save!
|
|||
domain = Domain.create :name => "test.net"
|
|||
4e057da2 | Joseph Mitchell Magen | domain.locations.destroy_all
|
|
611f5bff | Amos Benari | domain.locations.push location1
|
|
domain.locations.push location2
|
|||
assert domain.save!
|
|||
end
|
|||
6895854c | Stephen Benjamin | test "should update hosts_count" do
|
|
domain = domains(:yourdomain)
|
|||
assert_difference "domain.hosts_count" do
|
|||
e14b5758 | Greg Sutcliffe | FactoryGirl.create(:host).update_attribute(:domain, domain)
|
|
6895854c | Stephen Benjamin | domain.reload
|
|
end
|
|||
end
|
|||
ae4998bc | Tomer Brisker | test "should update hosts_count on domain_id change" do
|
|
domain = domains(:yourdomain)
|
|||
assert_difference "domain.hosts_count" do
|
|||
43c4bd72 | Marek Hulan | host = FactoryGirl.create(:host, :managed, :ip => '127.0.0.1')
|
|
primary = host.primary_interface
|
|||
primary.domain = domain
|
|||
primary.host.overwrite = true
|
|||
assert primary.save
|
|||
ae4998bc | Tomer Brisker | domain.reload
|
|
end
|
|||
end
|
|||
6895854c | Stephen Benjamin | test "should update hostgroups_count" do
|
|
domain = domains(:yourdomain)
|
|||
assert_difference "domain.hostgroups_count" do
|
|||
hostgroups(:common).update_attribute(:domain, domain)
|
|||
domain.reload
|
|||
end
|
|||
end
|
|||
10139fde | José Luis Escalante | #I must find out how to create a fact_name inside of fact_value
|
|
# test "should counts how many times a fact value exists in this domain" do
|
|||
# host = create_a_host
|
|||
# host.fact_values = FactValue.create(:fact_name)
|
|||
# end
|
|||
def create_a_host
|
|||
43c4bd72 | Marek Hulan | FactoryGirl.create(:host, :domain => FactoryGirl.build(:domain))
|
|
9fd7478e | Paul Kelly | end
|
|
1f03a563 | Ohad Levy | test "should query local nameservers when enabled" do
|
|
Setting['query_local_nameservers'] = true
|
|||
assert Domain.first.nameservers.empty?
|
|||
end
|
|||
test "should query remote nameservers" do
|
|||
assert Domain.first.nameservers.empty?
|
|||
end
|
|||
1fa008a4 | Joseph Magen | ||
# test taxonomix methods
|
|||
test "should get used location ids for host" do
|
|||
e14b5758 | Greg Sutcliffe | FactoryGirl.create(:host, :domain => domains(:mydomain), :location => taxonomies(:location1))
|
|
1fa008a4 | Joseph Magen | assert_equal [taxonomies(:location1).id], domains(:mydomain).used_location_ids
|
|
end
|
|||
test "should get used and selected location ids for host" do
|
|||
assert_equal [taxonomies(:location1).id], domains(:mydomain).used_or_selected_location_ids
|
|||
end
|
|||
950ddeb3 | Ohad Levy | end
|