Skip to content

Commit

Permalink
Fixed a bug where modifying the :original didn't report the correct f…
Browse files Browse the repository at this point in the history
…ile_size
  • Loading branch information
Jon Yurek committed Dec 30, 2008
1 parent 3cc7ab7 commit 826c4e6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip/attachment.rb
Expand Up @@ -92,7 +92,7 @@ def assign uploaded_file
post_process if valid?

# 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
uploaded_file.close if close_uploaded_file
validate
Expand Down
6 changes: 4 additions & 2 deletions test/attachment_test.rb
Expand Up @@ -298,11 +298,13 @@ def do_after_all; end
rebuild_model

@not_file = mock
@tempfile = mock
@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(:content_type).returns("image/png\r\n")
@not_file.expects(:size).returns(10).times(2)

@dummy = Dummy.new
@attachment = @dummy.avatar
Expand Down
17 changes: 17 additions & 0 deletions test/integration_test.rb
Expand Up @@ -51,6 +51,23 @@ class IntegrationTest < Test::Unit::TestCase
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
setup do
rebuild_model :styles => { :large => "100x100",
Expand Down

0 comments on commit 826c4e6

Please sign in to comment.