diff --git a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/document/document_filter.rb b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/document/document_filter.rb index 46ef0630090..dff679e0718 100644 --- a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/document/document_filter.rb +++ b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/document/document_filter.rb @@ -83,6 +83,7 @@ def unpaginated_documents documents = documents.with_lead_organisation(@filters[:lead_organisation]) if @filters[:lead_organisation].present? documents = documents.from_date(from_date) if valid? && from_date documents = documents.to_date(to_date) if valid? && to_date + documents = documents.distinct documents.order("content_block_editions.updated_at DESC") end end diff --git a/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/document/document_filter_test.rb b/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/document/document_filter_test.rb index 50ac25629c5..990889d0eb8 100644 --- a/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/document/document_filter_test.rb +++ b/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/document/document_filter_test.rb @@ -9,6 +9,7 @@ class ContentBlockManager::DocumentFilterTest < ActiveSupport::TestCase before do ContentBlockManager::ContentBlock::Document.expects(:live).returns(document_scope_mock) document_scope_mock.expects(:joins).with(:latest_edition).returns(document_scope_mock) + document_scope_mock.expects(:distinct).returns(document_scope_mock) document_scope_mock.expects(:order).with("content_block_editions.updated_at DESC").returns(document_scope_mock) document_scope_mock.expects(:per).with(15).returns([]) end