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
ce604d66
Commit
ce604d66
authored
Aug 07, 2013
by
William Ross
Committed by
Jon Yurek
Aug 16, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accept url strings
parent
c893aa0c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
0 deletions
+101
-0
lib/paperclip.rb
+1
-0
lib/paperclip/io_adapters/url_adapter.rb
+15
-0
test/io_adapters/url_adapter_test.rb
+85
-0
No files found.
lib/paperclip.rb
View file @
ce604d66
...
...
@@ -191,3 +191,4 @@ require 'paperclip/io_adapters/nil_adapter'
require
'paperclip/io_adapters/attachment_adapter'
require
'paperclip/io_adapters/uploaded_file_adapter'
require
'paperclip/io_adapters/uri_adapter'
require
'paperclip/io_adapters/url_adapter'
lib/paperclip/io_adapters/url_adapter.rb
0 → 100644
View file @
ce604d66
module
Paperclip
class
UrlAdapter
<
UriAdapter
REGEXP
=
/^https?:\/\//
def
initialize
(
target
)
super
(
URI
(
target
))
end
end
end
Paperclip
.
io_adapters
.
register
Paperclip
::
UrlAdapter
do
|
target
|
String
===
target
&&
target
=~
Paperclip
::
UrlAdapter
::
REGEXP
end
test/io_adapters/url_adapter_test.rb
0 → 100644
View file @
ce604d66
require
'./test/helper'
class
UrlProxyTest
<
Test
::
Unit
::
TestCase
context
"a new instance"
do
setup
do
@open_return
=
StringIO
.
new
(
"xxx"
)
@open_return
.
stubs
(
:content_type
).
returns
(
"image/png"
)
Paperclip
::
UrlAdapter
.
any_instance
.
stubs
(
:download_content
).
returns
(
@open_return
)
@url
=
"http://thoughtbot.com/images/thoughtbot-logo.png"
@subject
=
Paperclip
.
io_adapters
.
for
(
@url
)
end
should
"return a file name"
do
assert_equal
"thoughtbot-logo.png"
,
@subject
.
original_filename
end
should
'close open handle after reading'
do
assert_equal
true
,
@open_return
.
closed?
end
should
"return a content type"
do
assert_equal
"image/png"
,
@subject
.
content_type
end
should
"return the size of the data"
do
assert_equal
@open_return
.
size
,
@subject
.
size
end
should
"generate an MD5 hash of the contents"
do
assert_equal
Digest
::
MD5
.
hexdigest
(
"xxx"
),
@subject
.
fingerprint
end
should
"generate correct fingerprint after read"
do
fingerprint
=
Digest
::
MD5
.
hexdigest
(
@subject
.
read
)
assert_equal
fingerprint
,
@subject
.
fingerprint
end
should
"generate same fingerprint"
do
assert_equal
@subject
.
fingerprint
,
@subject
.
fingerprint
end
should
"return the data contained in the StringIO"
do
assert_equal
"xxx"
,
@subject
.
read
end
should
'accept a content_type'
do
@subject
.
content_type
=
'image/png'
assert_equal
'image/png'
,
@subject
.
content_type
end
should
'accept an original_filename'
do
@subject
.
original_filename
=
'image.png'
assert_equal
'image.png'
,
@subject
.
original_filename
end
end
context
"a url with query params"
do
setup
do
Paperclip
::
UrlAdapter
.
any_instance
.
stubs
(
:download_content
).
returns
(
StringIO
.
new
(
"xxx"
))
@url
=
"https://github.com/thoughtbot/paperclip?file=test"
@subject
=
Paperclip
.
io_adapters
.
for
(
@url
)
end
should
"return a file name"
do
assert_equal
"paperclip"
,
@subject
.
original_filename
end
end
context
"a url with restricted characters in the filename"
do
setup
do
Paperclip
::
UrlAdapter
.
any_instance
.
stubs
(
:download_content
).
returns
(
StringIO
.
new
(
"xxx"
))
@url
=
"https://github.com/thoughtbot/paper:clip.jpg"
@subject
=
Paperclip
.
io_adapters
.
for
(
@url
)
end
should
"not generate filenames that include restricted characters"
do
assert_equal
"paper_clip.jpg"
,
@subject
.
original_filename
end
should
"not generate paths that include restricted characters"
do
assert_no_match
/:/
,
@subject
.
path
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