annotate .svn/pristine/2c/2caf818a4b5c04288552a4ab14703d73f1006735.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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