Commit 790354cffdf7634a0862392b7c0e98b4fe0d3e90
1 parent
5ac6e5f2
Exists in
master
and in
28 other branches
ActionItem6: Enterprise's unit test
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@204 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
61 additions
and
4 deletions
Show diff stats
app/models/enterprise.rb
1 | #A enterprise is a kind of profile. According to the system concept, only enterprises can offer priducts/services | 1 | #A enterprise is a kind of profile. According to the system concept, only enterprises can offer priducts/services |
2 | class Enterprise < Profile | 2 | class Enterprise < Profile |
3 | + | ||
4 | + validates_numericality_of :foundation_year, :only_integer => true | ||
3 | end | 5 | end |
test/unit/enterprise_test.rb
1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | ||
3 | class EnterpriseTest < Test::Unit::TestCase | 3 | class EnterpriseTest < Test::Unit::TestCase |
4 | - fixtures :profiles | 4 | + fixtures :profiles, :virtual_communities, :users |
5 | 5 | ||
6 | - # Replace this with your real tests. | ||
7 | - def test_truth | ||
8 | - assert true | 6 | + def test_identifier_validation |
7 | + p = Enterprise.new | ||
8 | + p.valid? | ||
9 | + assert p.errors.invalid?(:identifier) | ||
10 | + | ||
11 | + p.identifier = 'with space' | ||
12 | + p.valid? | ||
13 | + assert p.errors.invalid?(:identifier) | ||
14 | + | ||
15 | + p.identifier = 'áéíóú' | ||
16 | + p.valid? | ||
17 | + assert p.errors.invalid?(:identifier) | ||
18 | + | ||
19 | + p.identifier = 'rightformat2007' | ||
20 | + p.valid? | ||
21 | + assert ! p.errors.invalid?(:identifier) | ||
22 | + | ||
23 | + p.identifier = 'rightformat' | ||
24 | + p.valid? | ||
25 | + assert ! p.errors.invalid?(:identifier) | ||
26 | + | ||
27 | + p.identifier = 'right_format' | ||
28 | + p.valid? | ||
29 | + assert ! p.errors.invalid?(:identifier) | ||
30 | + end | ||
31 | + | ||
32 | + def test_has_domains | ||
33 | + p = Enterprise.new | ||
34 | + assert_kind_of Array, p.domains | ||
35 | + end | ||
36 | + | ||
37 | + def test_belongs_to_virtual_community_and_has_default | ||
38 | + p = Enterprise.new | ||
39 | + assert_kind_of VirtualCommunity, p.virtual_community | ||
9 | end | 40 | end |
41 | + | ||
42 | + def test_cannot_rename | ||
43 | + p1 = profiles(:johndoe) | ||
44 | + assert_raise ArgumentError do | ||
45 | + p1.identifier = 'bli' | ||
46 | + end | ||
47 | + end | ||
48 | + | ||
49 | + def test_numericality_year | ||
50 | + count = Enterprise.count | ||
51 | + | ||
52 | + e = Enterprise.new(:identifier => 'test_numericality_year') | ||
53 | + e.foundation_year = 'xxxx' | ||
54 | + assert ! e.save | ||
55 | + | ||
56 | + e.foundation_year = 20.07 | ||
57 | + assert ! e.save | ||
58 | + | ||
59 | + e.foundation_year = 2007 | ||
60 | + assert e.save | ||
61 | + | ||
62 | + assert count + 1, Enterprise.count | ||
63 | + end | ||
64 | + | ||
10 | end | 65 | end |