Defect #42226 » fix-tracker-deletion-error-message.patch
| app/controllers/trackers_controller.rb | ||
|---|---|---|
| 90 | 90 |
@tracker = Tracker.find(params[:id]) |
| 91 | 91 |
unless @tracker.issues.empty? |
| 92 | 92 |
projects = Project.joins(:issues).where(issues: {tracker_id: @tracker.id}).sorted.distinct
|
| 93 |
tracker_project_ids = @tracker.projects.ids.to_set |
|
| 93 | 94 |
links = projects.map do |p| |
| 94 |
view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id, status_id: '*')) |
|
| 95 |
if tracker_project_ids.include?(p.id) |
|
| 96 |
view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id, status_id: '*')) |
|
| 97 |
else |
|
| 98 |
# This tracker is not enabled in the project, |
|
| 99 |
# so we can't link to the issues list |
|
| 100 |
ERB::Util.html_escape(p.name) |
|
| 101 |
end |
|
| 95 | 102 |
end.join(', ')
|
| 96 | 103 |
flash[:error] = l(:error_can_not_delete_tracker_html, projects: links.html_safe) |
| 97 | 104 |
else |
| test/functional/trackers_controller_test.rb | ||
|---|---|---|
| 273 | 273 | |
| 274 | 274 |
def test_destroy_tracker_in_use |
| 275 | 275 |
tracker = Tracker.generate!(name: 'In use') |
| 276 |
projects = Array.new(2) do
|
|
| 276 |
project1, project2 = Array.new(2) do
|
|
| 277 | 277 |
project = Project.generate! |
| 278 | 278 |
Issue.generate!(project: project, tracker: tracker) |
| 279 | 279 |
project |
| 280 | 280 |
end |
| 281 |
# Remove all associated trackers from project2 |
|
| 282 |
project2.trackers = [] |
|
| 283 |
project2.save! |
|
| 281 | 284 | |
| 282 | 285 |
assert_no_difference 'Tracker.count' do |
| 283 | 286 |
delete :destroy, params: {id: tracker.id}
|
| 284 | 287 |
end |
| 285 | 288 |
assert_redirected_to action: 'index' |
| 286 |
assert_match /The following projects have issues with this tracker:/, flash[:error] |
|
| 287 |
projects.each do |project| |
|
| 288 |
assert_match /#{project.name}/, flash[:error]
|
|
| 289 |
end |
|
| 289 |
assert_includes flash[:error], 'The following projects have issues with this tracker:' |
|
| 290 | ||
| 291 |
# Ensure project1 is listed with a link to its issue list |
|
| 292 |
assert_includes flash[:error], project1.name |
|
| 293 |
assert_match %r{<a href=".*#{project1.identifier}.*">}, flash[:error]
|
|
| 294 | ||
| 295 |
# project2 should only appear as text in the error message, without a link |
|
| 296 |
assert_includes flash[:error], project2.name |
|
| 297 |
assert_no_match %r{<a href=".*#{project2.identifier}.*">}, flash[:error]
|
|
| 290 | 298 |
end |
| 291 | 299 | |
| 292 | 300 |
def test_get_fields |