Commit a12dec10 by Jon Yurek

Changed the name of the URL adapter, fix "too many files"

parent ce604d66
......@@ -191,4 +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'
require 'paperclip/io_adapters/http_url_proxy_adapter'
module Paperclip
class UrlAdapter < UriAdapter
class HttpUrlProxyAdapter < UriAdapter
REGEXP = /^https?:\/\//
......@@ -10,6 +10,6 @@ module Paperclip
end
end
Paperclip.io_adapters.register Paperclip::UrlAdapter do |target|
String === target && target =~ Paperclip::UrlAdapter::REGEXP
Paperclip.io_adapters.register Paperclip::HttpUrlProxyAdapter do |target|
String === target && target =~ Paperclip::HttpUrlProxyAdapter::REGEXP
end
require './test/helper'
class UrlProxyTest < Test::Unit::TestCase
class HttpUrlProxyAdapterTest < 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)
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).returns(@open_return)
@url = "http://thoughtbot.com/images/thoughtbot-logo.png"
@subject = Paperclip.io_adapters.for(@url)
end
teardown do
@subject.close
end
should "return a file name" do
assert_equal "thoughtbot-logo.png", @subject.original_filename
end
......@@ -56,11 +60,15 @@ class UrlProxyTest < Test::Unit::TestCase
context "a url with query params" do
setup do
Paperclip::UrlAdapter.any_instance.stubs(:download_content).returns(StringIO.new("xxx"))
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).returns(StringIO.new("x"))
@url = "https://github.com/thoughtbot/paperclip?file=test"
@subject = Paperclip.io_adapters.for(@url)
end
teardown do
@subject.close
end
should "return a file name" do
assert_equal "paperclip", @subject.original_filename
end
......@@ -68,11 +76,20 @@ class UrlProxyTest < Test::Unit::TestCase
context "a url with restricted characters in the filename" do
setup do
Paperclip::UrlAdapter.any_instance.stubs(:download_content).returns(StringIO.new("xxx"))
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).returns(StringIO.new("x"))
@url = "https://github.com/thoughtbot/paper:clip.jpg"
@subject = Paperclip.io_adapters.for(@url)
end
teardown do
begin
@subject.close
rescue Exception => e
binding.pry
true
end
end
should "not generate filenames that include restricted characters" do
assert_equal "paper_clip.jpg", @subject.original_filename
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment