foreman/test/unit/architecture_test.rb @ 783fb4aa
a393106d | Ohad Levy | require 'test_helper'
|
|
class ArchitectureTest < ActiveSupport::TestCase
|
|||
9fd7478e | Paul Kelly | setup do
|
|
e07f9a12 | Dominic Cleal | User.current = users :admin
|
|
ae4998bc | Tomer Brisker | Architecture.all.each do |a| #because we load from fixtures, counters aren't updated
|
|
Architecture.reset_counters(a.id,:hosts)
|
|||
Architecture.reset_counters(a.id,:hostgroups)
|
|||
end
|
|||
9fd7478e | Paul Kelly | end
|
|
ae4998bc | Tomer Brisker | ||
3de556e1 | Lucas Tolchinsky | test "should not save without a name" do
|
|
935612ab | Lucas Tolchinsky | architecture = Architecture.new
|
|
acfbc458 | Marek Hulan | assert_not architecture.save
|
|
3de556e1 | Lucas Tolchinsky | end
|
|
6b9aeb72 | Lucas Tolchinsky | test "name should not be blank" do
|
|
architecture = Architecture.new :name => " "
|
|||
acfbc458 | Marek Hulan | assert_empty architecture.name.strip
|
|
assert_not architecture.save
|
|||
6b9aeb72 | Lucas Tolchinsky | end
|
|
0539f427 | Lucas Tolchinsky | test "name should be unique" do
|
|
architecture = Architecture.new :name => "i386"
|
|||
assert architecture.save
|
|||
other_architecture = Architecture.new :name => "i386"
|
|||
acfbc458 | Marek Hulan | assert_not other_architecture.save
|
|
0539f427 | Lucas Tolchinsky | end
|
|
1e6a9256 | Lucas Tolchinsky | test "to_s retrives name" do
|
|
architecture = Architecture.new :name => "i386"
|
|||
assert architecture.to_s == architecture.name
|
|||
a393106d | Ohad Levy | end
|
|
1e4b330b | Lucas Tolchinsky | ||
6895854c | Stephen Benjamin | test "should update hosts_count" do
|
|
arch = architectures(:sparc)
|
|||
assert_difference "arch.hosts_count" do
|
|||
e14b5758 | Greg Sutcliffe | FactoryGirl.create(:host).update_attribute(:architecture, arch)
|
|
6895854c | Stephen Benjamin | arch.reload
|
|
end
|
|||
end
|
|||
test "should update hostgroups_count" do
|
|||
arch = architectures(:sparc)
|
|||
assert_difference "arch.hostgroups_count" do
|
|||
hostgroups(:common).update_attribute(:architecture, arch)
|
|||
arch.reload
|
|||
end
|
|||
end
|
|||
1e4b330b | Lucas Tolchinsky | test "should not destroy while using" do
|
|
architecture = Architecture.new :name => "i386"
|
|||
assert architecture.save
|
|||
e14b5758 | Greg Sutcliffe | host = FactoryGirl.create(:host)
|
|
f1ff5404 | Ohad Levy | host.architecture = architecture
|
|
017e1049 | Ohad Levy | host.save(:validate => false)
|
|
1e4b330b | Lucas Tolchinsky | ||
acfbc458 | Marek Hulan | assert_not architecture.destroy
|
|
1e4b330b | Lucas Tolchinsky | end
|
|
a393106d | Ohad Levy | end
|