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
9c510875
Commit
9c510875
authored
Dec 10, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#58 Applied Rob Anderton's patch, fixing many windows-related issues.
parent
8fce8150
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
77 additions
and
55 deletions
+77
-55
lib/paperclip/attachment.rb
+3
-0
lib/paperclip/storage.rb
+1
-1
test/attachment_test.rb
+11
-8
test/geometry_test.rb
+1
-1
test/integration_test.rb
+29
-27
test/iostream_test.rb
+22
-8
test/paperclip_test.rb
+3
-3
test/storage_test.rb
+2
-2
test/thumbnail_test.rb
+5
-5
No files found.
lib/paperclip/attachment.rb
View file @
9c510875
...
@@ -62,6 +62,7 @@ module Paperclip
...
@@ -62,6 +62,7 @@ module Paperclip
if
uploaded_file
.
is_a?
(
Paperclip
::
Attachment
)
if
uploaded_file
.
is_a?
(
Paperclip
::
Attachment
)
uploaded_file
=
uploaded_file
.
to_file
(
:original
)
uploaded_file
=
uploaded_file
.
to_file
(
:original
)
close_uploaded_file
=
true
if
uploaded_file
.
respond_to?
(
:close
)
end
end
return
nil
unless
valid_assignment?
(
uploaded_file
)
return
nil
unless
valid_assignment?
(
uploaded_file
)
...
@@ -88,6 +89,7 @@ module Paperclip
...
@@ -88,6 +89,7 @@ module Paperclip
# Reset the file size if the original file was reprocessed.
# Reset the file size if the original file was reprocessed.
instance_write
(
:file_size
,
uploaded_file
.
size
.
to_i
)
instance_write
(
:file_size
,
uploaded_file
.
size
.
to_i
)
ensure
ensure
uploaded_file
.
close
if
close_uploaded_file
validate
validate
end
end
...
@@ -191,6 +193,7 @@ module Paperclip
...
@@ -191,6 +193,7 @@ module Paperclip
# again.
# again.
def
reprocess!
def
reprocess!
new_original
=
Tempfile
.
new
(
"paperclip-reprocess"
)
new_original
=
Tempfile
.
new
(
"paperclip-reprocess"
)
new_original
.
binmode
if
old_original
=
to_file
(
:original
)
if
old_original
=
to_file
(
:original
)
new_original
.
write
(
old_original
.
read
)
new_original
.
write
(
old_original
.
read
)
new_original
.
rewind
new_original
.
rewind
...
...
lib/paperclip/storage.rb
View file @
9c510875
...
@@ -31,7 +31,7 @@ module Paperclip
...
@@ -31,7 +31,7 @@ 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
@queued_for_write
[
style
]
||
(
File
.
new
(
path
(
style
))
if
exists?
(
style
))
@queued_for_write
[
style
]
||
(
File
.
new
(
path
(
style
)
,
'rb'
)
if
exists?
(
style
))
end
end
alias_method
:to_io
,
:to_file
alias_method
:to_io
,
:to_file
...
...
test/attachment_test.rb
View file @
9c510875
...
@@ -77,7 +77,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -77,7 +77,7 @@ class AttachmentTest < Test::Unit::TestCase
@dummy
.
stubs
(
:id
).
returns
(
1024
)
@dummy
.
stubs
(
:id
).
returns
(
1024
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"fixtures"
,
"5k.png"
))
"5k.png"
)
,
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
...
@@ -95,7 +95,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -95,7 +95,7 @@ class AttachmentTest < Test::Unit::TestCase
@dummy
.
stubs
(
:id
).
returns
(
@id
)
@dummy
.
stubs
(
:id
).
returns
(
@id
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"fixtures"
,
"5k.png"
))
"5k.png"
)
,
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
...
@@ -131,7 +131,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -131,7 +131,7 @@ class AttachmentTest < Test::Unit::TestCase
setup
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"fixtures"
,
"5k.png"
))
"5k.png"
)
,
'rb'
)
Paperclip
::
Thumbnail
.
stubs
(
:make
)
Paperclip
::
Thumbnail
.
stubs
(
:make
)
[
:thumb
,
:large
].
each
do
|
style
|
[
:thumb
,
:large
].
each
do
|
style
|
@dummy
.
avatar
.
stubs
(
:extra_options_for
).
with
(
style
)
@dummy
.
avatar
.
stubs
(
:extra_options_for
).
with
(
style
)
...
@@ -213,7 +213,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -213,7 +213,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
=
Paperclip
::
Attachment
.
new
(
:avatar
,
@instance
)
@attachment
=
Paperclip
::
Attachment
.
new
(
:avatar
,
@instance
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"fixtures"
,
"5k.png"
))
"5k.png"
)
,
'rb'
)
end
end
should
"raise if there are not the correct columns when you try to assign"
do
should
"raise if there are not the correct columns when you try to assign"
do
...
@@ -300,9 +300,11 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -300,9 +300,11 @@ class AttachmentTest < Test::Unit::TestCase
end
end
should
"return the real url"
do
should
"return the real url"
do
assert
@attachment
.
to_file
file
=
@attachment
.
to_file
assert
file
assert_match
%r{^/avatars/
#{
@instance
.
id
}
/original/5k
\.
png}
,
@attachment
.
url
assert_match
%r{^/avatars/
#{
@instance
.
id
}
/original/5k
\.
png}
,
@attachment
.
url
assert_match
%r{^/avatars/
#{
@instance
.
id
}
/small/5k
\.
jpg}
,
@attachment
.
url
(
:small
)
assert_match
%r{^/avatars/
#{
@instance
.
id
}
/small/5k
\.
jpg}
,
@attachment
.
url
(
:small
)
file
.
close
end
end
should
"commit the files to disk"
do
should
"commit the files to disk"
do
...
@@ -310,6 +312,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -310,6 +312,7 @@ class AttachmentTest < Test::Unit::TestCase
io
=
@attachment
.
to_io
(
style
)
io
=
@attachment
.
to_io
(
style
)
assert
File
.
exists?
(
io
)
assert
File
.
exists?
(
io
)
assert
!
io
.
is_a?
(
::
Tempfile
)
assert
!
io
.
is_a?
(
::
Tempfile
)
io
.
close
end
end
end
end
...
@@ -317,8 +320,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -317,8 +320,7 @@ class AttachmentTest < Test::Unit::TestCase
[[
:large
,
400
,
61
,
"PNG"
],
[[
:large
,
400
,
61
,
"PNG"
],
[
:medium
,
100
,
15
,
"GIF"
],
[
:medium
,
100
,
15
,
"GIF"
],
[
:small
,
32
,
32
,
"JPEG"
]].
each
do
|
style
|
[
:small
,
32
,
32
,
"JPEG"
]].
each
do
|
style
|
cmd
=
"identify -format '%w %h %b %m' "
+
cmd
=
%Q[identify -format "%w %h %b %m" "
#{
@attachment
.
path
(
style
.
first
)
}
"]
"
#{
@attachment
.
to_io
(
style
.
first
).
path
}
"
out
=
`
#{
cmd
}
`
out
=
`
#{
cmd
}
`
width
,
height
,
size
,
format
=
out
.
split
(
" "
)
width
,
height
,
size
,
format
=
out
.
split
(
" "
)
assert_equal
style
[
1
].
to_s
,
width
.
to_s
assert_equal
style
[
1
].
to_s
,
width
.
to_s
...
@@ -328,7 +330,8 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -328,7 +330,8 @@ class AttachmentTest < Test::Unit::TestCase
end
end
should
"still have its #file attribute not be nil"
do
should
"still have its #file attribute not be nil"
do
assert
!
@attachment
.
to_file
.
nil?
assert
!
(
file
=
@attachment
.
to_file
).
nil?
file
.
close
end
end
context
"and deleted"
do
context
"and deleted"
do
...
...
test/geometry_test.rb
View file @
9c510875
...
@@ -93,7 +93,7 @@ class GeometryTest < Test::Unit::TestCase
...
@@ -93,7 +93,7 @@ class GeometryTest < Test::Unit::TestCase
should
"be generated from a file"
do
should
"be generated from a file"
do
file
=
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
)
file
=
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
)
file
=
File
.
new
(
file
)
file
=
File
.
new
(
file
,
'rb'
)
assert_nothing_raised
{
@geo
=
Paperclip
::
Geometry
.
from_file
(
file
)
}
assert_nothing_raised
{
@geo
=
Paperclip
::
Geometry
.
from_file
(
file
)
}
assert
@geo
.
height
>
0
assert
@geo
.
height
>
0
assert
@geo
.
width
>
0
assert
@geo
.
width
>
0
...
...
test/integration_test.rb
View file @
9c510875
...
@@ -4,7 +4,7 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -4,7 +4,7 @@ class IntegrationTest < Test::Unit::TestCase
context
"Many models at once"
do
context
"Many models at once"
do
setup
do
setup
do
rebuild_model
rebuild_model
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
))
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
)
,
'rb'
)
300
.
times
do
|
i
|
300
.
times
do
|
i
|
Dummy
.
create!
:avatar
=>
@file
Dummy
.
create!
:avatar
=>
@file
end
end
...
@@ -24,13 +24,13 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -24,13 +24,13 @@ class IntegrationTest < Test::Unit::TestCase
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"fixtures"
,
"5k.png"
))
"5k.png"
)
,
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
assert
@dummy
.
save
assert
@dummy
.
save
end
end
should
"create its thumbnails properly"
do
should
"create its thumbnails properly"
do
assert_match
/\b50x50\b/
,
`identify
'
#{
@dummy
.
avatar
.
path
(
:thumb
)
}
'
`
assert_match
/\b50x50\b/
,
`identify
"
#{
@dummy
.
avatar
.
path
(
:thumb
)
}
"
`
end
end
context
"redefining its attachment styles"
do
context
"redefining its attachment styles"
do
...
@@ -44,7 +44,7 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -44,7 +44,7 @@ class IntegrationTest < Test::Unit::TestCase
end
end
should
"create its thumbnails properly"
do
should
"create its thumbnails properly"
do
assert_match
/\b150x25\b/
,
`identify
'
#{
@dummy
.
avatar
.
path
(
:thumb
)
}
'
`
assert_match
/\b150x25\b/
,
`identify
"
#{
@dummy
.
avatar
.
path
(
:thumb
)
}
"
`
end
end
end
end
end
end
...
@@ -133,8 +133,8 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -133,8 +133,8 @@ class IntegrationTest < Test::Unit::TestCase
:url
=>
"/:attachment/:class/:style/:id/:basename.:extension"
,
:url
=>
"/:attachment/:class/:style/:id/:basename.:extension"
,
:path
=>
":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
:path
=>
":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
))
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
)
,
'rb'
)
@bad_file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"bad.png"
))
@bad_file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"bad.png"
)
,
'rb'
)
assert
@dummy
.
avatar
=
@file
assert
@dummy
.
avatar
=
@file
assert
@dummy
.
valid?
assert
@dummy
.
valid?
...
@@ -146,18 +146,18 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -146,18 +146,18 @@ class IntegrationTest < Test::Unit::TestCase
[
"300x46"
,
:large
],
[
"300x46"
,
:large
],
[
"100x15"
,
:medium
],
[
"100x15"
,
:medium
],
[
"32x32"
,
:thumb
]].
each
do
|
geo
,
style
|
[
"32x32"
,
:thumb
]].
each
do
|
geo
,
style
|
cmd
=
%Q[identify -format "%wx%h"
#{
@dummy
.
avatar
.
to_file
(
style
).
path
}
]
cmd
=
%Q[identify -format "%wx%h"
"
#{
@dummy
.
avatar
.
path
(
style
)
}
"
]
assert_equal
geo
,
`
#{
cmd
}
`
.
chomp
,
cmd
assert_equal
geo
,
`
#{
cmd
}
`
.
chomp
,
cmd
end
end
saved_paths
=
[
:thumb
,
:medium
,
:large
,
:original
].
collect
{
|
s
|
@dummy
.
avatar
.
to_file
(
s
).
path
}
saved_paths
=
[
:thumb
,
:medium
,
:large
,
:original
].
collect
{
|
s
|
@dummy
.
avatar
.
path
(
s
)
}
@d2
=
Dummy
.
find
(
@dummy
.
id
)
@d2
=
Dummy
.
find
(
@dummy
.
id
)
assert_equal
"100x15"
,
`identify -format "%wx%h"
#{
@d2
.
avatar
.
to_file
.
path
}
`
.
chomp
assert_equal
"100x15"
,
`identify -format "%wx%h"
"
#{
@d2
.
avatar
.
path
}
"
`
.
chomp
assert_equal
"434x66"
,
`identify -format "%wx%h"
#{
@d2
.
avatar
.
to_file
(
:original
).
path
}
`
.
chomp
assert_equal
"434x66"
,
`identify -format "%wx%h"
"
#{
@d2
.
avatar
.
path
(
:original
)
}
"
`
.
chomp
assert_equal
"300x46"
,
`identify -format "%wx%h"
#{
@d2
.
avatar
.
to_file
(
:large
).
path
}
`
.
chomp
assert_equal
"300x46"
,
`identify -format "%wx%h"
"
#{
@d2
.
avatar
.
path
(
:large
)
}
"
`
.
chomp
assert_equal
"100x15"
,
`identify -format "%wx%h"
#{
@d2
.
avatar
.
to_file
(
:medium
).
path
}
`
.
chomp
assert_equal
"100x15"
,
`identify -format "%wx%h"
"
#{
@d2
.
avatar
.
path
(
:medium
)
}
"
`
.
chomp
assert_equal
"32x32"
,
`identify -format "%wx%h"
#{
@d2
.
avatar
.
to_file
(
:thumb
).
path
}
`
.
chomp
assert_equal
"32x32"
,
`identify -format "%wx%h"
"
#{
@d2
.
avatar
.
path
(
:thumb
)
}
"
`
.
chomp
@dummy
.
avatar
=
"not a valid file but not nil"
@dummy
.
avatar
=
"not a valid file but not nil"
assert_equal
File
.
basename
(
@file
.
path
),
@dummy
.
avatar_file_name
assert_equal
File
.
basename
(
@file
.
path
),
@dummy
.
avatar_file_name
...
@@ -186,10 +186,10 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -186,10 +186,10 @@ class IntegrationTest < Test::Unit::TestCase
assert_equal
@dummy
.
avatar_file_name
,
@d2
.
avatar_file_name
assert_equal
@dummy
.
avatar_file_name
,
@d2
.
avatar_file_name
[
:thumb
,
:medium
,
:large
,
:original
].
each
do
|
style
|
[
:thumb
,
:medium
,
:large
,
:original
].
each
do
|
style
|
assert_equal
@dummy
.
avatar
.
to_file
(
style
).
path
,
@d2
.
avatar
.
to_file
(
style
).
path
assert_equal
@dummy
.
avatar
.
path
(
style
),
@d2
.
avatar
.
path
(
style
)
end
end
saved_paths
=
[
:thumb
,
:medium
,
:large
,
:original
].
collect
{
|
s
|
@dummy
.
avatar
.
to_file
(
s
).
path
}
saved_paths
=
[
:thumb
,
:medium
,
:large
,
:original
].
collect
{
|
s
|
@dummy
.
avatar
.
path
(
s
)
}
@d2
.
avatar
=
nil
@d2
.
avatar
=
nil
assert
@d2
.
save
assert
@d2
.
save
...
@@ -203,7 +203,8 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -203,7 +203,8 @@ class IntegrationTest < Test::Unit::TestCase
expected
=
@dummy
.
avatar
.
to_file
expected
=
@dummy
.
avatar
.
to_file
@dummy
.
avatar
=
"not a file"
@dummy
.
avatar
=
"not a file"
assert
@dummy
.
valid?
assert
@dummy
.
valid?
assert_equal
expected
.
path
,
@dummy
.
avatar
.
to_file
.
path
assert_equal
expected
.
path
,
@dummy
.
avatar
.
path
expected
.
close
@dummy
.
avatar
=
@bad_file
@dummy
.
avatar
=
@bad_file
assert
!
@dummy
.
valid?
assert
!
@dummy
.
valid?
...
@@ -234,19 +235,19 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -234,19 +235,19 @@ class IntegrationTest < Test::Unit::TestCase
context
"that is assigned its file from another Paperclip attachment"
do
context
"that is assigned its file from another Paperclip attachment"
do
setup
do
setup
do
@dummy2
=
Dummy
.
new
@dummy2
=
Dummy
.
new
@file2
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"12k.png"
))
@file2
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"12k.png"
)
,
'rb'
)
assert
@dummy2
.
avatar
=
@file2
assert
@dummy2
.
avatar
=
@file2
@dummy2
.
save
@dummy2
.
save
end
end
should
"work when assigned a file"
do
should
"work when assigned a file"
do
assert_not_equal
`identify -format "%wx%h"
#{
@dummy
.
avatar
.
to_file
(
:original
).
path
}
`
,
assert_not_equal
`identify -format "%wx%h"
"
#{
@dummy
.
avatar
.
path
(
:original
)
}
"
`
,
`identify -format "%wx%h"
#{
@dummy2
.
avatar
.
to_file
(
:original
).
path
}
`
`identify -format "%wx%h"
"
#{
@dummy2
.
avatar
.
path
(
:original
)
}
"
`
assert
@dummy
.
avatar
=
@dummy2
.
avatar
assert
@dummy
.
avatar
=
@dummy2
.
avatar
@dummy
.
save
@dummy
.
save
assert_equal
`identify -format "%wx%h"
#{
@dummy
.
avatar
.
to_file
(
:original
).
path
}
`
,
assert_equal
`identify -format "%wx%h"
"
#{
@dummy
.
avatar
.
path
(
:original
)
}
"
`
,
`identify -format "%wx%h"
#{
@dummy2
.
avatar
.
to_file
(
:original
).
path
}
`
`identify -format "%wx%h"
"
#{
@dummy2
.
avatar
.
path
(
:original
)
}
"
`
end
end
should
"work when assigned a nil file"
do
should
"work when assigned a nil file"
do
...
@@ -265,8 +266,9 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -265,8 +266,9 @@ class IntegrationTest < Test::Unit::TestCase
if
ENV
[
'S3_TEST_BUCKET'
]
if
ENV
[
'S3_TEST_BUCKET'
]
def
s3_files_for
attachment
def
s3_files_for
attachment
[
:thumb
,
:medium
,
:large
,
:original
].
inject
({})
do
|
files
,
style
|
[
:thumb
,
:medium
,
:large
,
:original
].
inject
({})
do
|
files
,
style
|
data
=
`curl
'
#{
attachment
.
url
(
style
)
}
'
2>/dev/null`
.
chomp
data
=
`curl
"
#{
attachment
.
url
(
style
)
}
"
2>/dev/null`
.
chomp
t
=
Tempfile
.
new
(
"paperclip-test"
)
t
=
Tempfile
.
new
(
"paperclip-test"
)
t
.
binmode
t
.
write
(
data
)
t
.
write
(
data
)
t
.
rewind
t
.
rewind
files
[
style
]
=
t
files
[
style
]
=
t
...
@@ -275,7 +277,7 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -275,7 +277,7 @@ class IntegrationTest < Test::Unit::TestCase
end
end
def
s3_headers_for
attachment
,
style
def
s3_headers_for
attachment
,
style
`curl --head
'
#{
attachment
.
url
(
style
)
}
'
2>/dev/null`
.
split
(
"
\n
"
).
inject
({})
do
|
h
,
head
|
`curl --head
"
#{
attachment
.
url
(
style
)
}
"
2>/dev/null`
.
split
(
"
\n
"
).
inject
({})
do
|
h
,
head
|
split_head
=
head
.
chomp
.
split
(
/\s*:\s*/
,
2
)
split_head
=
head
.
chomp
.
split
(
/\s*:\s*/
,
2
)
h
[
split_head
.
first
.
downcase
]
=
split_head
.
last
unless
split_head
.
empty?
h
[
split_head
.
first
.
downcase
]
=
split_head
.
last
unless
split_head
.
empty?
h
h
...
@@ -295,8 +297,8 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -295,8 +297,8 @@ class IntegrationTest < Test::Unit::TestCase
:bucket
=>
ENV
[
'S3_TEST_BUCKET'
],
:bucket
=>
ENV
[
'S3_TEST_BUCKET'
],
:path
=>
":class/:attachment/:id/:style/:basename.:extension"
:path
=>
":class/:attachment/:id/:style/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
))
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
)
,
'rb'
)
@bad_file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"bad.png"
))
@bad_file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"bad.png"
)
,
'rb'
)
assert
@dummy
.
avatar
=
@file
assert
@dummy
.
avatar
=
@file
assert
@dummy
.
valid?
assert
@dummy
.
valid?
...
@@ -310,7 +312,7 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -310,7 +312,7 @@ class IntegrationTest < Test::Unit::TestCase
[
"300x46"
,
:large
],
[
"300x46"
,
:large
],
[
"100x15"
,
:medium
],
[
"100x15"
,
:medium
],
[
"32x32"
,
:thumb
]].
each
do
|
geo
,
style
|
[
"32x32"
,
:thumb
]].
each
do
|
geo
,
style
|
cmd
=
%Q[identify -format "%wx%h"
#{
@files_on_s3
[
style
].
path
}
]
cmd
=
%Q[identify -format "%wx%h"
"
#{
@files_on_s3
[
style
].
path
}
"
]
assert_equal
geo
,
`
#{
cmd
}
`
.
chomp
,
cmd
assert_equal
geo
,
`
#{
cmd
}
`
.
chomp
,
cmd
end
end
...
@@ -320,7 +322,7 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -320,7 +322,7 @@ class IntegrationTest < Test::Unit::TestCase
[
"300x46"
,
:large
],
[
"300x46"
,
:large
],
[
"100x15"
,
:medium
],
[
"100x15"
,
:medium
],
[
"32x32"
,
:thumb
]].
each
do
|
geo
,
style
|
[
"32x32"
,
:thumb
]].
each
do
|
geo
,
style
|
cmd
=
%Q[identify -format "%wx%h"
#{
@d2_files
[
style
].
path
}
]
cmd
=
%Q[identify -format "%wx%h"
"
#{
@d2_files
[
style
].
path
}
"
]
assert_equal
geo
,
`
#{
cmd
}
`
.
chomp
,
cmd
assert_equal
geo
,
`
#{
cmd
}
`
.
chomp
,
cmd
end
end
...
...
test/iostream_test.rb
View file @
9c510875
...
@@ -11,21 +11,18 @@ class IOStreamTest < Test::Unit::TestCase
...
@@ -11,21 +11,18 @@ class IOStreamTest < Test::Unit::TestCase
context
"A file"
do
context
"A file"
do
setup
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
))
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
)
,
'rb'
)
end
end
context
"that is sent #stream_to"
do
context
"that is sent #stream_to"
do
[[
"/tmp/iostream.string.test"
,
File
],
context
"and given a String"
do
[
Tempfile
.
new
(
'iostream.test'
),
Tempfile
]].
each
do
|
args
|
context
"and given a
#{
args
[
0
].
class
.
to_s
}
"
do
setup
do
setup
do
assert
@result
=
@file
.
stream_to
(
args
[
0
]
)
assert
@result
=
@file
.
stream_to
(
"/tmp/iostream.string.test"
)
end
end
should
"return a
#{
args
[
1
].
to_s
}
"
do
should
"return a File
"
do
assert
@result
.
is_a?
(
args
[
1
]
)
assert
@result
.
is_a?
(
File
)
end
end
should
"contain the same data as the original file"
do
should
"contain the same data as the original file"
do
...
@@ -33,7 +30,24 @@ class IOStreamTest < Test::Unit::TestCase
...
@@ -33,7 +30,24 @@ class IOStreamTest < Test::Unit::TestCase
assert_equal
@file
.
read
,
@result
.
read
assert_equal
@file
.
read
,
@result
.
read
end
end
end
end
context
"and given a Tempfile"
do
setup
do
tempfile
=
Tempfile
.
new
(
'iostream.test'
)
tempfile
.
binmode
assert
@result
=
@file
.
stream_to
(
tempfile
)
end
should
"return a Tempfile"
do
assert
@result
.
is_a?
(
Tempfile
)
end
should
"contain the same data as the original file"
do
@file
.
rewind
;
@result
.
rewind
assert_equal
@file
.
read
,
@result
.
read
end
end
end
end
end
context
"that is sent #to_tempfile"
do
context
"that is sent #to_tempfile"
do
...
...
test/paperclip_test.rb
View file @
9c510875
...
@@ -35,7 +35,7 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -35,7 +35,7 @@ class PaperclipTest < Test::Unit::TestCase
context
"An ActiveRecord model with an 'avatar' attachment"
do
context
"An ActiveRecord model with an 'avatar' attachment"
do
setup
do
setup
do
rebuild_model
:path
=>
"tmp/:class/omg/:style.:extension"
rebuild_model
:path
=>
"tmp/:class/omg/:style.:extension"
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
))
@file
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"5k.png"
)
,
'rb'
)
end
end
should
"not error when trying to also create a 'blah' attachment"
do
should
"not error when trying to also create a 'blah' attachment"
do
...
@@ -176,8 +176,8 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -176,8 +176,8 @@ class PaperclipTest < Test::Unit::TestCase
[
:content_type
,
{
:content_type
=>
"text/plain"
},
"text.txt"
,
"5k.png"
],
[
:content_type
,
{
:content_type
=>
"text/plain"
},
"text.txt"
,
"5k.png"
],
[
:content_type
,
{
:content_type
=>
%r{image/.*}
},
"5k.png"
,
"text.txt"
]].
each
do
|
args
|
[
:content_type
,
{
:content_type
=>
%r{image/.*}
},
"5k.png"
,
"text.txt"
]].
each
do
|
args
|
validation
,
options
,
valid_file
,
invalid_file
=
args
validation
,
options
,
valid_file
,
invalid_file
=
args
valid_file
&&=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
valid_file
)
)
valid_file
&&=
File
.
open
(
File
.
join
(
FIXTURES_DIR
,
valid_file
),
"rb"
)
invalid_file
&&=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
invalid_file
)
)
invalid_file
&&=
File
.
open
(
File
.
join
(
FIXTURES_DIR
,
invalid_file
),
"rb"
)
should_validate
validation
,
options
,
valid_file
,
invalid_file
should_validate
validation
,
options
,
valid_file
,
invalid_file
end
end
...
...
test/storage_test.rb
View file @
9c510875
...
@@ -77,7 +77,7 @@ class StorageTest < Test::Unit::TestCase
...
@@ -77,7 +77,7 @@ class StorageTest < Test::Unit::TestCase
context
"when assigned"
do
context
"when assigned"
do
setup
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
))
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
)
,
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
...
@@ -144,7 +144,7 @@ class StorageTest < Test::Unit::TestCase
...
@@ -144,7 +144,7 @@ class StorageTest < Test::Unit::TestCase
context
"when assigned"
do
context
"when assigned"
do
setup
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
))
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
)
,
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
...
...
test/thumbnail_test.rb
View file @
9c510875
...
@@ -32,7 +32,7 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -32,7 +32,7 @@ class ThumbnailTest < Test::Unit::TestCase
context
"An image"
do
context
"An image"
do
setup
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
))
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
)
,
'rb'
)
end
end
[[
"600x600>"
,
"434x66"
],
[[
"600x600>"
,
"434x66"
],
...
@@ -45,7 +45,7 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -45,7 +45,7 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
should
"start with dimensions of 434x66"
do
should
"start with dimensions of 434x66"
do
cmd
=
%Q[identify -format "%wx%h"
#{
@file
.
path
}
]
cmd
=
%Q[identify -format "%wx%h"
"
#{
@file
.
path
}
"
]
assert_equal
"434x66"
,
`
#{
cmd
}
`
.
chomp
assert_equal
"434x66"
,
`
#{
cmd
}
`
.
chomp
end
end
...
@@ -59,7 +59,7 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -59,7 +59,7 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
should
"be the size we expect it to be"
do
should
"be the size we expect it to be"
do
cmd
=
%Q[identify -format "%wx%h"
#{
@thumb_result
.
path
}
]
cmd
=
%Q[identify -format "%wx%h"
"
#{
@thumb_result
.
path
}
"
]
assert_equal
args
[
1
],
`
#{
cmd
}
`
.
chomp
assert_equal
args
[
1
],
`
#{
cmd
}
`
.
chomp
end
end
end
end
...
@@ -97,7 +97,7 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -97,7 +97,7 @@ class ThumbnailTest < Test::Unit::TestCase
should
"create the thumbnail when sent #make"
do
should
"create the thumbnail when sent #make"
do
dst
=
@thumb
.
make
dst
=
@thumb
.
make
assert_match
/100x50/
,
`identify
#{
dst
.
path
}
`
assert_match
/100x50/
,
`identify
"
#{
dst
.
path
}
"
`
end
end
end
end
...
@@ -119,7 +119,7 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -119,7 +119,7 @@ class ThumbnailTest < Test::Unit::TestCase
should
"create the thumbnail when sent #make"
do
should
"create the thumbnail when sent #make"
do
dst
=
@thumb
.
make
dst
=
@thumb
.
make
assert_match
/100x50/
,
`identify
#{
dst
.
path
}
`
assert_match
/100x50/
,
`identify
"
#{
dst
.
path
}
"
`
end
end
context
"redefined to have bad convert_options setting"
do
context
"redefined to have bad convert_options setting"
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