To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 4f / 4f68d76f852340754bcbaa389f8acdaba7e60be4.svn-base @ 1298:4f746d8966dd
History | View | Annotate | Download (10.4 KB)
| 1 | 1295:622f24f53b42 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2013 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.find_all_by_activity_id_and_project_id(9, 1).size |
||
| 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.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities" |
||
| 142 | # All TimeEntries using project activity |
||
| 143 | 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 | end |
||
| 146 | |||
| 147 | 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 |
||
| 149 | # aren't setup for mocking. Just create a record now so the |
||
| 150 | # second one is a dupicate |
||
| 151 | parent = TimeEntryActivity.find(9) |
||
| 152 | TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
|
||
| 153 | TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
|
||
| 154 | |||
| 155 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size |
||
| 156 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size |
||
| 157 | |||
| 158 | @request.session[:user_id] = 2 # manager |
||
| 159 | put :update, :project_id => 1, :enumerations => {
|
||
| 160 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
|
||
| 161 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
|
||
| 162 | } |
||
| 163 | assert_response :redirect |
||
| 164 | |||
| 165 | # 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" |
||
| 167 | # 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" |
||
| 169 | end |
||
| 170 | |||
| 171 | def test_destroy |
||
| 172 | @request.session[:user_id] = 2 # manager |
||
| 173 | project_activity = TimeEntryActivity.new({
|
||
| 174 | :name => 'Project Specific', |
||
| 175 | :parent => TimeEntryActivity.first, |
||
| 176 | :project => Project.find(1), |
||
| 177 | :active => true |
||
| 178 | }) |
||
| 179 | assert project_activity.save |
||
| 180 | project_activity_two = TimeEntryActivity.new({
|
||
| 181 | :name => 'Project Specific Two', |
||
| 182 | :parent => TimeEntryActivity.last, |
||
| 183 | :project => Project.find(1), |
||
| 184 | :active => true |
||
| 185 | }) |
||
| 186 | assert project_activity_two.save |
||
| 187 | |||
| 188 | delete :destroy, :project_id => 1 |
||
| 189 | assert_response :redirect |
||
| 190 | assert_redirected_to '/projects/ecookbook/settings/activities' |
||
| 191 | |||
| 192 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) |
||
| 193 | assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) |
||
| 194 | end |
||
| 195 | |||
| 196 | def test_destroy_should_reassign_time_entries_back_to_the_system_activity |
||
| 197 | @request.session[:user_id] = 2 # manager |
||
| 198 | project_activity = TimeEntryActivity.new({
|
||
| 199 | :name => 'Project Specific Design', |
||
| 200 | :parent => TimeEntryActivity.find(9), |
||
| 201 | :project => Project.find(1), |
||
| 202 | :active => true |
||
| 203 | }) |
||
| 204 | assert project_activity.save |
||
| 205 | assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["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 |
||
| 207 | |||
| 208 | delete :destroy, :project_id => 1 |
||
| 209 | assert_response :redirect |
||
| 210 | assert_redirected_to '/projects/ecookbook/settings/activities' |
||
| 211 | |||
| 212 | 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" |
||
| 214 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" |
||
| 215 | end |
||
| 216 | |||
| 217 | end |