Project

General

Profile

Feature #12521 » 12521-v3.patch

Go MAEDA, 2024-10-08 11:50

View differences:

app/controllers/trackers_controller.rb
89 89
  def destroy
90 90
    @tracker = Tracker.find(params[:id])
91 91
    unless @tracker.issues.empty?
92
      flash[:error] = l(:error_can_not_delete_tracker)
92
      projects = Project.joins(:issues).where(issues: {tracker_id: @tracker.id}).sorted.distinct
93
      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
      end.join(', ')
96
      flash[:error] = l(:error_can_not_delete_tracker_html, projects: links.html_safe)
93 97
    else
94 98
      @tracker.destroy
95 99
    end
config/locales/en.yml
205 205
  error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.'
206 206
  error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
207 207
  error_can_not_delete_custom_field: Unable to delete custom field
208
  error_can_not_delete_tracker: "This tracker contains issues and cannot be deleted."
208
  error_can_not_delete_tracker_html: "This tracker contains issues and cannot be deleted.<p>The following projects have issues with this tracker:<br>%{projects}</p>"
209 209
  error_can_not_remove_role: "This role is in use and cannot be deleted."
210 210
  error_can_not_reopen_issue_on_closed_version: 'An issue assigned to a closed version cannot be reopened'
211 211
  error_can_not_archive_project: This project cannot be archived
test/functional/trackers_controller_test.rb
274 274
  end
275 275

  
276 276
  def test_destroy_tracker_in_use
277
    tracker = Tracker.generate!(name: 'In use')
278
    projects = Array.new(2) do
279
      project = Project.generate!
280
      Issue.generate!(project: project, tracker: tracker)
281
      project
282
    end
283

  
277 284
    assert_no_difference 'Tracker.count' do
278
      delete :destroy, :params => {:id => 1}
285
      delete :destroy, params: {id: tracker.id}
286
    end
287
    assert_redirected_to action: 'index'
288
    assert_match /The following projects have issues with this tracker:/, flash[:error]
289
    projects.each do |project|
290
      assert_match /#{project.name}/, flash[:error]
279 291
    end
280
    assert_redirected_to :action => 'index'
281
    assert_not_nil flash[:error]
282 292
  end
283 293

  
284 294
  def test_get_fields
(5-5/5)