Commit db1d2a295dfd02c2332f9ef958c912af2731a395
1 parent
f28c05e6
Exists in
master
and in
29 other branches
ActionItem0: making unit test of manage_template plugin
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@85 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
114 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,62 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class BlockTest < Test::Unit::TestCase | |
4 | + fixtures :blocks, :profiles | |
5 | + | |
6 | + def setup | |
7 | + @profile = Profile.find(1) | |
8 | + end | |
9 | + | |
10 | + def test_setup_assumptions | |
11 | + assert @profile.valid? | |
12 | + end | |
13 | + | |
14 | + # Replace this with your real tests. | |
15 | + def test_create | |
16 | + count = Block.count | |
17 | + b = Block.new | |
18 | + assert !b.valid? | |
19 | + assert b.errors.invalid?(:box_id) | |
20 | + assert b.errors.invalid?(:position) | |
21 | + | |
22 | + box = Box.new | |
23 | + box.owner = @profile | |
24 | + box.number = 1000 | |
25 | + assert box.save | |
26 | + b.box = box | |
27 | + assert !b.valid? | |
28 | + assert b.errors.invalid?(:position) | |
29 | + | |
30 | + b.position=1 | |
31 | + assert b.save | |
32 | + | |
33 | + assert_equal count + 1, Block.count | |
34 | + end | |
35 | + | |
36 | + def test_box_presence | |
37 | + b = Block.new | |
38 | + b.position = 1000 | |
39 | + assert !b.valid? | |
40 | + assert b.errors.invalid?(:box_id) | |
41 | + | |
42 | + box = Box.new | |
43 | + box.owner = @profiles | |
44 | + box.number = 1000 | |
45 | + assert box.save | |
46 | + b.box = box | |
47 | + assert b.valid? | |
48 | + | |
49 | + end | |
50 | + | |
51 | + def test_destroy | |
52 | + b = Block.find(1) | |
53 | + assert b.destroy | |
54 | + end | |
55 | + | |
56 | + def test_valid_fixtures | |
57 | + Block.find(:all).each do |b| | |
58 | + assert b.valid? | |
59 | + end | |
60 | + end | |
61 | + | |
62 | +end | ... | ... |
... | ... | @@ -0,0 +1,52 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class BoxTest < Test::Unit::TestCase | |
4 | + fixtures :boxes, :blocks | |
5 | + | |
6 | + def test_destroy | |
7 | + count = Box.count | |
8 | + assert Box.find(1).destroy | |
9 | + assert_equal count - 1, Box.count | |
10 | + end | |
11 | + | |
12 | + def test_create | |
13 | + count = Box.count | |
14 | + b = Box.new | |
15 | + b.number = 2 | |
16 | + assert b.save | |
17 | + assert count + 1, Box.count | |
18 | + end | |
19 | + | |
20 | + | |
21 | + def test_number_format | |
22 | + b = Box.new | |
23 | + b.number = "none" | |
24 | + assert !b.valid? | |
25 | + assert b.errors.invalid?(:number) | |
26 | + | |
27 | + b = Box.new | |
28 | + b.number = 10.2 | |
29 | + assert !b.save | |
30 | + | |
31 | + b = Box.new | |
32 | + b.number = 10 | |
33 | + assert b.save | |
34 | + | |
35 | + end | |
36 | + | |
37 | + def test_unique_number | |
38 | + assert Box.delete_all | |
39 | + assert Box.create(:number => 1) | |
40 | + | |
41 | + b = Box.new(:number => 1) | |
42 | + assert !b.valid? | |
43 | + assert b.errors.invalid?(:number) | |
44 | + end | |
45 | + | |
46 | + def test_presence_number | |
47 | + b = Box.new(:number => nil) | |
48 | + assert !b.valid? | |
49 | + assert b.errors.invalid?(:number) | |
50 | + end | |
51 | + | |
52 | +end | ... | ... |