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
This commit is contained in:
Toshi MARUYAMA 2012-08-21 13:45:53 +00:00
parent 185ab2a020
commit 665a331cc4
2 changed files with 12 additions and 0 deletions

View File

@ -31,4 +31,12 @@ class DocumentCategory < Enumeration
def transfer_relations(to) def transfer_relations(to)
documents.update_all("category_id = #{to.id}") documents.update_all("category_id = #{to.id}")
end end
def self.default
d = super
if d.nil?
d = find(:first)
end
d
end
end end

View File

@ -38,4 +38,8 @@ class DocumentCategoryTest < ActiveSupport::TestCase
e.update_attributes(:is_default => true) e.update_attributes(:is_default => true)
assert_equal 3, DocumentCategory.default.id assert_equal 3, DocumentCategory.default.id
end end
def test_force_default
assert_equal 1, DocumentCategory.default.id
end
end end