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
31d74d66
Commit
31d74d66
authored
Sep 23, 2011
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split test cases for multiple storages
parent
1738f3c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
88 deletions
+95
-88
test/storage/filesystem_test.rb
+34
-0
test/storage/s3_live_test.rb
+51
-0
test/storage/s3_test.rb
+10
-88
No files found.
test/storage/filesystem_test.rb
0 → 100644
View file @
31d74d66
require
'helper'
class
FileSystemTest
<
Test
::
Unit
::
TestCase
context
"Filesystem"
do
setup
do
rebuild_model
:styles
=>
{
:thumbnail
=>
"25x25#"
}
@dummy
=
Dummy
.
create!
@dummy
.
avatar
=
File
.
open
(
File
.
join
(
File
.
dirname
(
__FILE__
),
".."
,
"fixtures"
,
"5k.png"
))
end
should
"allow file assignment"
do
assert
@dummy
.
save
end
should
"store the original"
do
@dummy
.
save
assert
File
.
exists?
(
@dummy
.
avatar
.
path
)
end
should
"store the thumbnail"
do
@dummy
.
save
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:thumbnail
))
end
should
"clean up file objects"
do
File
.
stubs
(
:exist?
).
returns
(
true
)
Paperclip
::
Tempfile
.
any_instance
.
expects
(
:close
).
at_least_once
()
Paperclip
::
Tempfile
.
any_instance
.
expects
(
:unlink
).
at_least_once
()
@dummy
.
save!
end
end
end
test/storage/s3_live_test.rb
0 → 100644
View file @
31d74d66
require
'helper'
require
'aws/s3'
class
S3LiveTest
<
Test
::
Unit
::
TestCase
unless
ENV
[
"S3_TEST_BUCKET"
].
blank?
context
"Using S3 for real, an attachment with S3 storage"
do
setup
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:square
=>
"32x32#"
},
:storage
=>
:s3
,
:bucket
=>
ENV
[
"S3_TEST_BUCKET"
],
:path
=>
":class/:attachment/:id/:style.:extension"
,
:s3_credentials
=>
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
".."
,
"s3.yml"
))
Dummy
.
delete_all
@dummy
=
Dummy
.
new
end
should
"be extended by the S3 module"
do
assert
Dummy
.
new
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
S3
)
end
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'fixtures'
,
'5k.png'
),
'rb'
)
@dummy
.
avatar
=
@file
end
teardown
{
@file
.
close
}
should
"still return a Tempfile when sent #to_file"
do
assert_equal
Paperclip
::
Tempfile
,
@dummy
.
avatar
.
to_file
.
class
end
context
"and saved"
do
setup
do
@dummy
.
save
end
should
"be on S3"
do
assert
true
end
should
"generate a tempfile with the right name"
do
file
=
@dummy
.
avatar
.
to_file
assert_match
/^original.*\.png$/
,
File
.
basename
(
file
.
path
)
end
end
end
end
end
end
test/storage_test.rb
→
test/storage
/s3
_test.rb
View file @
31d74d66
require
'
./test/
helper'
require
'helper'
require
'aws/s3'
class
S
torage
Test
<
Test
::
Unit
::
TestCase
class
S
3
Test
<
Test
::
Unit
::
TestCase
def
rails_env
(
env
)
silence_warnings
do
Object
.
const_set
(
:Rails
,
stub
(
'Rails'
,
:env
=>
env
))
end
end
context
"filesystem"
do
setup
do
rebuild_model
:styles
=>
{
:thumbnail
=>
"25x25#"
}
@dummy
=
Dummy
.
create!
@dummy
.
avatar
=
File
.
open
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
))
end
should
"allow file assignment"
do
assert
@dummy
.
save
end
should
"store the original"
do
@dummy
.
save
assert
File
.
exists?
(
@dummy
.
avatar
.
path
)
end
should
"store the thumbnail"
do
@dummy
.
save
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:thumbnail
))
end
should
"clean up file objects"
do
File
.
stubs
(
:exist?
).
returns
(
true
)
Paperclip
::
Tempfile
.
any_instance
.
expects
(
:close
).
at_least_once
()
Paperclip
::
Tempfile
.
any_instance
.
expects
(
:unlink
).
at_least_once
()
@dummy
.
save!
end
end
context
"Parsing S3 credentials"
do
setup
do
@proxy_settings
=
{
:host
=>
"127.0.0.1"
,
:port
=>
8888
,
:user
=>
"foo"
,
:password
=>
"bar"
}
...
...
@@ -129,7 +98,7 @@ class StorageTest < Test::Unit::TestCase
}
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
@dummy
.
avatar
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'
..'
,
'
fixtures'
,
'5k.png'
),
'rb'
)
end
should
"return a url containing the correct original file mime type"
do
...
...
@@ -345,7 +314,7 @@ class StorageTest < Test::Unit::TestCase
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'
..'
,
'
fixtures'
,
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
end
...
...
@@ -436,7 +405,7 @@ class StorageTest < Test::Unit::TestCase
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'
..'
,
'
fixtures'
,
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
end
...
...
@@ -471,7 +440,7 @@ class StorageTest < Test::Unit::TestCase
rails_env
(
'test'
)
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
Pathname
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
))).
join
(
"fixtures/s3.yml"
)
:s3_credentials
=>
Pathname
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
))).
join
(
"
../
fixtures/s3.yml"
)
Dummy
.
delete_all
@dummy
=
Dummy
.
new
...
...
@@ -493,7 +462,7 @@ class StorageTest < Test::Unit::TestCase
rails_env
(
'test'
)
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures/s3.yml"
))
:s3_credentials
=>
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"
../
fixtures/s3.yml"
))
Dummy
.
delete_all
...
...
@@ -521,7 +490,7 @@ class StorageTest < Test::Unit::TestCase
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'
..'
,
'
fixtures'
,
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
end
...
...
@@ -560,7 +529,7 @@ class StorageTest < Test::Unit::TestCase
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'
..'
,
'
fixtures'
,
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
end
...
...
@@ -605,7 +574,7 @@ class StorageTest < Test::Unit::TestCase
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'
..'
,
'
fixtures'
,
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
end
...
...
@@ -632,51 +601,4 @@ class StorageTest < Test::Unit::TestCase
end
end
end
unless
ENV
[
"S3_TEST_BUCKET"
].
blank?
context
"Using S3 for real, an attachment with S3 storage"
do
setup
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:square
=>
"32x32#"
},
:storage
=>
:s3
,
:bucket
=>
ENV
[
"S3_TEST_BUCKET"
],
:path
=>
":class/:attachment/:id/:style.:extension"
,
:s3_credentials
=>
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"s3.yml"
))
Dummy
.
delete_all
@dummy
=
Dummy
.
new
end
should
"be extended by the S3 module"
do
assert
Dummy
.
new
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
S3
)
end
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
@dummy
.
avatar
=
@file
end
teardown
{
@file
.
close
}
should
"still return a Tempfile when sent #to_file"
do
assert_equal
Paperclip
::
Tempfile
,
@dummy
.
avatar
.
to_file
.
class
end
context
"and saved"
do
setup
do
@dummy
.
save
end
should
"be on S3"
do
assert
true
end
should
"generate a tempfile with the right name"
do
file
=
@dummy
.
avatar
.
to_file
assert_match
/^original.*\.png$/
,
File
.
basename
(
file
.
path
)
end
end
end
end
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