From 7f0bb136ad114e7772e7b1fb1c4210826f7a114f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 15 Jul 2012 14:42:00 +0000 Subject: [PATCH] Validate attachment description length (#11365). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9984 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 1 + test/unit/attachment_test.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 1fd0a5b82..0dda33023 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -24,6 +24,7 @@ class Attachment < ActiveRecord::Base validates_presence_of :filename, :author validates_length_of :filename, :maximum => 255 validates_length_of :disk_filename, :maximum => 255 + validates_length_of :description, :maximum => 255 validate :validate_max_file_size acts_as_event :title => :filename, diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index cd301dc93..c2a3e56b4 100644 --- a/test/unit/attachment_test.rb +++ b/test/unit/attachment_test.rb @@ -75,6 +75,12 @@ class AttachmentTest < ActiveSupport::TestCase end end + def test_description_length_should_be_validated + a = Attachment.new(:description => 'a' * 300) + assert !a.save + assert_not_nil a.errors[:description] + end + def test_destroy a = Attachment.new(:container => Issue.find(1), :file => uploaded_test_file("testfile.txt", "text/plain"),