Defect #42226 » fix-tracker-deletion-error-message-v2.patch
| 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
|
||
|
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) || p.rolled_up_trackers.ids.include?(@tracker.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 | ||
|---|---|---|
|
end
|
||
|
def test_destroy_tracker_in_use
|
||
|
tracker = Tracker.generate!(name: 'In use')
|
||
|
projects = Array.new(2) do
|
||
|
project = Project.generate!
|
||
|
Issue.generate!(project: project, tracker: tracker)
|
||
|
project
|
||
|
end
|
||
|
tracker = Tracker.find_by(name: 'Bug')
|
||
|
# A project where the tracker is explicitly enabled
|
||
|
project_with_tracker = Project.find_by(identifier: 'private-child')
|
||
|
# A project where the tracker is disabled, but rolled up from subprojects
|
||
|
project_with_rolled_up_tracker = Project.find_by(identifier: 'ecookbook')
|
||
|
project_with_rolled_up_tracker.trackers.delete(tracker)
|
||
|
# A project where the tracker is completely disabled
|
||
|
project_without_tracker = Project.find_by(identifier: 'onlinestore')
|
||
|
project_without_tracker.trackers.delete(tracker)
|
||
|
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:'
|
||
|
# projects with the tracker enabled or rolled up have a link in the error message
|
||
|
assert_includes flash[:error], project_with_tracker.name
|
||
|
assert_match %r{<a href=".*#{project_with_tracker.identifier}.*">}, flash[:error]
|
||
|
assert_includes flash[:error], project_with_rolled_up_tracker.name
|
||
|
assert_match %r{<a href=".*#{project_with_rolled_up_tracker.identifier}.*">}, flash[:error]
|
||
|
# projects without the tracker appear as text in the error message, without a link
|
||
|
assert_includes flash[:error], project_without_tracker.name
|
||
|
assert_no_match %r{<a href=".*#{project_without_tracker.identifier}.*">}, flash[:error]
|
||
|
end
|
||
|
def test_get_fields
|
||
- « Previous
- 1
- 2
- Next »