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
3b2b9bcf
Commit
3b2b9bcf
authored
Feb 06, 2012
by
Kelley Reynolds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rewind to to_file where appropriate
parent
772c8e96
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
2 deletions
+29
-2
lib/paperclip/storage/filesystem.rb
+6
-1
lib/paperclip/storage/fog.rb
+1
-0
lib/paperclip/storage/s3.rb
+4
-1
test/storage/filesystem_test.rb
+6
-0
test/storage/fog_test.rb
+6
-0
test/storage/s3_test.rb
+6
-0
No files found.
lib/paperclip/storage/filesystem.rb
View file @
3b2b9bcf
...
@@ -30,7 +30,12 @@ module Paperclip
...
@@ -30,7 +30,12 @@ module Paperclip
# Returns representation of the data of the file assigned to the given
# Returns representation of the data of the file assigned to the given
# style, in the format most representative of the current storage.
# style, in the format most representative of the current storage.
def
to_file
style_name
=
default_style
def
to_file
style_name
=
default_style
@queued_for_write
[
style_name
]
||
(
File
.
new
(
path
(
style_name
),
'rb'
)
if
exists?
(
style_name
))
if
@queued_for_write
[
style_name
]
@queued_for_write
[
style_name
].
rewind
@queued_for_write
[
style_name
]
elsif
exists?
(
style_name
)
File
.
new
(
path
(
style_name
),
'rb'
)
end
end
end
def
flush_writes
#:nodoc:
def
flush_writes
#:nodoc:
...
...
lib/paperclip/storage/fog.rb
View file @
3b2b9bcf
...
@@ -110,6 +110,7 @@ module Paperclip
...
@@ -110,6 +110,7 @@ module Paperclip
# style, in the format most representative of the current storage.
# style, in the format most representative of the current storage.
def
to_file
(
style
=
default_style
)
def
to_file
(
style
=
default_style
)
if
@queued_for_write
[
style
]
if
@queued_for_write
[
style
]
@queued_for_write
[
style
].
rewind
@queued_for_write
[
style
]
@queued_for_write
[
style
]
else
else
body
=
directory
.
files
.
get
(
path
(
style
)).
body
body
=
directory
.
files
.
get
(
path
(
style
)).
body
...
...
lib/paperclip/storage/s3.rb
View file @
3b2b9bcf
...
@@ -257,7 +257,10 @@ module Paperclip
...
@@ -257,7 +257,10 @@ module Paperclip
# Returns representation of the data of the file assigned to the given
# Returns representation of the data of the file assigned to the given
# style, in the format most representative of the current storage.
# style, in the format most representative of the current storage.
def
to_file
style
=
default_style
def
to_file
style
=
default_style
return
@queued_for_write
[
style
]
if
@queued_for_write
[
style
]
if
@queued_for_write
[
style
]
@queued_for_write
[
style
].
rewind
return
@queued_for_write
[
style
]
end
filename
=
path
(
style
)
filename
=
path
(
style
)
extname
=
File
.
extname
(
filename
)
extname
=
File
.
extname
(
filename
)
basename
=
File
.
basename
(
filename
,
extname
)
basename
=
File
.
basename
(
filename
,
extname
)
...
...
test/storage/filesystem_test.rb
View file @
3b2b9bcf
...
@@ -31,6 +31,12 @@ class FileSystemTest < Test::Unit::TestCase
...
@@ -31,6 +31,12 @@ class FileSystemTest < Test::Unit::TestCase
@dummy
.
save!
@dummy
.
save!
end
end
should
"always be rewound when returning from #to_file"
do
assert_equal
0
,
@dummy
.
avatar
.
to_file
.
pos
@dummy
.
avatar
.
to_file
.
seek
(
10
)
assert_equal
0
,
@dummy
.
avatar
.
to_file
.
pos
end
context
"with file that has space in file name"
do
context
"with file that has space in file name"
do
setup
do
setup
do
rebuild_model
:styles
=>
{
:thumbnail
=>
"25x25#"
}
rebuild_model
:styles
=>
{
:thumbnail
=>
"25x25#"
}
...
...
test/storage/fog_test.rb
View file @
3b2b9bcf
...
@@ -110,6 +110,12 @@ class FogTest < Test::Unit::TestCase
...
@@ -110,6 +110,12 @@ class FogTest < Test::Unit::TestCase
directory
.
destroy
directory
.
destroy
end
end
should
"always be rewound when returning from #to_file"
do
assert_equal
0
,
@dummy
.
avatar
.
to_file
.
pos
@dummy
.
avatar
.
to_file
.
seek
(
10
)
assert_equal
0
,
@dummy
.
avatar
.
to_file
.
pos
end
should
"pass the content type to the Fog::Storage::AWS::Files instance"
do
should
"pass the content type to the Fog::Storage::AWS::Files instance"
do
Fog
::
Storage
::
AWS
::
Files
.
any_instance
.
expects
(
:create
).
with
do
|
hash
|
Fog
::
Storage
::
AWS
::
Files
.
any_instance
.
expects
(
:create
).
with
do
|
hash
|
hash
[
:content_type
]
hash
[
:content_type
]
...
...
test/storage/s3_test.rb
View file @
3b2b9bcf
...
@@ -335,6 +335,12 @@ class S3Test < Test::Unit::TestCase
...
@@ -335,6 +335,12 @@ class S3Test < Test::Unit::TestCase
should
"return a relative URL for Rails to calculate assets host"
do
should
"return a relative URL for Rails to calculate assets host"
do
assert_match
%r{^avatars/stringio
\.
txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^avatars/stringio
\.
txt}
,
@dummy
.
avatar
.
url
end
end
should
"always be rewound when returning from #to_file"
do
assert_equal
0
,
@dummy
.
avatar
.
to_file
.
pos
@dummy
.
avatar
.
to_file
.
seek
(
10
)
assert_equal
0
,
@dummy
.
avatar
.
to_file
.
pos
end
end
end
context
"Generating a secure url with an expiration"
do
context
"Generating a secure url with an expiration"
do
...
...
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