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
508563d8
Commit
508563d8
authored
Jan 24, 2014
by
Dan Collis-Puro
Committed by
Jon Yurek
Jan 29, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix s3 test for new file naming and content type detection semantics
parent
a7313e91
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
31 deletions
+36
-31
test/helper.rb
+4
-0
test/storage/s3_test.rb
+32
-31
No files found.
test/helper.rb
View file @
508563d8
...
@@ -197,6 +197,10 @@ def with_exitstatus_returning(code)
...
@@ -197,6 +197,10 @@ def with_exitstatus_returning(code)
end
end
end
end
def
stringy_file
StringIO
.
new
(
'.\n'
)
end
def
fixture_file
(
filename
)
def
fixture_file
(
filename
)
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
filename
)
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
filename
)
end
end
...
...
test/storage/s3_test.rb
View file @
508563d8
...
@@ -92,7 +92,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -92,7 +92,7 @@ class S3Test < Test::Unit::TestCase
:s3_credentials
=>
{
:not
=>
:important
}
:s3_credentials
=>
{
:not
=>
:important
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -111,11 +111,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -111,11 +111,11 @@ class S3Test < Test::Unit::TestCase
:path
=>
":attachment/:basename.:extension"
,
:path
=>
":attachment/:basename.:extension"
,
:url
=>
":s3_path_url"
:url
=>
":s3_path_url"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on an S3 path"
do
should
"return a url based on an S3 path"
do
assert_match
%r{^http://s3.amazonaws.com/bucket/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://s3.amazonaws.com/bucket/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
should
"use the correct bucket"
do
should
"use the correct bucket"
do
...
@@ -123,7 +123,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -123,7 +123,7 @@ class S3Test < Test::Unit::TestCase
end
end
should
"use the correct key"
do
should
"use the correct key"
do
assert_equal
"avatars/
stringio
.txt"
,
@dummy
.
avatar
.
s3_object
.
key
assert_equal
"avatars/
data
.txt"
,
@dummy
.
avatar
.
s3_object
.
key
end
end
end
end
...
@@ -151,11 +151,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -151,11 +151,11 @@ class S3Test < Test::Unit::TestCase
:bucket
=>
"bucket"
,
:bucket
=>
"bucket"
,
:path
=>
":attachment/:basename.:extension"
:path
=>
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on an S3 path"
do
should
"return a url based on an S3 path"
do
assert_match
%r{^https://s3.amazonaws.com/bucket/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^https://s3.amazonaws.com/bucket/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
end
end
...
@@ -167,11 +167,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -167,11 +167,11 @@ class S3Test < Test::Unit::TestCase
:bucket
=>
"bucket"
,
:bucket
=>
"bucket"
,
:path
=>
":attachment/:basename.:extension"
:path
=>
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on an S3 path"
do
should
"return a url based on an S3 path"
do
assert_match
%r{^https://s3.amazonaws.com/bucket/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^https://s3.amazonaws.com/bucket/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
end
end
...
@@ -183,11 +183,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -183,11 +183,11 @@ class S3Test < Test::Unit::TestCase
:bucket
=>
"bucket"
,
:bucket
=>
"bucket"
,
:path
=>
":attachment/:basename.:extension"
:path
=>
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on an S3 path"
do
should
"return a url based on an S3 path"
do
assert_match
%r{^//s3.amazonaws.com/bucket/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^//s3.amazonaws.com/bucket/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
end
end
...
@@ -205,16 +205,16 @@ class S3Test < Test::Unit::TestCase
...
@@ -205,16 +205,16 @@ class S3Test < Test::Unit::TestCase
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
@avatar
=
@dummy
.
avatar
@avatar
=
@dummy
.
avatar
end
end
should
"use an S3 object based on the correct path for the default style"
do
should
"use an S3 object based on the correct path for the default style"
do
assert_equal
(
"avatars/original/
stringio
.txt"
,
@dummy
.
avatar
.
s3_object
.
key
)
assert_equal
(
"avatars/original/
data
.txt"
,
@dummy
.
avatar
.
s3_object
.
key
)
end
end
should
"use an S3 object based on the correct path for the custom style"
do
should
"use an S3 object based on the correct path for the custom style"
do
assert_equal
(
"avatars/thumb/
stringio
.txt"
,
@dummy
.
avatar
.
s3_object
(
:thumb
).
key
)
assert_equal
(
"avatars/thumb/
data
.txt"
,
@dummy
.
avatar
.
s3_object
(
:thumb
).
key
)
end
end
end
end
...
@@ -226,11 +226,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -226,11 +226,11 @@ class S3Test < Test::Unit::TestCase
:path
=>
":attachment/:basename.:extension"
,
:path
=>
":attachment/:basename.:extension"
,
:s3_host_name
=>
"s3-ap-northeast-1.amazonaws.com"
:s3_host_name
=>
"s3-ap-northeast-1.amazonaws.com"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on an :s3_host_name path"
do
should
"return a url based on an :s3_host_name path"
do
assert_match
%r{^http://s3-ap-northeast-1.amazonaws.com/bucket/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://s3-ap-northeast-1.amazonaws.com/bucket/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
should
"use the S3 bucket with the correct host name"
do
should
"use the S3 bucket with the correct host name"
do
...
@@ -249,12 +249,12 @@ class S3Test < Test::Unit::TestCase
...
@@ -249,12 +249,12 @@ class S3Test < Test::Unit::TestCase
class
<<
@dummy
class
<<
@dummy
attr_accessor
:value
attr_accessor
:value
end
end
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"use s3_host_name as a proc if available"
do
should
"use s3_host_name as a proc if available"
do
@dummy
.
value
=
"s3.something.com"
@dummy
.
value
=
"s3.something.com"
assert_equal
"http://s3.something.com/bucket/avatars/
stringio
.txt"
,
@dummy
.
avatar
.
url
(
:original
,
:timestamp
=>
false
)
assert_equal
"http://s3.something.com/bucket/avatars/
data
.txt"
,
@dummy
.
avatar
.
url
(
:original
,
:timestamp
=>
false
)
end
end
end
end
...
@@ -366,7 +366,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -366,7 +366,7 @@ class S3Test < Test::Unit::TestCase
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
}
}
stringio
=
StringIO
.
new
(
"."
)
stringio
=
stringy_file
class
<<
stringio
class
<<
stringio
def
original_filename
def
original_filename
"question?mark.png"
"question?mark.png"
...
@@ -395,11 +395,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -395,11 +395,11 @@ class S3Test < Test::Unit::TestCase
:path
=>
":attachment/:basename.:extension"
,
:path
=>
":attachment/:basename.:extension"
,
:url
=>
":s3_domain_url"
:url
=>
":s3_domain_url"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on an S3 subdomain"
do
should
"return a url based on an S3 subdomain"
do
assert_match
%r{^http://bucket.s3.amazonaws.com/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://bucket.s3.amazonaws.com/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
end
end
...
@@ -414,11 +414,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -414,11 +414,11 @@ class S3Test < Test::Unit::TestCase
:path
=>
":attachment/:basename.:extension"
,
:path
=>
":attachment/:basename.:extension"
,
:url
=>
":s3_alias_url"
:url
=>
":s3_alias_url"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on the host_alias"
do
should
"return a url based on the host_alias"
do
assert_match
%r{^http://something.something.com/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://something.something.com/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
end
end
...
@@ -437,12 +437,12 @@ class S3Test < Test::Unit::TestCase
...
@@ -437,12 +437,12 @@ class S3Test < Test::Unit::TestCase
end
end
end
end
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"return a url based on the host_alias"
do
should
"return a url based on the host_alias"
do
assert_match
%r{^http://cdn1.example.com/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://cdn1.example.com/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://cdn2.example.com/avatars/
stringio
.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://cdn2.example.com/avatars/
data
.txt}
,
@dummy
.
avatar
.
url
end
end
should
"still return the bucket name"
do
should
"still return the bucket name"
do
...
@@ -459,11 +459,11 @@ class S3Test < Test::Unit::TestCase
...
@@ -459,11 +459,11 @@ class S3Test < Test::Unit::TestCase
:path
=>
":attachment/:basename.:extension"
,
:path
=>
":attachment/:basename.:extension"
,
:url
=>
":asset_host"
:url
=>
":asset_host"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
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/
data
\.
txt}
,
@dummy
.
avatar
.
url
end
end
end
end
...
@@ -493,7 +493,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -493,7 +493,7 @@ class S3Test < Test::Unit::TestCase
rails_env
(
"production"
)
rails_env
(
"production"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
...
@@ -508,7 +508,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -508,7 +508,7 @@ class S3Test < Test::Unit::TestCase
rails_env
(
"production"
)
rails_env
(
"production"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
...
@@ -524,8 +524,9 @@ class S3Test < Test::Unit::TestCase
...
@@ -524,8 +524,9 @@ class S3Test < Test::Unit::TestCase
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"."
)
@file
=
stringy_file
@file
.
stubs
(
:original_filename
).
returns
(
"5k.png
\n\n
"
)
@file
.
stubs
(
:original_filename
).
returns
(
"5k.png
\n\n
"
)
Paperclip
.
stubs
(
:run
).
returns
(
'image/png'
)
@file
.
stubs
(
:content_type
).
returns
(
"image/png
\n\n
"
)
@file
.
stubs
(
:content_type
).
returns
(
"image/png
\n\n
"
)
@file
.
stubs
(
:to_tempfile
).
returns
(
@file
)
@file
.
stubs
(
:to_tempfile
).
returns
(
@file
)
...
@@ -574,7 +575,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -574,7 +575,7 @@ class S3Test < Test::Unit::TestCase
rails_env
(
"production"
)
rails_env
(
"production"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
stringy_file
end
end
should
"should generate a url for the thumb"
do
should
"should generate a url for the thumb"
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