Skip to content
This repository
Browse code

Don't calculate fingerprint when fingerprint can not be stored.

  • Loading branch information...
commit 4e076813a48cd1466fe0159ab411c11f5620bd4c 1 parent 7b70fa4
Nathan Hyde authored jyurek committed

Showing 2 changed files with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. +3 2 lib/paperclip/attachment.rb
  2. +8 1 test/attachment_test.rb
5 lib/paperclip/attachment.rb
@@ -106,11 +106,12 @@ def assign uploaded_file
106 106 return nil if uploaded_file.nil?
107 107
108 108 uploaded_filename ||= uploaded_file.original_filename
  109 + stores_fingerprint = @instance.respond_to?("#{name}_fingerprint".to_sym)
109 110 @queued_for_write[:original] = to_tempfile(uploaded_file)
110 111 instance_write(:file_name, uploaded_filename.strip)
111 112 instance_write(:content_type, uploaded_file.content_type.to_s.strip)
112 113 instance_write(:file_size, uploaded_file.size.to_i)
113   - instance_write(:fingerprint, generate_fingerprint(uploaded_file))
  114 + instance_write(:fingerprint, stores_fingerprint ? generate_fingerprint(uploaded_file) : false)
114 115 instance_write(:updated_at, Time.now)
115 116
116 117 @dirty = true
@@ -119,7 +120,7 @@ def assign uploaded_file
119 120
120 121 # Reset the file size if the original file was reprocessed.
121 122 instance_write(:file_size, @queued_for_write[:original].size.to_i)
122   - instance_write(:fingerprint, generate_fingerprint(@queued_for_write[:original]))
  123 + instance_write(:fingerprint, generate_fingerprint(@queued_for_write[:original])) if stores_fingerprint
123 124 ensure
124 125 uploaded_file.close if close_uploaded_file
125 126 end
9 test/attachment_test.rb
@@ -997,7 +997,14 @@ def do_after_all; end
997 997 assert_equal now.to_i, @dummy.avatar.updated_at
998 998 end
999 999 end
1000   -
  1000 +
  1001 + should "not calculate fingerprint without fingerprint column" do
  1002 + assert_equal false, @dummy.respond_to?(:avatar_fingerprint)
  1003 + @dummy.avatar = @file
  1004 + @dummy.save
  1005 + assert_nil @dummy.avatar.fingerprint
  1006 + end
  1007 +
1001 1008 context "and avatar_content_type column" do
1002 1009 setup do
1003 1010 ActiveRecord::Base.connection.add_column :dummies, :avatar_content_type, :string

0 comments on commit 4e07681

Please sign in to comment.
Something went wrong with that request. Please try again.