mbailey-paperclip 2.3.2.1 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paperclip/attachment.rb +5 -5
- data/lib/paperclip/interpolations.rb +3 -3
- data/lib/paperclip/upfile.rb +4 -4
- data/lib/paperclip/version.rb +1 -1
- data/test/attachment_test.rb +8 -8
- data/test/helper.rb +2 -2
- metadata +3 -4
data/lib/paperclip/attachment.rb
CHANGED
@@ -92,7 +92,7 @@ module Paperclip
|
|
92
92
|
instance_write(:file_name, uploaded_file.original_filename.strip)
|
93
93
|
instance_write(:content_type, uploaded_file.content_type.to_s.strip)
|
94
94
|
instance_write(:file_size, uploaded_file.size.to_i)
|
95
|
-
instance_write(:
|
95
|
+
instance_write(:fingerprint, uploaded_file.fingerprint)
|
96
96
|
instance_write(:updated_at, Time.now)
|
97
97
|
|
98
98
|
@dirty = true
|
@@ -101,7 +101,7 @@ module Paperclip
|
|
101
101
|
|
102
102
|
# Reset the file size if the original file was reprocessed.
|
103
103
|
instance_write(:file_size, @queued_for_write[:original].size.to_i)
|
104
|
-
instance_write(:
|
104
|
+
instance_write(:fingerprint, @queued_for_write[:original].fingerprint)
|
105
105
|
ensure
|
106
106
|
uploaded_file.close if close_uploaded_file
|
107
107
|
end
|
@@ -179,9 +179,9 @@ module Paperclip
|
|
179
179
|
end
|
180
180
|
|
181
181
|
# Returns the hash of the file as originally assigned, and lives in the
|
182
|
-
# <attachment>
|
183
|
-
def
|
184
|
-
instance_read(:
|
182
|
+
# <attachment>_fingerprint attribute of the model.
|
183
|
+
def fingerprint
|
184
|
+
instance_read(:fingerprint) || (@queued_for_write[:original] && @queued_for_write[:original].fingerprint)
|
185
185
|
end
|
186
186
|
|
187
187
|
# Returns the content_type of the file as originally assigned, and lives
|
@@ -88,9 +88,9 @@ module Paperclip
|
|
88
88
|
attachment.instance.id
|
89
89
|
end
|
90
90
|
|
91
|
-
# Returns the
|
92
|
-
def
|
93
|
-
attachment.
|
91
|
+
# Returns the fingerprint of the instance.
|
92
|
+
def fingerprint attachment, style_name
|
93
|
+
attachment.fingerprint
|
94
94
|
end
|
95
95
|
|
96
96
|
# Returns the id of the instance in a split path form. e.g. returns
|
data/lib/paperclip/upfile.rb
CHANGED
@@ -34,7 +34,7 @@ module Paperclip
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# Returns the hash of the file.
|
37
|
-
def
|
37
|
+
def fingerprint
|
38
38
|
Digest::MD5.hexdigest(self.read)
|
39
39
|
end
|
40
40
|
end
|
@@ -42,15 +42,15 @@ end
|
|
42
42
|
|
43
43
|
if defined? StringIO
|
44
44
|
class StringIO
|
45
|
-
attr_accessor :original_filename, :content_type, :
|
45
|
+
attr_accessor :original_filename, :content_type, :fingerprint
|
46
46
|
def original_filename
|
47
47
|
@original_filename ||= "stringio.txt"
|
48
48
|
end
|
49
49
|
def content_type
|
50
50
|
@content_type ||= "text/plain"
|
51
51
|
end
|
52
|
-
def
|
53
|
-
@
|
52
|
+
def fingerprint
|
53
|
+
@fingerprint ||= Digest::MD5.hexdigest(self.string)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/paperclip/version.rb
CHANGED
data/test/attachment_test.rb
CHANGED
@@ -446,8 +446,8 @@ class AttachmentTest < Test::Unit::TestCase
|
|
446
446
|
@not_file = mock
|
447
447
|
@tempfile = mock
|
448
448
|
@not_file.stubs(:nil?).returns(false)
|
449
|
-
@not_file.stubs(:
|
450
|
-
@tempfile.stubs(:
|
449
|
+
@not_file.stubs(:fingerprint).returns('bd94545193321376b70136f8b223abf8')
|
450
|
+
@tempfile.stubs(:fingerprint).returns('bd94545193321376b70136f8b223abf8')
|
451
451
|
@not_file.expects(:size).returns(10)
|
452
452
|
@tempfile.expects(:size).returns(10)
|
453
453
|
@not_file.expects(:to_tempfile).returns(@tempfile)
|
@@ -757,9 +757,9 @@ class AttachmentTest < Test::Unit::TestCase
|
|
757
757
|
end
|
758
758
|
end
|
759
759
|
|
760
|
-
context "and
|
760
|
+
context "and avatar_fingerprint column" do
|
761
761
|
setup do
|
762
|
-
ActiveRecord::Base.connection.add_column :dummies, :
|
762
|
+
ActiveRecord::Base.connection.add_column :dummies, :avatar_fingerprint, :string
|
763
763
|
rebuild_class
|
764
764
|
@dummy = Dummy.new
|
765
765
|
end
|
@@ -768,16 +768,16 @@ class AttachmentTest < Test::Unit::TestCase
|
|
768
768
|
assert_nothing_raised { @dummy.avatar = @file }
|
769
769
|
end
|
770
770
|
|
771
|
-
should "return the right value when sent #
|
771
|
+
should "return the right value when sent #avatar_fingerprint" do
|
772
772
|
@dummy.avatar = @file
|
773
|
-
assert_equal 'aec488126c3b33c08a10c3fa303acf27', @dummy.
|
773
|
+
assert_equal 'aec488126c3b33c08a10c3fa303acf27', @dummy.avatar_fingerprint
|
774
774
|
end
|
775
775
|
|
776
|
-
should "return the right value when saved, reloaded, and sent #
|
776
|
+
should "return the right value when saved, reloaded, and sent #avatar_fingerprint" do
|
777
777
|
@dummy.avatar = @file
|
778
778
|
@dummy.save
|
779
779
|
@dummy = Dummy.find(@dummy.id)
|
780
|
-
assert_equal 'aec488126c3b33c08a10c3fa303acf27', @dummy.
|
780
|
+
assert_equal 'aec488126c3b33c08a10c3fa303acf27', @dummy.avatar_fingerprint
|
781
781
|
end
|
782
782
|
end
|
783
783
|
end
|
data/test/helper.rb
CHANGED
@@ -86,7 +86,7 @@ def rebuild_model options = {}
|
|
86
86
|
table.column :avatar_content_type, :string
|
87
87
|
table.column :avatar_file_size, :integer
|
88
88
|
table.column :avatar_updated_at, :datetime
|
89
|
-
table.column :
|
89
|
+
table.column :avatar_fingerprint, :string
|
90
90
|
end
|
91
91
|
rebuild_class options
|
92
92
|
end
|
@@ -106,7 +106,7 @@ class FakeModel
|
|
106
106
|
:avatar_file_size,
|
107
107
|
:avatar_last_updated,
|
108
108
|
:avatar_content_type,
|
109
|
-
:
|
109
|
+
:avatar_fingerprint,
|
110
110
|
:id
|
111
111
|
|
112
112
|
def errors
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mbailey-paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 2.3.2.1
|
9
|
+
- 3
|
10
|
+
version: 2.3.3
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Jon Yurek
|