From 665a331cc407f3143bece9caf0e19d48d2f66149 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Tue, 21 Aug 2012 13:45:53 +0000 Subject: [PATCH] force set default document category if it is not set on database (#11665) git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10221 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/document_category.rb | 8 ++++++++ test/unit/document_category_test.rb | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/app/models/document_category.rb b/app/models/document_category.rb index a7a2fd9d6..c22b81e5b 100644 --- a/app/models/document_category.rb +++ b/app/models/document_category.rb @@ -31,4 +31,12 @@ class DocumentCategory < Enumeration def transfer_relations(to) documents.update_all("category_id = #{to.id}") end + + def self.default + d = super + if d.nil? + d = find(:first) + end + d + end end diff --git a/test/unit/document_category_test.rb b/test/unit/document_category_test.rb index d3d3978bf..30ef1687a 100644 --- a/test/unit/document_category_test.rb +++ b/test/unit/document_category_test.rb @@ -38,4 +38,8 @@ class DocumentCategoryTest < ActiveSupport::TestCase e.update_attributes(:is_default => true) assert_equal 3, DocumentCategory.default.id end + + def test_force_default + assert_equal 1, DocumentCategory.default.id + end end -- 2.39.5