Project

General

Profile

Defect #42226 » fix-tracker-deletion-error-message.patch

Go MAEDA, 2025-02-05 16:10

View differences:

app/controllers/trackers_controller.rb
@tracker = Tracker.find(params[:id])
unless @tracker.issues.empty?
projects = Project.joins(:issues).where(issues: {tracker_id: @tracker.id}).sorted.distinct
tracker_project_ids = @tracker.projects.ids.to_set
links = projects.map do |p|
view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id, status_id: '*'))
if tracker_project_ids.include?(p.id)
view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id, status_id: '*'))
else
# This tracker is not enabled in the project,
# so we can't link to the issues list
ERB::Util.html_escape(p.name)
end
end.join(', ')
flash[:error] = l(:error_can_not_delete_tracker_html, projects: links.html_safe)
else
test/functional/trackers_controller_test.rb
def test_destroy_tracker_in_use
tracker = Tracker.generate!(name: 'In use')
projects = Array.new(2) do
project1, project2 = Array.new(2) do
project = Project.generate!
Issue.generate!(project: project, tracker: tracker)
project
end
# Remove all associated trackers from project2
project2.trackers = []
project2.save!
assert_no_difference 'Tracker.count' do
delete :destroy, params: {id: tracker.id}
end
assert_redirected_to action: 'index'
assert_match /The following projects have issues with this tracker:/, flash[:error]
projects.each do |project|
assert_match /#{project.name}/, flash[:error]
end
assert_includes flash[:error], 'The following projects have issues with this tracker:'
# Ensure project1 is listed with a link to its issue list
assert_includes flash[:error], project1.name
assert_match %r{<a href=".*#{project1.identifier}.*">}, flash[:error]
# project2 should only appear as text in the error message, without a link
assert_includes flash[:error], project2.name
assert_no_match %r{<a href=".*#{project2.identifier}.*">}, flash[:error]
end
def test_get_fields
(1-1/2)