diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index eb2e488f8..70e627c07 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -114,9 +114,9 @@ class IssueStatus < ApplicationRecord def check_integrity if Issue.where(:status_id => id).any? - raise "This status is used by some issues" + raise l(:error_issue_status_in_use_by_issues) elsif Tracker.where(:default_status_id => id).any? - raise "This status is used as the default status by some trackers" + raise l(:error_issue_status_default_for_trackers) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2a30a9d3a..d0d93746a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -218,6 +218,8 @@ en: error_workflow_copy_source: 'Please select a source tracker or role' error_workflow_copy_target: 'Please select target tracker(s) and role(s)' error_unable_delete_issue_status: 'Unable to delete issue status (%{value})' + error_issue_status_in_use_by_issues: "This status is used by some issues" + error_issue_status_default_for_trackers: "This status is used as the default status by some trackers" error_unable_to_connect: "Unable to connect (%{value})" error_attachments_too_many: "This file cannot be uploaded because it exceeds the maximum number of files that can be attached simultaneously (%{max_number_of_files})" error_attachment_too_big: "This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size})" diff --git a/test/unit/issue_status_test.rb b/test/unit/issue_status_test.rb index aa9629943..68a2c3ee2 100644 --- a/test/unit/issue_status_test.rb +++ b/test/unit/issue_status_test.rb @@ -46,7 +46,18 @@ class IssueStatusTest < ActiveSupport::TestCase def test_destroy_status_in_use # Status assigned to an Issue status = Issue.find(1).status - assert_raise(RuntimeError, "Cannot delete status") {status.destroy} + e = assert_raise(RuntimeError) {status.destroy} + assert_equal I18n.t(:error_issue_status_in_use_by_issues), e.message + end + + def test_destroy_status_used_as_default_by_tracker + # Status that is not used by any issue but is the default status of a tracker + status = IssueStatus.find(3) + assert_not Issue.where(:status_id => status.id).exists? + Tracker.find(1).update_column(:default_status_id, status.id) + + e = assert_raise(RuntimeError) {status.destroy} + assert_equal I18n.t(:error_issue_status_default_for_trackers), e.message end def test_new_statuses_allowed_to