Project

General

Profile

Download (1.27 KB) Statistics
| Branch: | Tag: | Revision:
6e50fa1d Ohad Levy
require 'test_helper'

class EnvironmentTest < ActiveSupport::TestCase
ae4998bc Tomer Brisker
def setup
Environment.all.each do |e| #because we load from fixtures, counters aren't updated
Environment.reset_counters(e.id,:hosts)
Environment.reset_counters(e.id,:hostgroups)
end
end

33dc2d19 Juan Manuel
test "should have name" do
213312e9 Lucas Tolchinsky
env = Environment.new
33dc2d19 Juan Manuel
assert !env.valid?
6e50fa1d Ohad Levy
end
213312e9 Lucas Tolchinsky
33dc2d19 Juan Manuel
test "name should be unique" do
0fe147c7 Joseph Mitchell Magen
as_admin do
env = Environment.create :name => "foo"
env2 = Environment.new :name => env.name
assert !env2.valid?
end
33dc2d19 Juan Manuel
end
213312e9 Lucas Tolchinsky
a675da90 Lucas Tolchinsky
test "to_label should print name" do
env = Environment.new :name => "foo"
a989a617 Ohad Levy
assert_equal env.to_label, env.name
a675da90 Lucas Tolchinsky
end

test "to_s should print name" do
env = Environment.new :name => "foo"
a989a617 Ohad Levy
assert_equal env.to_s, env.name
a675da90 Lucas Tolchinsky
end

6895854c Stephen Benjamin
test "should update hosts_count" do
environment = environments(:testing)
assert_difference "environment.hosts_count" do
e14b5758 Greg Sutcliffe
FactoryGirl.create(:host).update_attribute(:environment, environment)
6895854c Stephen Benjamin
environment.reload
end
end

test "should update hostgroups_count" do
environment = environments(:testing)
assert_difference "environment.hostgroups_count" do
hostgroups(:common).update_attribute(:environment, environment)
environment.reload
end
end
6e50fa1d Ohad Levy
end