Project

General

Profile

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

Go MAEDA, 2025-02-08 09:38

View differences:

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
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) || p.rolled_up_trackers.ids.include?(@tracker.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
272 272
  end
273 273

  
274 274
  def test_destroy_tracker_in_use
275
    tracker = Tracker.generate!(name: 'In use')
276
    projects = Array.new(2) do
277
      project = Project.generate!
278
      Issue.generate!(project: project, tracker: tracker)
279
      project
280
    end
275
    tracker = Tracker.find_by(name: 'Bug')
276
    # A project where the tracker is explicitly enabled
277
    project_with_tracker = Project.find_by(identifier: 'private-child')
278
    # A project where the tracker is disabled, but rolled up from subprojects
279
    project_with_rolled_up_tracker = Project.find_by(identifier: 'ecookbook')
280
    project_with_rolled_up_tracker.trackers.delete(tracker)
281
    # A project where the tracker is completely disabled
282
    project_without_tracker = Project.find_by(identifier: 'onlinestore')
283
    project_without_tracker.trackers.delete(tracker)
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
    # projects with the tracker enabled or rolled up have a link in the error message
292
    assert_includes flash[:error], project_with_tracker.name
293
    assert_match %r{<a href=".*#{project_with_tracker.identifier}.*">}, flash[:error]
294
    assert_includes flash[:error], project_with_rolled_up_tracker.name
295
    assert_match %r{<a href=".*#{project_with_rolled_up_tracker.identifier}.*">}, flash[:error]
296

  
297
    # projects without the tracker appear as text in the error message, without a link
298
    assert_includes flash[:error], project_without_tracker.name
299
    assert_no_match %r{<a href=".*#{project_without_tracker.identifier}.*">}, flash[:error]
290 300
  end
291 301

  
292 302
  def test_get_fields
(2-2/2)