]> source.dussan.org Git - redmine.git/commitdiff
Better message for file size validation error.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 23 Feb 2012 12:18:10 +0000 (12:18 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 23 Feb 2012 12:18:10 +0000 (12:18 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8937 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb
test/integration/api_test/attachments_test.rb

index 84e945c444e010dc48f5beec7a04e24c42ee5d61..6efe320720d17ae98f82981abdcc9a5ff488a4dd 100644 (file)
@@ -68,7 +68,7 @@ class Attachment < ActiveRecord::Base
 
   def validate_max_file_size
     if @temp_file && self.filesize > Setting.attachment_max_size.to_i.kilobytes
-      errors.add(:base, :too_long, :count => Setting.attachment_max_size.to_i.kilobytes)
+      errors.add(:base, l(:error_attachment_too_big, :max_size => Setting.attachment_max_size.to_i.kilobytes))
     end
   end
 
index 16fc531a306cace6c8ac33a00f5c3a8b519214d3..5e20449d48b0bbe01289016ea23f05ed6e9f3334 100644 (file)
@@ -116,5 +116,16 @@ class ApiTest::AttachmentsTest < ActionController::IntegrationTest
         assert_response 406
       end
     end
+
+    should "return errors if file is too big" do
+      set_tmp_attachments_directory
+      with_settings :attachment_max_size => 1 do
+        assert_no_difference 'Attachment.count' do
+          post '/uploads.xml', ('x' * 2048), {'Content-Type' => 'application/octet-stream'}.merge(credentials('jsmith'))
+          assert_response 422
+          assert_tag 'error', :content => /exceeds the maximum allowed file size/
+        end
+      end
+    end
   end
 end