diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index f2d8e3873..7b134292d 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -90,8 +90,15 @@ class TrackersController < ApplicationController @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 diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb index f3f614198..db8df2248 100644 --- a/test/functional/trackers_controller_test.rb +++ b/test/functional/trackers_controller_test.rb @@ -273,20 +273,28 @@ class TrackersControllerTest < Redmine::ControllerTest 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{}, 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{}, flash[:error] end def test_get_fields