Commit 826c4e6e by Jon Yurek

Fixed a bug where modifying the :original didn't report the correct file_size

parent 3cc7ab7d
...@@ -92,7 +92,7 @@ module Paperclip ...@@ -92,7 +92,7 @@ module Paperclip
post_process if valid? post_process if valid?
# Reset the file size if the original file was reprocessed. # Reset the file size if the original file was reprocessed.
instance_write(:file_size, uploaded_file.size.to_i) instance_write(:file_size, @queued_for_write[:original].size.to_i)
ensure ensure
uploaded_file.close if close_uploaded_file uploaded_file.close if close_uploaded_file
validate validate
......
...@@ -298,11 +298,13 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -298,11 +298,13 @@ class AttachmentTest < Test::Unit::TestCase
rebuild_model rebuild_model
@not_file = mock @not_file = mock
@tempfile = mock
@not_file.stubs(:nil?).returns(false) @not_file.stubs(:nil?).returns(false)
@not_file.expects(:to_tempfile).returns(self) @not_file.expects(:size).returns(10)
@tempfile.expects(:size).returns(10)
@not_file.expects(:to_tempfile).returns(@tempfile)
@not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n") @not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n")
@not_file.expects(:content_type).returns("image/png\r\n") @not_file.expects(:content_type).returns("image/png\r\n")
@not_file.expects(:size).returns(10).times(2)
@dummy = Dummy.new @dummy = Dummy.new
@attachment = @dummy.avatar @attachment = @dummy.avatar
......
...@@ -51,6 +51,23 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -51,6 +51,23 @@ class IntegrationTest < Test::Unit::TestCase
end end
end end
context "A model that modifies its original" do
setup do
rebuild_model :styles => { :original => "2x2#" }
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@dummy.avatar = @file
end
should "report the file size of the processed file and not the original" do
assert_not_equal @file.size, @dummy.avatar.size
end
teardown { @file.close }
end
context "A model with attachments scoped under an id" do context "A model with attachments scoped under an id" do
setup do setup do
rebuild_model :styles => { :large => "100x100", rebuild_model :styles => { :large => "100x100",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment