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