Defect #29622 » 29622.patch
| app/models/issue.rb | ||
|---|---|---|
|
end
|
||
|
def after_project_change
|
||
|
# Update project_id on related time entries
|
||
|
TimeEntry.where({:issue_id => id}).update_all(["project_id = ?", project_id])
|
||
|
# Update project_id and activity_id on related time entries
|
||
|
activities = project.activities
|
||
|
time_entries.each do |time_entry|
|
||
|
curr_activity = time_entry.activity
|
||
|
curr_activity_id = (curr_activity.parent_id || curr_activity.id)
|
||
|
new_activity =
|
||
|
activities.detect do |activity|
|
||
|
activity.id == curr_activity_id || activity.parent_id == curr_activity_id
|
||
|
end
|
||
|
time_entry.project = project
|
||
|
time_entry.activity = new_activity unless curr_activity == new_activity
|
||
|
unless time_entry.save
|
||
|
errors.add(
|
||
|
:base,
|
||
|
l(:error_move_of_time_entries_not_possible,
|
||
|
:id => "##{time_entry.id}",
|
||
|
:errors => time_entry.errors.full_messages.join(", "))
|
||
|
)
|
||
|
raise ActiveRecord::Rollback
|
||
|
end
|
||
|
end
|
||
|
# Delete issue relations
|
||
|
unless Setting.cross_project_issue_relations?
|
||
| config/locales/en.yml | ||
|---|---|---|
|
error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue"
|
||
|
error_no_projects_with_tracker_allowed_for_new_issue: "There are no projects with trackers for which you can create an issue"
|
||
|
error_move_of_child_not_possible: "Subtask %{child} could not be moved to the new project: %{errors}"
|
||
|
error_move_of_time_entries_not_possible: "Spent time %{id} could not be moved to the new project: %{errors}"
|
||
|
error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: "Spent time cannot be reassigned to an issue that is about to be deleted"
|
||
|
warning_fields_cleared_on_bulk_edit: "Changes will result in the automatic deletion of values from one or more fields on the selected objects"
|
||
|
error_exceeds_maximum_hours_per_day: "Cannot log more than %{max_hours} hours on the same day (%{logged_hours} hours have already been logged)"
|
||
| test/unit/issue_test.rb | ||
|---|---|---|
|
issue.save!
|
||
|
end
|
||
|
def test_after_project_change_should_update_project_and_activity_of_time_entries
|
||
|
time_entry = TimeEntry.find(3)
|
||
|
assert_equal [1, 9], [time_entry.project_id, time_entry.activity_id]
|
||
|
activity = TimeEntryActivity.create!(:name => 'Design', :parent_id => 9, :project_id => 3)
|
||
|
issue = Issue.find(3)
|
||
|
issue.project = Project.find(3)
|
||
|
assert issue.save
|
||
|
time_entry.reload
|
||
|
assert_equal [3, activity.id], [time_entry.project_id, time_entry.activity_id]
|
||
|
end
|
||
|
def test_after_project_change_should_not_update_project_and_activity_of_time_entries_when_activity_is_inactive
|
||
|
time_entry = TimeEntry.find(3)
|
||
|
assert_equal [1, 9], [time_entry.project_id, time_entry.activity_id]
|
||
|
TimeEntryActivity.create!(:name => 'Design', :active => false, :parent_id => 9, :project_id => 3)
|
||
|
issue = Issue.find(3)
|
||
|
issue.project = Project.find(3)
|
||
|
assert !issue.save
|
||
|
assert_match /\ASpent time #3 could not be moved to the new project:/, issue.errors.full_messages.first
|
||
|
time_entry.reload
|
||
|
assert_equal [1, 9], [time_entry.project_id, time_entry.activity_id]
|
||
|
end
|
||
|
def test_adding_journal_should_update_timestamp
|
||
|
issue = Issue.find(1)
|
||
|
updated_on_was = issue.updated_on
|
||
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »