environment_test.rb
4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require File.dirname(__FILE__) + '/../test_helper'
class EnvironmentTest < Test::Unit::TestCase
fixtures :environments
def test_exists_default_and_it_is_unique
Environment.delete_all
vc = Environment.new(:name => 'Test Community')
vc.is_default = true
assert vc.save
vc2 = Environment.new(:name => 'Another Test Community')
vc2.is_default = true
assert !vc2.valid?
assert vc2.errors.invalid?(:is_default)
assert_equal vc, Environment.default
end
def test_acts_as_configurable
vc = Environment.new(:name => 'Testing Environment')
assert_kind_of Hash, vc.settings
vc.settings[:some_setting] = 1
assert vc.save
assert_equal 1, vc.settings[:some_setting]
end
def test_available_features
assert_kind_of Hash, Environment.available_features
end
def test_mock
assert_equal ['feature1', 'feature2', 'feature3'], Environment.available_features.keys.sort
end
def test_features
v = environments(:colivre_net)
v.enable('feature1')
assert v.enabled?('feature1')
v.disable('feature1')
assert !v.enabled?('feature1')
end
def test_enabled_features
v = environments(:colivre_net)
v.enabled_features = [ 'feature1', 'feature2' ]
assert v.enabled?('feature1') && v.enabled?('feature2') && !v.enabled?('feature3')
end
def test_enabled_features_no_features_enabled
v = environments(:colivre_net)
v.enabled_features = nil
assert !v.enabled?('feature1') && !v.enabled?('feature2') && !v.enabled?('feature3')
end
def test_name_is_mandatory
v = Environment.new
v.valid?
assert v.errors.invalid?(:name)
v.name = 'blablabla'
v.valid?
assert !v.errors.invalid?(:name)
end
def test_terms_of_use
v = Environment.new(:name => 'My test environment')
assert_nil v.terms_of_use
v.terms_of_use = 'To be part of this environment, you must accept the following terms: ...'
assert v.save
id = v.id
assert_equal 'To be part of this environment, you must accept the following terms: ...', Environment.find(id).terms_of_use
end
def test_has_terms_of_use
v = Environment.new
assert !v.has_terms_of_use?
v.terms_of_use = 'some terms of use'
assert v.has_terms_of_use?
end
def test_should_profive_flexible_template_stuff
v = Environment.new
# template
assert_nil v.flexible_template_template
v.flexible_template_template = 'bli'
assert_equal 'bli', v.flexible_template_template
# theme
assert_nil v.flexible_template_theme
v.flexible_template_theme = 'bli'
assert_equal 'bli', v.flexible_template_theme
# icon theme
assert_nil v.flexible_template_icon_theme
v.flexible_template_icon_theme = 'bli'
assert_equal 'bli', v.flexible_template_icon_theme
end
def test_should_list_top_level_categories
env = Environment.create!(:name => 'a test environment')
cat1 = Category.create!(:name => 'first category', :environment_id => env.id)
cat2 = Category.create!(:name => 'second category', :environment_id => env.id)
subcat = Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat2.id)
cats = env.top_level_categories
assert_equal 2, cats.size
assert cats.include?(cat1)
assert cats.include?(cat2)
assert !cats.include?(subcat)
end
def test_should_list_all_categories
env = Environment.create!(:name => 'a test environment')
cat1 = Category.create!(:name => 'first category', :environment_id => env.id)
cat2 = Category.create!(:name => 'second category', :environment_id => env.id)
subcat = Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat2.id)
cats = env.categories
assert_equal 3, cats.size
assert cats.include?(cat1)
assert cats.include?(cat2)
assert cats.include?(subcat)
end
should 'list displayable categories' do
env = Environment.create!(:name => 'a test environment')
cat1 = env.categories.create(:name => 'category one', :display_color => 1)
assert ! cat1.new_record?
# subcategories should be ignored
subcat1 = env.categories.create(:name => 'subcategory one', :parent_id => cat1.id)
assert ! subcat1.new_record?
cat2 = env.categories.create(:name => 'category two')
assert !cat2.new_record?
assert_equal 1, env.display_categories.size
assert env.display_categories.include?(cat1)
assert !env.display_categories.include?(cat2)
end
end