Mercurial > hg > soundsoftware-site
comparison test/functional/project_enumerations_controller_test.rb @ 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 | e248c7af89ec |
children | fb9a13467253 |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
127 assert_equal project_activity_two.id, activity_two.id | 127 assert_equal project_activity_two.id, activity_two.id |
128 assert !activity_two.active? | 128 assert !activity_two.active? |
129 end | 129 end |
130 | 130 |
131 def test_update_when_creating_new_activities_will_convert_existing_data | 131 def test_update_when_creating_new_activities_will_convert_existing_data |
132 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 |
133 | 133 |
134 @request.session[:user_id] = 2 # manager | 134 @request.session[:user_id] = 2 # manager |
135 put :update, :project_id => 1, :enumerations => { | 135 put :update, :project_id => 1, :enumerations => { |
136 "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 |
137 } | 137 } |
138 assert_response :redirect | 138 assert_response :redirect |
139 | 139 |
140 # No more TimeEntries using the system activity | 140 # No more TimeEntries using the system activity |
141 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" | |
142 # All TimeEntries using project activity | 143 # All TimeEntries using project activity |
143 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) |
144 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" | |
145 end | 148 end |
146 | 149 |
147 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 |
148 # TODO: Need to cause an exception on create but these tests | 151 # TODO: Need to cause an exception on create but these tests |
149 # 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 |
150 # second one is a dupicate | 153 # second one is a dupicate |
151 parent = TimeEntryActivity.find(9) | 154 parent = TimeEntryActivity.find(9) |
152 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true}) | 155 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, |
153 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}) |
154 | 157 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), |
155 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'}) |
156 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 |
157 | 160 assert_equal 1, TimeEntry.where(:activity_id => 10, :project_id => 1).count |
158 @request.session[:user_id] = 2 # manager | 161 |
159 put :update, :project_id => 1, :enumerations => { | 162 @request.session[:user_id] = 2 # manager |
160 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design | 163 put :update, :project_id => 1, :enumerations => { |
161 "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"} | |
162 } | 168 } |
163 assert_response :redirect | 169 assert_response :redirect |
164 | 170 |
165 # TimeEntries shouldn't have been reassigned on the failed record | 171 # TimeEntries shouldn't have been reassigned on the failed record |
166 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" | |
167 # TimeEntries shouldn't have been reassigned on the saved record either | 175 # TimeEntries shouldn't have been reassigned on the saved record either |
168 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" | |
169 end | 179 end |
170 | 180 |
171 def test_destroy | 181 def test_destroy |
172 @request.session[:user_id] = 2 # manager | 182 @request.session[:user_id] = 2 # manager |
173 project_activity = TimeEntryActivity.new({ | 183 project_activity = TimeEntryActivity.new({ |
200 :parent => TimeEntryActivity.find(9), | 210 :parent => TimeEntryActivity.find(9), |
201 :project => Project.find(1), | 211 :project => Project.find(1), |
202 :active => true | 212 :active => true |
203 }) | 213 }) |
204 assert project_activity.save | 214 assert project_activity.save |
205 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]). |
206 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}'") |
207 | 217 assert_equal 3, TimeEntry.where(:activity_id => project_activity.id, |
218 :project_id => 1).count | |
208 delete :destroy, :project_id => 1 | 219 delete :destroy, :project_id => 1 |
209 assert_response :redirect | 220 assert_response :redirect |
210 assert_redirected_to '/projects/ecookbook/settings/activities' | 221 assert_redirected_to '/projects/ecookbook/settings/activities' |
211 | 222 |
212 assert_nil TimeEntryActivity.find_by_id(project_activity.id) | 223 assert_nil TimeEntryActivity.find_by_id(project_activity.id) |
213 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( |
214 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, |
215 end | 226 :project_id => 1 |
216 | 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 | |
217 end | 235 end |