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
8c928584
Commit
8c928584
authored
Jul 15, 2011
by
takuyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove @region, modify s3_host_name and test
parent
81b74f6d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
lib/paperclip/storage/s3.rb
+3
-8
test/storage_test.rb
+12
-7
No files found.
lib/paperclip/storage/s3.rb
View file @
8c928584
...
@@ -66,7 +66,7 @@ module Paperclip
...
@@ -66,7 +66,7 @@ module Paperclip
# to interpolate. Keys should be unique, like filenames, and despite the fact that
# to interpolate. Keys should be unique, like filenames, and despite the fact that
# S3 (strictly speaking) does not support directories, you can still use a / to
# S3 (strictly speaking) does not support directories, you can still use a / to
# separate parts of your file name.
# separate parts of your file name.
# * +
region+: If you are using your bucket in Tokyo region, "tokyo" writ
e.
# * +
s3_host_name+: If you are using your bucket in Tokyo region etc, write host_nam
e.
module
S3
module
S3
def
self
.
extended
base
def
self
.
extended
base
begin
begin
...
@@ -78,7 +78,7 @@ module Paperclip
...
@@ -78,7 +78,7 @@ module Paperclip
base
.
instance_eval
do
base
.
instance_eval
do
@s3_credentials
=
parse_credentials
(
@options
[
:s3_credentials
])
@s3_credentials
=
parse_credentials
(
@options
[
:s3_credentials
])
@
region
=
@options
[
:region
]
||
@s3_credentials
[
:region
]
@
s3_host_name
=
@options
[
:s3_host_name
]
||
@s3_credentials
[
:s3_host_name
]
@bucket
=
@options
[
:bucket
]
||
@s3_credentials
[
:bucket
]
@bucket
=
@options
[
:bucket
]
||
@s3_credentials
[
:bucket
]
@bucket
=
@bucket
.
call
(
self
)
if
@bucket
.
is_a?
(
Proc
)
@bucket
=
@bucket
.
call
(
self
)
if
@bucket
.
is_a?
(
Proc
)
@s3_options
=
@options
[
:s3_options
]
||
{}
@s3_options
=
@options
[
:s3_options
]
||
{}
...
@@ -123,12 +123,7 @@ module Paperclip
...
@@ -123,12 +123,7 @@ module Paperclip
end
end
def
s3_host_name
def
s3_host_name
case
@region
@s3_host_name
||
"s3.amazonaws.com"
when
"tokyo"
"s3-ap-northeast-1.amazonaws.com"
else
"s3.amazonaws.com"
end
end
end
def
set_permissions
permissions
def
set_permissions
permissions
...
...
test/storage_test.rb
View file @
8c928584
...
@@ -79,19 +79,19 @@ class StorageTest < Test::Unit::TestCase
...
@@ -79,19 +79,19 @@ class StorageTest < Test::Unit::TestCase
end
end
end
end
context
"
S3 Tokyo Region
"
do
context
"
s3_host_name
"
do
setup
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
rebuild_model
:storage
=>
:s3
,
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
{},
:s3_credentials
=>
{},
:bucket
=>
"bucket"
,
:bucket
=>
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
:path
=>
":attachment/:basename.:extension"
,
:
region
=>
"tokyo
"
:
s3_host_name
=>
"s3-ap-northeast-1.amazonaws.com
"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
end
end
should
"return a url based on an
S3@tokyo
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/stringio.txt}
,
@dummy
.
avatar
.
url
end
end
end
end
...
@@ -277,26 +277,31 @@ class StorageTest < Test::Unit::TestCase
...
@@ -277,26 +277,31 @@ class StorageTest < Test::Unit::TestCase
end
end
end
end
context
"Parsing S3 credentials with a
region
in them"
do
context
"Parsing S3 credentials with a
s3_host_name
in them"
do
setup
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
rebuild_model
:storage
=>
:s3
,
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
{
:s3_credentials
=>
{
:production
=>
{
:region
=>
"us"
},
:production
=>
{
:s3_host_name
=>
"s3-world-end.amazonaws.com"
},
:development
=>
{
:
region
=>
"tokyo
"
}
:development
=>
{
:
s3_host_name
=>
"s3-ap-northeast-1.amazonaws.com
"
}
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
should
"get the right s3_host_name in production"
do
should
"get the right s3_host_name in production"
do
rails_env
(
"production"
)
rails_env
(
"production"
)
assert_match
%r{^s3.amazonaws.com}
,
@dummy
.
avatar
.
s3_host_name
assert_match
%r{^s3
-world-end
.amazonaws.com}
,
@dummy
.
avatar
.
s3_host_name
end
end
should
"get the right s3_host_name in development"
do
should
"get the right s3_host_name in development"
do
rails_env
(
"development"
)
rails_env
(
"development"
)
assert_match
%r{^s3-ap-northeast-1.amazonaws.com}
,
@dummy
.
avatar
.
s3_host_name
assert_match
%r{^s3-ap-northeast-1.amazonaws.com}
,
@dummy
.
avatar
.
s3_host_name
end
end
should
"get the right s3_host_name if the key does not exist"
do
rails_env
(
"test"
)
assert_match
%r{^s3.amazonaws.com}
,
@dummy
.
avatar
.
s3_host_name
end
end
end
context
"An attachment with S3 storage"
do
context
"An attachment with S3 storage"
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