diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb
index aa5e5200d..f7f2f332a 100644
--- a/app/views/documents/index.html.erb
+++ b/app/views/documents/index.html.erb
@@ -17,9 +17,10 @@
-<% if @grouped.empty? %>
<%= l(:label_no_data) %>
<% end %>
+<% group_keys = @grouped.keys.compact %>
+<% if @grouped.empty? || group_keys.empty? %>
<%= l(:label_no_data) %>
<% end %>
-<% @grouped.keys.sort.__send__(@sort_by == 'date' ? :reverse_each : :each) do |group| %>
+<% group_keys.compact.sort.__send__(@sort_by == 'date' ? :reverse_each : :each) do |group| %>
<%= group %>
<%= render :partial => 'documents/document', :collection => @grouped[group] %>
diff --git a/test/functional/documents_controller_test.rb b/test/functional/documents_controller_test.rb
index 099683640..41dd9120b 100644
--- a/test/functional/documents_controller_test.rb
+++ b/test/functional/documents_controller_test.rb
@@ -62,6 +62,21 @@ class DocumentsControllerTest < Redmine::ControllerTest
end
end
+ def test_index_grouped_by_category_should_ignore_invalid_document_category
+ # Delete a document category skipping callbacks
+ DocumentCategory.find_by(name: 'Technical documentation').delete
+ get(
+ :index,
+ :params => {
+ :project_id => 'ecookbook',
+ :sort_by => 'category'
+ }
+ )
+ assert_response :success
+ assert_select 'h3.group-name', :text => 'Uncategorized', :count => 1
+ assert_select 'h3.group-name', :text => 'Technical documentation', :count => 0
+ end
+
def test_index_grouped_by_date
get(
:index,