##// END OF EJS Templates
remove empty setup method from unit enumeration test...
Toshi MARUYAMA -
r10049:a1d8cab6c652
parent child
Show More
@@ -1,133 +1,130
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class EnumerationTest < ActiveSupport::TestCase
20 class EnumerationTest < ActiveSupport::TestCase
21 fixtures :enumerations, :issues, :custom_fields, :custom_values
21 fixtures :enumerations, :issues, :custom_fields, :custom_values
22
22
23 def setup
24 end
25
26 def test_objects_count
23 def test_objects_count
27 # low priority
24 # low priority
28 assert_equal 6, Enumeration.find(4).objects_count
25 assert_equal 6, Enumeration.find(4).objects_count
29 # urgent
26 # urgent
30 assert_equal 0, Enumeration.find(7).objects_count
27 assert_equal 0, Enumeration.find(7).objects_count
31 end
28 end
32
29
33 def test_in_use
30 def test_in_use
34 # low priority
31 # low priority
35 assert Enumeration.find(4).in_use?
32 assert Enumeration.find(4).in_use?
36 # urgent
33 # urgent
37 assert !Enumeration.find(7).in_use?
34 assert !Enumeration.find(7).in_use?
38 end
35 end
39
36
40 def test_default
37 def test_default
41 e = Enumeration.default
38 e = Enumeration.default
42 assert e.is_a?(Enumeration)
39 assert e.is_a?(Enumeration)
43 assert e.is_default?
40 assert e.is_default?
44 assert e.active?
41 assert e.active?
45 assert_equal 'Default Enumeration', e.name
42 assert_equal 'Default Enumeration', e.name
46 end
43 end
47
44
48 def test_default_non_active
45 def test_default_non_active
49 e = Enumeration.find(12)
46 e = Enumeration.find(12)
50 assert e.is_a?(Enumeration)
47 assert e.is_a?(Enumeration)
51 assert e.is_default?
48 assert e.is_default?
52 assert e.active?
49 assert e.active?
53 e.update_attributes(:active => false)
50 e.update_attributes(:active => false)
54 assert e.is_default?
51 assert e.is_default?
55 assert !e.active?
52 assert !e.active?
56 end
53 end
57
54
58 def test_create
55 def test_create
59 e = Enumeration.new(:name => 'Not default', :is_default => false)
56 e = Enumeration.new(:name => 'Not default', :is_default => false)
60 e.type = 'Enumeration'
57 e.type = 'Enumeration'
61 assert e.save
58 assert e.save
62 assert_equal 'Default Enumeration', Enumeration.default.name
59 assert_equal 'Default Enumeration', Enumeration.default.name
63 end
60 end
64
61
65 def test_create_as_default
62 def test_create_as_default
66 e = Enumeration.new(:name => 'Very urgent', :is_default => true)
63 e = Enumeration.new(:name => 'Very urgent', :is_default => true)
67 e.type = 'Enumeration'
64 e.type = 'Enumeration'
68 assert e.save
65 assert e.save
69 assert_equal e, Enumeration.default
66 assert_equal e, Enumeration.default
70 end
67 end
71
68
72 def test_update_default
69 def test_update_default
73 e = Enumeration.default
70 e = Enumeration.default
74 e.update_attributes(:name => 'Changed', :is_default => true)
71 e.update_attributes(:name => 'Changed', :is_default => true)
75 assert_equal e, Enumeration.default
72 assert_equal e, Enumeration.default
76 end
73 end
77
74
78 def test_update_default_to_non_default
75 def test_update_default_to_non_default
79 e = Enumeration.default
76 e = Enumeration.default
80 e.update_attributes(:name => 'Changed', :is_default => false)
77 e.update_attributes(:name => 'Changed', :is_default => false)
81 assert_nil Enumeration.default
78 assert_nil Enumeration.default
82 end
79 end
83
80
84 def test_change_default
81 def test_change_default
85 e = Enumeration.find_by_name('Default Enumeration')
82 e = Enumeration.find_by_name('Default Enumeration')
86 e.update_attributes(:name => 'Changed Enumeration', :is_default => true)
83 e.update_attributes(:name => 'Changed Enumeration', :is_default => true)
87 assert_equal e, Enumeration.default
84 assert_equal e, Enumeration.default
88 end
85 end
89
86
90 def test_destroy_with_reassign
87 def test_destroy_with_reassign
91 Enumeration.find(4).destroy(Enumeration.find(6))
88 Enumeration.find(4).destroy(Enumeration.find(6))
92 assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
89 assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
93 assert_equal 6, Enumeration.find(6).objects_count
90 assert_equal 6, Enumeration.find(6).objects_count
94 end
91 end
95
92
96 def test_should_be_customizable
93 def test_should_be_customizable
97 assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
94 assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
98 end
95 end
99
96
100 def test_should_belong_to_a_project
97 def test_should_belong_to_a_project
101 association = Enumeration.reflect_on_association(:project)
98 association = Enumeration.reflect_on_association(:project)
102 assert association, "No Project association found"
99 assert association, "No Project association found"
103 assert_equal :belongs_to, association.macro
100 assert_equal :belongs_to, association.macro
104 end
101 end
105
102
106 def test_should_act_as_tree
103 def test_should_act_as_tree
107 enumeration = Enumeration.find(4)
104 enumeration = Enumeration.find(4)
108
105
109 assert enumeration.respond_to?(:parent)
106 assert enumeration.respond_to?(:parent)
110 assert enumeration.respond_to?(:children)
107 assert enumeration.respond_to?(:children)
111 end
108 end
112
109
113 def test_is_override
110 def test_is_override
114 # Defaults to off
111 # Defaults to off
115 enumeration = Enumeration.find(4)
112 enumeration = Enumeration.find(4)
116 assert !enumeration.is_override?
113 assert !enumeration.is_override?
117
114
118 # Setup as an override
115 # Setup as an override
119 enumeration.parent = Enumeration.find(5)
116 enumeration.parent = Enumeration.find(5)
120 assert enumeration.is_override?
117 assert enumeration.is_override?
121 end
118 end
122
119
123 def test_get_subclasses
120 def test_get_subclasses
124 classes = Enumeration.get_subclasses
121 classes = Enumeration.get_subclasses
125 assert_include IssuePriority, classes
122 assert_include IssuePriority, classes
126 assert_include DocumentCategory, classes
123 assert_include DocumentCategory, classes
127 assert_include TimeEntryActivity, classes
124 assert_include TimeEntryActivity, classes
128
125
129 classes.each do |klass|
126 classes.each do |klass|
130 assert_equal Enumeration, klass.superclass
127 assert_equal Enumeration, klass.superclass
131 end
128 end
132 end
129 end
133 end
130 end
General Comments 0
You need to be logged in to leave comments. Login now