Mercurial > hg > soundsoftware-site
comparison .svn/pristine/b4/b408d1debae10454b94703190c6eec2c5d068e17.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class ProjectEnumerationsControllerTest < ActionController::TestCase | |
21 fixtures :projects, :trackers, :issue_statuses, :issues, | |
22 :enumerations, :users, :issue_categories, | |
23 :projects_trackers, | |
24 :roles, | |
25 :member_roles, | |
26 :members, | |
27 :enabled_modules, | |
28 :custom_fields, :custom_fields_projects, | |
29 :custom_fields_trackers, :custom_values, | |
30 :time_entries | |
31 | |
32 self.use_transactional_fixtures = false | |
33 | |
34 def setup | |
35 @request.session[:user_id] = nil | |
36 Setting.default_language = 'en' | |
37 end | |
38 | |
39 def test_update_to_override_system_activities | |
40 @request.session[:user_id] = 2 # manager | |
41 billable_field = TimeEntryActivityCustomField.find_by_name("Billable") | |
42 | |
43 put :update, :project_id => 1, :enumerations => { | |
44 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate | |
45 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value | |
46 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value | |
47 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes | |
48 } | |
49 | |
50 assert_response :redirect | |
51 assert_redirected_to '/projects/ecookbook/settings/activities' | |
52 | |
53 # Created project specific activities... | |
54 project = Project.find('ecookbook') | |
55 | |
56 # ... Design | |
57 design = project.time_entry_activities.find_by_name("Design") | |
58 assert design, "Project activity not found" | |
59 | |
60 assert_equal 9, design.parent_id # Relate to the system activity | |
61 assert_not_equal design.parent.id, design.id # Different records | |
62 assert_equal design.parent.name, design.name # Same name | |
63 assert !design.active? | |
64 | |
65 # ... Development | |
66 development = project.time_entry_activities.find_by_name("Development") | |
67 assert development, "Project activity not found" | |
68 | |
69 assert_equal 10, development.parent_id # Relate to the system activity | |
70 assert_not_equal development.parent.id, development.id # Different records | |
71 assert_equal development.parent.name, development.name # Same name | |
72 assert development.active? | |
73 assert_equal "0", development.custom_value_for(billable_field).value | |
74 | |
75 # ... Inactive Activity | |
76 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity") | |
77 assert previously_inactive, "Project activity not found" | |
78 | |
79 assert_equal 14, previously_inactive.parent_id # Relate to the system activity | |
80 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records | |
81 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name | |
82 assert previously_inactive.active? | |
83 assert_equal "1", previously_inactive.custom_value_for(billable_field).value | |
84 | |
85 # ... QA | |
86 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified" | |
87 end | |
88 | |
89 def test_update_will_update_project_specific_activities | |
90 @request.session[:user_id] = 2 # manager | |
91 | |
92 project_activity = TimeEntryActivity.new({ | |
93 :name => 'Project Specific', | |
94 :parent => TimeEntryActivity.first, | |
95 :project => Project.find(1), | |
96 :active => true | |
97 }) | |
98 assert project_activity.save | |
99 project_activity_two = TimeEntryActivity.new({ | |
100 :name => 'Project Specific Two', | |
101 :parent => TimeEntryActivity.last, | |
102 :project => Project.find(1), | |
103 :active => true | |
104 }) | |
105 assert project_activity_two.save | |
106 | |
107 | |
108 put :update, :project_id => 1, :enumerations => { | |
109 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate | |
110 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate | |
111 } | |
112 | |
113 assert_response :redirect | |
114 assert_redirected_to '/projects/ecookbook/settings/activities' | |
115 | |
116 # Created project specific activities... | |
117 project = Project.find('ecookbook') | |
118 assert_equal 2, project.time_entry_activities.count | |
119 | |
120 activity_one = project.time_entry_activities.find_by_name(project_activity.name) | |
121 assert activity_one, "Project activity not found" | |
122 assert_equal project_activity.id, activity_one.id | |
123 assert !activity_one.active? | |
124 | |
125 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name) | |
126 assert activity_two, "Project activity not found" | |
127 assert_equal project_activity_two.id, activity_two.id | |
128 assert !activity_two.active? | |
129 end | |
130 | |
131 def test_update_when_creating_new_activities_will_convert_existing_data | |
132 assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count | |
133 | |
134 @request.session[:user_id] = 2 # manager | |
135 put :update, :project_id => 1, :enumerations => { | |
136 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate | |
137 } | |
138 assert_response :redirect | |
139 | |
140 # No more TimeEntries using the system activity | |
141 assert_equal 0, TimeEntry.where(:activity_id => 9, :project_id => 1).count, | |
142 "Time Entries still assigned to system activities" | |
143 # All TimeEntries using project activity | |
144 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) | |
145 assert_equal 3, TimeEntry.where(:activity_id => project_specific_activity.id, | |
146 :project_id => 1).count | |
147 "No Time Entries assigned to the project activity" | |
148 end | |
149 | |
150 def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised | |
151 # TODO: Need to cause an exception on create but these tests | |
152 # aren't setup for mocking. Just create a record now so the | |
153 # second one is a dupicate | |
154 parent = TimeEntryActivity.find(9) | |
155 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, | |
156 :position => parent.position, :active => true}) | |
157 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), | |
158 :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) | |
159 assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count | |
160 assert_equal 1, TimeEntry.where(:activity_id => 10, :project_id => 1).count | |
161 | |
162 @request.session[:user_id] = 2 # manager | |
163 put :update, :project_id => 1, :enumerations => { | |
164 # Design | |
165 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, | |
166 # Development, Change custom value | |
167 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} | |
168 } | |
169 assert_response :redirect | |
170 | |
171 # TimeEntries shouldn't have been reassigned on the failed record | |
172 assert_equal 3, TimeEntry.where(:activity_id => 9, | |
173 :project_id => 1).count | |
174 "Time Entries are not assigned to system activities" | |
175 # TimeEntries shouldn't have been reassigned on the saved record either | |
176 assert_equal 1, TimeEntry.where(:activity_id => 10, | |
177 :project_id => 1).count | |
178 "Time Entries are not assigned to system activities" | |
179 end | |
180 | |
181 def test_destroy | |
182 @request.session[:user_id] = 2 # manager | |
183 project_activity = TimeEntryActivity.new({ | |
184 :name => 'Project Specific', | |
185 :parent => TimeEntryActivity.first, | |
186 :project => Project.find(1), | |
187 :active => true | |
188 }) | |
189 assert project_activity.save | |
190 project_activity_two = TimeEntryActivity.new({ | |
191 :name => 'Project Specific Two', | |
192 :parent => TimeEntryActivity.last, | |
193 :project => Project.find(1), | |
194 :active => true | |
195 }) | |
196 assert project_activity_two.save | |
197 | |
198 delete :destroy, :project_id => 1 | |
199 assert_response :redirect | |
200 assert_redirected_to '/projects/ecookbook/settings/activities' | |
201 | |
202 assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
203 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | |
204 end | |
205 | |
206 def test_destroy_should_reassign_time_entries_back_to_the_system_activity | |
207 @request.session[:user_id] = 2 # manager | |
208 project_activity = TimeEntryActivity.new({ | |
209 :name => 'Project Specific Design', | |
210 :parent => TimeEntryActivity.find(9), | |
211 :project => Project.find(1), | |
212 :active => true | |
213 }) | |
214 assert project_activity.save | |
215 assert TimeEntry.where(["project_id = ? AND activity_id = ?", 1, 9]). | |
216 update_all("activity_id = '#{project_activity.id}'") | |
217 assert_equal 3, TimeEntry.where(:activity_id => project_activity.id, | |
218 :project_id => 1).count | |
219 delete :destroy, :project_id => 1 | |
220 assert_response :redirect | |
221 assert_redirected_to '/projects/ecookbook/settings/activities' | |
222 | |
223 assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
224 assert_equal 0, TimeEntry.where( | |
225 :activity_id => project_activity.id, | |
226 :project_id => 1 | |
227 ).count, | |
228 "TimeEntries still assigned to project specific activity" | |
229 assert_equal 3, TimeEntry.where( | |
230 :activity_id => 9, | |
231 :project_id => 1 | |
232 ).count, | |
233 "TimeEntries still assigned to project specific activity" | |
234 end | |
235 end |