Mercurial > hg > soundsoftware-site
comparison test/functional/project_enumerations_controller_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | fb9a13467253 |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
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 | |
1 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
2 | 19 |
3 class ProjectEnumerationsControllerTest < ActionController::TestCase | 20 class ProjectEnumerationsControllerTest < ActionController::TestCase |
4 fixtures :projects, :trackers, :issue_statuses, :issues, | 21 fixtures :projects, :trackers, :issue_statuses, :issues, |
5 :enumerations, :users, :issue_categories, | 22 :enumerations, :users, :issue_categories, |
6 :projects_trackers, | 23 :projects_trackers, |
7 :roles, | 24 :roles, |
8 :member_roles, | 25 :member_roles, |
9 :members, | 26 :members, |
10 :enabled_modules, | 27 :enabled_modules, |
11 :workflows, | |
12 :custom_fields, :custom_fields_projects, | 28 :custom_fields, :custom_fields_projects, |
13 :custom_fields_trackers, :custom_values, | 29 :custom_fields_trackers, :custom_values, |
14 :time_entries | 30 :time_entries |
15 | 31 |
16 self.use_transactional_fixtures = false | 32 self.use_transactional_fixtures = false |
73 def test_update_will_update_project_specific_activities | 89 def test_update_will_update_project_specific_activities |
74 @request.session[:user_id] = 2 # manager | 90 @request.session[:user_id] = 2 # manager |
75 | 91 |
76 project_activity = TimeEntryActivity.new({ | 92 project_activity = TimeEntryActivity.new({ |
77 :name => 'Project Specific', | 93 :name => 'Project Specific', |
78 :parent => TimeEntryActivity.find(:first), | 94 :parent => TimeEntryActivity.first, |
79 :project => Project.find(1), | 95 :project => Project.find(1), |
80 :active => true | 96 :active => true |
81 }) | 97 }) |
82 assert project_activity.save | 98 assert project_activity.save |
83 project_activity_two = TimeEntryActivity.new({ | 99 project_activity_two = TimeEntryActivity.new({ |
84 :name => 'Project Specific Two', | 100 :name => 'Project Specific Two', |
85 :parent => TimeEntryActivity.find(:last), | 101 :parent => TimeEntryActivity.last, |
86 :project => Project.find(1), | 102 :project => Project.find(1), |
87 :active => true | 103 :active => true |
88 }) | 104 }) |
89 assert project_activity_two.save | 105 assert project_activity_two.save |
90 | 106 |
111 assert_equal project_activity_two.id, activity_two.id | 127 assert_equal project_activity_two.id, activity_two.id |
112 assert !activity_two.active? | 128 assert !activity_two.active? |
113 end | 129 end |
114 | 130 |
115 def test_update_when_creating_new_activities_will_convert_existing_data | 131 def test_update_when_creating_new_activities_will_convert_existing_data |
116 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size | 132 assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count |
117 | 133 |
118 @request.session[:user_id] = 2 # manager | 134 @request.session[:user_id] = 2 # manager |
119 put :update, :project_id => 1, :enumerations => { | 135 put :update, :project_id => 1, :enumerations => { |
120 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate | 136 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate |
121 } | 137 } |
122 assert_response :redirect | 138 assert_response :redirect |
123 | 139 |
124 # No more TimeEntries using the system activity | 140 # No more TimeEntries using the system activity |
125 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities" | 141 assert_equal 0, TimeEntry.where(:activity_id => 9, :project_id => 1).count, |
142 "Time Entries still assigned to system activities" | |
126 # All TimeEntries using project activity | 143 # All TimeEntries using project activity |
127 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) | 144 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) |
128 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity" | 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" | |
129 end | 148 end |
130 | 149 |
131 def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised | 150 def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised |
132 # TODO: Need to cause an exception on create but these tests | 151 # TODO: Need to cause an exception on create but these tests |
133 # aren't setup for mocking. Just create a record now so the | 152 # aren't setup for mocking. Just create a record now so the |
134 # second one is a dupicate | 153 # second one is a dupicate |
135 parent = TimeEntryActivity.find(9) | 154 parent = TimeEntryActivity.find(9) |
136 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true}) | 155 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, |
137 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) | 156 :position => parent.position, :active => true}) |
138 | 157 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), |
139 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size | 158 :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) |
140 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size | 159 assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count |
141 | 160 assert_equal 1, TimeEntry.where(:activity_id => 10, :project_id => 1).count |
142 @request.session[:user_id] = 2 # manager | 161 |
143 put :update, :project_id => 1, :enumerations => { | 162 @request.session[:user_id] = 2 # manager |
144 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design | 163 put :update, :project_id => 1, :enumerations => { |
145 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value | 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"} | |
146 } | 168 } |
147 assert_response :redirect | 169 assert_response :redirect |
148 | 170 |
149 # TimeEntries shouldn't have been reassigned on the failed record | 171 # TimeEntries shouldn't have been reassigned on the failed record |
150 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities" | 172 assert_equal 3, TimeEntry.where(:activity_id => 9, |
173 :project_id => 1).count | |
174 "Time Entries are not assigned to system activities" | |
151 # TimeEntries shouldn't have been reassigned on the saved record either | 175 # TimeEntries shouldn't have been reassigned on the saved record either |
152 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" | 176 assert_equal 1, TimeEntry.where(:activity_id => 10, |
177 :project_id => 1).count | |
178 "Time Entries are not assigned to system activities" | |
153 end | 179 end |
154 | 180 |
155 def test_destroy | 181 def test_destroy |
156 @request.session[:user_id] = 2 # manager | 182 @request.session[:user_id] = 2 # manager |
157 project_activity = TimeEntryActivity.new({ | 183 project_activity = TimeEntryActivity.new({ |
158 :name => 'Project Specific', | 184 :name => 'Project Specific', |
159 :parent => TimeEntryActivity.find(:first), | 185 :parent => TimeEntryActivity.first, |
160 :project => Project.find(1), | 186 :project => Project.find(1), |
161 :active => true | 187 :active => true |
162 }) | 188 }) |
163 assert project_activity.save | 189 assert project_activity.save |
164 project_activity_two = TimeEntryActivity.new({ | 190 project_activity_two = TimeEntryActivity.new({ |
165 :name => 'Project Specific Two', | 191 :name => 'Project Specific Two', |
166 :parent => TimeEntryActivity.find(:last), | 192 :parent => TimeEntryActivity.last, |
167 :project => Project.find(1), | 193 :project => Project.find(1), |
168 :active => true | 194 :active => true |
169 }) | 195 }) |
170 assert project_activity_two.save | 196 assert project_activity_two.save |
171 | 197 |
184 :parent => TimeEntryActivity.find(9), | 210 :parent => TimeEntryActivity.find(9), |
185 :project => Project.find(1), | 211 :project => Project.find(1), |
186 :active => true | 212 :active => true |
187 }) | 213 }) |
188 assert project_activity.save | 214 assert project_activity.save |
189 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) | 215 assert TimeEntry.where(["project_id = ? AND activity_id = ?", 1, 9]). |
190 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size | 216 update_all("activity_id = '#{project_activity.id}'") |
191 | 217 assert_equal 3, TimeEntry.where(:activity_id => project_activity.id, |
218 :project_id => 1).count | |
192 delete :destroy, :project_id => 1 | 219 delete :destroy, :project_id => 1 |
193 assert_response :redirect | 220 assert_response :redirect |
194 assert_redirected_to '/projects/ecookbook/settings/activities' | 221 assert_redirected_to '/projects/ecookbook/settings/activities' |
195 | 222 |
196 assert_nil TimeEntryActivity.find_by_id(project_activity.id) | 223 assert_nil TimeEntryActivity.find_by_id(project_activity.id) |
197 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" | 224 assert_equal 0, TimeEntry.where( |
198 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" | 225 :activity_id => project_activity.id, |
199 end | 226 :project_id => 1 |
200 | 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 | |
201 end | 235 end |