enterprise_test.rb
2.45 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
require File.dirname(__FILE__) + '/../test_helper'
class EnterpriseTest < Test::Unit::TestCase
fixtures :profiles, :environments, :users
def test_identifier_validation
p = Enterprise.new
p.valid?
assert p.errors.invalid?(:identifier)
p.identifier = 'with space'
p.valid?
assert p.errors.invalid?(:identifier)
p.identifier = 'áéíóú'
p.valid?
assert p.errors.invalid?(:identifier)
p.identifier = 'rightformat2007'
p.valid?
assert ! p.errors.invalid?(:identifier)
p.identifier = 'rightformat'
p.valid?
assert ! p.errors.invalid?(:identifier)
p.identifier = 'right_format'
p.valid?
assert ! p.errors.invalid?(:identifier)
end
def test_has_domains
p = Enterprise.new
assert_kind_of Array, p.domains
end
def test_belongs_to_environment_and_has_default
assert_equal Environment.default, Enterprise.create!(:name => 'my test environment', :identifier => 'mytestenvironment').environment
end
def test_cannot_rename
p1 = profiles(:johndoe)
assert_raise ArgumentError do
p1.identifier = 'bli'
end
end
should 'remove products when removing enterprise' do
e = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise')
e.products.build(:name => 'One product').save!
e.products.build(:name => 'Another product').save!
assert_difference Product, :count, -2 do
e.destroy
end
end
should 'get a default homepage and RSS feed' do
enterprise = Enterprise.create!(:name => 'my test enterprise', :identifier => 'myenterprise')
assert_kind_of Article, enterprise.home_page
assert_kind_of RssFeed, enterprise.articles.find_by_path('feed')
end
should 'create default set of blocks' do
e = Enterprise.create!(:name => 'my new community', :identifier => 'mynewcommunity')
assert e.boxes[0].blocks.map(&:class).include?(MainBlock), 'enterprise must have a MainBlock upon creation'
assert e.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock), 'enterprise must have a ProfileInfoBlock upon creation'
assert e.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock), 'enterprise must have a RecentDocumentsBlock upon creation'
assert e.boxes[2].blocks.map(&:class).include?(MembersBlock), 'enterprise must have a MembersBlock upon creation'
assert e.boxes[2].blocks.map(&:class).include?(TagsBlock), 'enterprise must have a TagsBlock upon creation'
assert_equal 5, e.blocks.size
end
end