Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
edad85f0
Commit
edad85f0
authored
Nov 23, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved fingerprint generation into Atatchment
parent
9e3b5db6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
32 deletions
+14
-32
lib/paperclip/attachment.rb
+9
-3
lib/paperclip/upfile.rb
+0
-7
test/attachment_test.rb
+5
-5
test/upfile_test.rb
+0
-17
No files found.
lib/paperclip/attachment.rb
View file @
edad85f0
...
...
@@ -93,7 +93,7 @@ module Paperclip
instance_write
(
:file_name
,
uploaded_file
.
original_filename
.
strip
)
instance_write
(
:content_type
,
uploaded_file
.
content_type
.
to_s
.
strip
)
instance_write
(
:file_size
,
uploaded_file
.
size
.
to_i
)
instance_write
(
:fingerprint
,
uploaded_file
.
fingerprint
)
instance_write
(
:fingerprint
,
generate_fingerprint
(
uploaded_file
)
)
instance_write
(
:updated_at
,
Time
.
now
)
@dirty
=
true
...
...
@@ -102,7 +102,7 @@ module Paperclip
# Reset the file size if the original file was reprocessed.
instance_write
(
:file_size
,
@queued_for_write
[
:original
].
size
.
to_i
)
instance_write
(
:fingerprint
,
@queued_for_write
[
:original
].
fingerprint
)
instance_write
(
:fingerprint
,
generate_fingerprint
(
@queued_for_write
[
:original
])
)
ensure
uploaded_file
.
close
if
close_uploaded_file
end
...
...
@@ -181,7 +181,7 @@ module Paperclip
# Returns the hash of the file as originally assigned, and lives in the
# <attachment>_fingerprint attribute of the model.
def
fingerprint
instance_read
(
:fingerprint
)
||
(
@queued_for_write
[
:original
]
&&
@queued_for_write
[
:original
].
fingerprint
)
instance_read
(
:fingerprint
)
||
(
@queued_for_write
[
:original
]
&&
generate_fingerprint
(
@queued_for_write
[
:original
])
)
end
# Returns the content_type of the file as originally assigned, and lives
...
...
@@ -197,6 +197,12 @@ module Paperclip
time
&&
time
.
to_f
.
to_i
end
def
generate_fingerprint
(
source
)
data
=
source
.
read
source
.
rewind
if
source
.
respond_to?
(
:rewind
)
Digest
::
MD5
.
hexdigest
(
data
)
end
# Paths and URLs can have a number of variables interpolated into them
# to vary the storage location based on name, id, style, class, etc.
# This method is a deprecated access into supplying and retrieving these
...
...
lib/paperclip/upfile.rb
View file @
edad85f0
...
...
@@ -32,13 +32,6 @@ module Paperclip
def
size
File
.
size
(
self
)
end
# Returns the hash of the file.
def
fingerprint
data
=
self
.
read
self
.
rewind
Digest
::
MD5
.
hexdigest
(
data
)
end
end
end
...
...
test/attachment_test.rb
View file @
edad85f0
...
...
@@ -463,14 +463,11 @@ class AttachmentTest < Test::Unit::TestCase
setup
do
rebuild_model
@not_file
=
mock
@tempfile
=
mock
@not_file
=
mock
(
"not_file"
)
@tempfile
=
mock
(
"tempfile"
)
@not_file
.
stubs
(
:nil?
).
returns
(
false
)
@not_file
.
stubs
(
:fingerprint
).
returns
(
'bd94545193321376b70136f8b223abf8'
)
@tempfile
.
stubs
(
:fingerprint
).
returns
(
'bd94545193321376b70136f8b223abf8'
)
@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
"
)
...
...
@@ -479,6 +476,9 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
.
expects
(
:valid_assignment?
).
with
(
@not_file
).
returns
(
true
)
@attachment
.
expects
(
:queue_existing_for_delete
)
@attachment
.
expects
(
:post_process
)
@attachment
.
expects
(
:to_tempfile
).
returns
(
@tempfile
)
@attachment
.
expects
(
:generate_fingerprint
).
with
(
@tempfile
).
returns
(
"12345"
)
@attachment
.
expects
(
:generate_fingerprint
).
with
(
@not_file
).
returns
(
"12345"
)
@dummy
.
avatar
=
@not_file
end
...
...
test/upfile_test.rb
View file @
edad85f0
...
...
@@ -33,21 +33,4 @@ class UpfileTest < Test::Unit::TestCase
end
assert_equal
'text/plain'
,
file
.
content_type
end
should
"return a MD5 fingerprint of the file"
do
file
=
StringIO
.
new
(
"1234567890"
)
class
<<
file
include
Paperclip
::
Upfile
end
assert_equal
"e807f1fcf82d132f9bb018ca6738a19f"
,
file
.
fingerprint
end
should
"still be readable after the file fingerprints itself"
do
file
=
StringIO
.
new
(
"1234567890"
)
class
<<
file
include
Paperclip
::
Upfile
end
file
.
fingerprint
assert_equal
"1234567890"
,
file
.
read
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment