annotate .svn/pristine/92/929002b516dc5d82c7d3b223bcd28e93bb353f29.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 2
Chris@1296 3 class ProjectEnumerationsControllerTest < ActionController::TestCase
Chris@1296 4 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@1296 5 :enumerations, :users, :issue_categories,
Chris@1296 6 :projects_trackers,
Chris@1296 7 :roles,
Chris@1296 8 :member_roles,
Chris@1296 9 :members,
Chris@1296 10 :enabled_modules,
Chris@1296 11 :workflows,
Chris@1296 12 :custom_fields, :custom_fields_projects,
Chris@1296 13 :custom_fields_trackers, :custom_values,
Chris@1296 14 :time_entries
Chris@1296 15
Chris@1296 16 self.use_transactional_fixtures = false
Chris@1296 17
Chris@1296 18 def setup
Chris@1296 19 @request.session[:user_id] = nil
Chris@1296 20 Setting.default_language = 'en'
Chris@1296 21 end
Chris@1296 22
Chris@1296 23 def test_update_to_override_system_activities
Chris@1296 24 @request.session[:user_id] = 2 # manager
Chris@1296 25 billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
Chris@1296 26
Chris@1296 27 put :update, :project_id => 1, :enumerations => {
Chris@1296 28 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
Chris@1296 29 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
Chris@1296 30 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value
Chris@1296 31 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes
Chris@1296 32 }
Chris@1296 33
Chris@1296 34 assert_response :redirect
Chris@1296 35 assert_redirected_to '/projects/ecookbook/settings/activities'
Chris@1296 36
Chris@1296 37 # Created project specific activities...
Chris@1296 38 project = Project.find('ecookbook')
Chris@1296 39
Chris@1296 40 # ... Design
Chris@1296 41 design = project.time_entry_activities.find_by_name("Design")
Chris@1296 42 assert design, "Project activity not found"
Chris@1296 43
Chris@1296 44 assert_equal 9, design.parent_id # Relate to the system activity
Chris@1296 45 assert_not_equal design.parent.id, design.id # Different records
Chris@1296 46 assert_equal design.parent.name, design.name # Same name
Chris@1296 47 assert !design.active?
Chris@1296 48
Chris@1296 49 # ... Development
Chris@1296 50 development = project.time_entry_activities.find_by_name("Development")
Chris@1296 51 assert development, "Project activity not found"
Chris@1296 52
Chris@1296 53 assert_equal 10, development.parent_id # Relate to the system activity
Chris@1296 54 assert_not_equal development.parent.id, development.id # Different records
Chris@1296 55 assert_equal development.parent.name, development.name # Same name
Chris@1296 56 assert development.active?
Chris@1296 57 assert_equal "0", development.custom_value_for(billable_field).value
Chris@1296 58
Chris@1296 59 # ... Inactive Activity
Chris@1296 60 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity")
Chris@1296 61 assert previously_inactive, "Project activity not found"
Chris@1296 62
Chris@1296 63 assert_equal 14, previously_inactive.parent_id # Relate to the system activity
Chris@1296 64 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records
Chris@1296 65 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name
Chris@1296 66 assert previously_inactive.active?
Chris@1296 67 assert_equal "1", previously_inactive.custom_value_for(billable_field).value
Chris@1296 68
Chris@1296 69 # ... QA
Chris@1296 70 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
Chris@1296 71 end
Chris@1296 72
Chris@1296 73 def test_update_will_update_project_specific_activities
Chris@1296 74 @request.session[:user_id] = 2 # manager
Chris@1296 75
Chris@1296 76 project_activity = TimeEntryActivity.new({
Chris@1296 77 :name => 'Project Specific',
Chris@1296 78 :parent => TimeEntryActivity.find(:first),
Chris@1296 79 :project => Project.find(1),
Chris@1296 80 :active => true
Chris@1296 81 })
Chris@1296 82 assert project_activity.save
Chris@1296 83 project_activity_two = TimeEntryActivity.new({
Chris@1296 84 :name => 'Project Specific Two',
Chris@1296 85 :parent => TimeEntryActivity.find(:last),
Chris@1296 86 :project => Project.find(1),
Chris@1296 87 :active => true
Chris@1296 88 })
Chris@1296 89 assert project_activity_two.save
Chris@1296 90
Chris@1296 91
Chris@1296 92 put :update, :project_id => 1, :enumerations => {
Chris@1296 93 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
Chris@1296 94 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
Chris@1296 95 }
Chris@1296 96
Chris@1296 97 assert_response :redirect
Chris@1296 98 assert_redirected_to '/projects/ecookbook/settings/activities'
Chris@1296 99
Chris@1296 100 # Created project specific activities...
Chris@1296 101 project = Project.find('ecookbook')
Chris@1296 102 assert_equal 2, project.time_entry_activities.count
Chris@1296 103
Chris@1296 104 activity_one = project.time_entry_activities.find_by_name(project_activity.name)
Chris@1296 105 assert activity_one, "Project activity not found"
Chris@1296 106 assert_equal project_activity.id, activity_one.id
Chris@1296 107 assert !activity_one.active?
Chris@1296 108
Chris@1296 109 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name)
Chris@1296 110 assert activity_two, "Project activity not found"
Chris@1296 111 assert_equal project_activity_two.id, activity_two.id
Chris@1296 112 assert !activity_two.active?
Chris@1296 113 end
Chris@1296 114
Chris@1296 115 def test_update_when_creating_new_activities_will_convert_existing_data
Chris@1296 116 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
Chris@1296 117
Chris@1296 118 @request.session[:user_id] = 2 # manager
Chris@1296 119 put :update, :project_id => 1, :enumerations => {
Chris@1296 120 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
Chris@1296 121 }
Chris@1296 122 assert_response :redirect
Chris@1296 123
Chris@1296 124 # No more TimeEntries using the system activity
Chris@1296 125 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities"
Chris@1296 126 # All TimeEntries using project activity
Chris@1296 127 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1)
Chris@1296 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"
Chris@1296 129 end
Chris@1296 130
Chris@1296 131 def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
Chris@1296 132 # TODO: Need to cause an exception on create but these tests
Chris@1296 133 # aren't setup for mocking. Just create a record now so the
Chris@1296 134 # second one is a dupicate
Chris@1296 135 parent = TimeEntryActivity.find(9)
Chris@1296 136 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
Chris@1296 137 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
Chris@1296 138
Chris@1296 139 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
Chris@1296 140 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
Chris@1296 141
Chris@1296 142 @request.session[:user_id] = 2 # manager
Chris@1296 143 put :update, :project_id => 1, :enumerations => {
Chris@1296 144 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
Chris@1296 145 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
Chris@1296 146 }
Chris@1296 147 assert_response :redirect
Chris@1296 148
Chris@1296 149 # TimeEntries shouldn't have been reassigned on the failed record
Chris@1296 150 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities"
Chris@1296 151 # TimeEntries shouldn't have been reassigned on the saved record either
Chris@1296 152 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
Chris@1296 153 end
Chris@1296 154
Chris@1296 155 def test_destroy
Chris@1296 156 @request.session[:user_id] = 2 # manager
Chris@1296 157 project_activity = TimeEntryActivity.new({
Chris@1296 158 :name => 'Project Specific',
Chris@1296 159 :parent => TimeEntryActivity.find(:first),
Chris@1296 160 :project => Project.find(1),
Chris@1296 161 :active => true
Chris@1296 162 })
Chris@1296 163 assert project_activity.save
Chris@1296 164 project_activity_two = TimeEntryActivity.new({
Chris@1296 165 :name => 'Project Specific Two',
Chris@1296 166 :parent => TimeEntryActivity.find(:last),
Chris@1296 167 :project => Project.find(1),
Chris@1296 168 :active => true
Chris@1296 169 })
Chris@1296 170 assert project_activity_two.save
Chris@1296 171
Chris@1296 172 delete :destroy, :project_id => 1
Chris@1296 173 assert_response :redirect
Chris@1296 174 assert_redirected_to '/projects/ecookbook/settings/activities'
Chris@1296 175
Chris@1296 176 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
Chris@1296 177 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id)
Chris@1296 178 end
Chris@1296 179
Chris@1296 180 def test_destroy_should_reassign_time_entries_back_to_the_system_activity
Chris@1296 181 @request.session[:user_id] = 2 # manager
Chris@1296 182 project_activity = TimeEntryActivity.new({
Chris@1296 183 :name => 'Project Specific Design',
Chris@1296 184 :parent => TimeEntryActivity.find(9),
Chris@1296 185 :project => Project.find(1),
Chris@1296 186 :active => true
Chris@1296 187 })
Chris@1296 188 assert project_activity.save
Chris@1296 189 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
Chris@1296 190 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
Chris@1296 191
Chris@1296 192 delete :destroy, :project_id => 1
Chris@1296 193 assert_response :redirect
Chris@1296 194 assert_redirected_to '/projects/ecookbook/settings/activities'
Chris@1296 195
Chris@1296 196 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
Chris@1296 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"
Chris@1296 198 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity"
Chris@1296 199 end
Chris@1296 200
Chris@1296 201 end