Defect #29622 » 29622.patch
app/models/issue.rb | ||
---|---|---|
1679 | 1679 |
end |
1680 | 1680 | |
1681 | 1681 |
def after_project_change |
1682 |
# Update project_id on related time entries |
|
1683 |
TimeEntry.where({:issue_id => id}).update_all(["project_id = ?", project_id]) |
|
1682 |
# Update project_id and activity_id on related time entries |
|
1683 |
activities = project.activities |
|
1684 |
time_entries.each do |time_entry| |
|
1685 |
curr_activity = time_entry.activity |
|
1686 |
curr_activity_id = (curr_activity.parent_id || curr_activity.id) |
|
1687 |
new_activity = |
|
1688 |
activities.detect do |activity| |
|
1689 |
activity.id == curr_activity_id || activity.parent_id == curr_activity_id |
|
1690 |
end |
|
1691 | ||
1692 |
time_entry.project = project |
|
1693 |
time_entry.activity = new_activity unless curr_activity == new_activity |
|
1694 |
unless time_entry.save |
|
1695 |
errors.add( |
|
1696 |
:base, |
|
1697 |
l(:error_move_of_time_entries_not_possible, |
|
1698 |
:id => "##{time_entry.id}", |
|
1699 |
:errors => time_entry.errors.full_messages.join(", ")) |
|
1700 |
) |
|
1701 |
raise ActiveRecord::Rollback |
|
1702 |
end |
|
1703 |
end |
|
1684 | 1704 | |
1685 | 1705 |
# Delete issue relations |
1686 | 1706 |
unless Setting.cross_project_issue_relations? |
config/locales/en.yml | ||
---|---|---|
229 | 229 |
error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue" |
230 | 230 |
error_no_projects_with_tracker_allowed_for_new_issue: "There are no projects with trackers for which you can create an issue" |
231 | 231 |
error_move_of_child_not_possible: "Subtask %{child} could not be moved to the new project: %{errors}" |
232 |
error_move_of_time_entries_not_possible: "Spent time %{id} could not be moved to the new project: %{errors}" |
|
232 | 233 |
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" |
233 | 234 |
warning_fields_cleared_on_bulk_edit: "Changes will result in the automatic deletion of values from one or more fields on the selected objects" |
234 | 235 |
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 | ||
---|---|---|
1550 | 1550 |
issue.save! |
1551 | 1551 |
end |
1552 | 1552 | |
1553 |
def test_after_project_change_should_update_project_and_activity_of_time_entries |
|
1554 |
time_entry = TimeEntry.find(3) |
|
1555 |
assert_equal [1, 9], [time_entry.project_id, time_entry.activity_id] |
|
1556 | ||
1557 |
activity = TimeEntryActivity.create!(:name => 'Design', :parent_id => 9, :project_id => 3) |
|
1558 |
issue = Issue.find(3) |
|
1559 |
issue.project = Project.find(3) |
|
1560 | ||
1561 |
assert issue.save |
|
1562 | ||
1563 |
time_entry.reload |
|
1564 |
assert_equal [3, activity.id], [time_entry.project_id, time_entry.activity_id] |
|
1565 |
end |
|
1566 | ||
1567 |
def test_after_project_change_should_not_update_project_and_activity_of_time_entries_when_activity_is_inactive |
|
1568 |
time_entry = TimeEntry.find(3) |
|
1569 |
assert_equal [1, 9], [time_entry.project_id, time_entry.activity_id] |
|
1570 | ||
1571 |
TimeEntryActivity.create!(:name => 'Design', :active => false, :parent_id => 9, :project_id => 3) |
|
1572 |
issue = Issue.find(3) |
|
1573 |
issue.project = Project.find(3) |
|
1574 | ||
1575 |
assert !issue.save |
|
1576 |
assert_match /\ASpent time #3 could not be moved to the new project:/, issue.errors.full_messages.first |
|
1577 | ||
1578 |
time_entry.reload |
|
1579 |
assert_equal [1, 9], [time_entry.project_id, time_entry.activity_id] |
|
1580 |
end |
|
1581 | ||
1553 | 1582 |
def test_adding_journal_should_update_timestamp |
1554 | 1583 |
issue = Issue.find(1) |
1555 | 1584 |
updated_on_was = issue.updated_on |
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »