Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only generate thumbnails for PDFs.

I think this was the intention of `process :generate_thumbnail, :if =>
:pdf?`, yet the presence of the surrounding thumbnail version results in
a copy of the file being created and stored, irrespective of file type.
  • Loading branch information...
commit d5fcd2e75b2a73101eeaa1111892088a9a269bd2 1 parent a2a3b73
@chrisroos-and-lazyatom chrisroos-and-lazyatom authored
View
4 app/uploaders/attachment_uploader.rb
@@ -10,11 +10,11 @@ class AttachmentUploader < CarrierWave::Uploader::Base
process :set_content_type
after :retrieve_from_cache, :set_content_type
- version :thumbnail do
+ version :thumbnail, if: :pdf? do
def full_filename(for_file)
super + ".png"
end
- process :generate_thumbnail, :if => :pdf?
+ process :generate_thumbnail
end
def store_dir
View
14 test/unit/attachment_uploader_test.rb
@@ -1,6 +1,8 @@
require 'test_helper'
class AttachmentUploaderTest < ActiveSupport::TestCase
+ include ActionDispatch::TestProcess
+
test 'should only allow PDF, CSV, RTF, PNG, JPG, DOC, DOCX, XLS, XLSX, PPT, PPTX attachments' do
uploader = AttachmentUploader.new
assert_equal %w(pdf csv rtf png jpg doc docx xls xlsx ppt pptx), uploader.extension_white_list
@@ -11,6 +13,18 @@ class AttachmentUploaderTest < ActiveSupport::TestCase
uploader = AttachmentUploader.new(model, "mounted-as")
assert_match /^system/, uploader.store_dir
end
+
+ test "should not generate thumbnail versions of non pdf files" do
+ AttachmentUploader.enable_processing = true
+
+ model = stub("AR Model", id: 1)
+ uploader = AttachmentUploader.new(model, "mounted-as")
+ uploader.store!(fixture_file_upload('portas-review.jpg'))
+
+ assert_nil uploader.thumbnail.path
+
+ AttachmentUploader.enable_processing = false
+ end
end
class AttachmentUploaderPDFTest < ActiveSupport::TestCase
Please sign in to comment.
Something went wrong with that request. Please try again.