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' ...@@ -191,4 +191,4 @@ require 'paperclip/io_adapters/nil_adapter'
require 'paperclip/io_adapters/attachment_adapter' require 'paperclip/io_adapters/attachment_adapter'
require 'paperclip/io_adapters/uploaded_file_adapter' require 'paperclip/io_adapters/uploaded_file_adapter'
require 'paperclip/io_adapters/uri_adapter' require 'paperclip/io_adapters/uri_adapter'
require 'paperclip/io_adapters/url_adapter' require 'paperclip/io_adapters/http_url_proxy_adapter'
module Paperclip module Paperclip
class UrlAdapter < UriAdapter class HttpUrlProxyAdapter < UriAdapter
REGEXP = /^https?:\/\// REGEXP = /^https?:\/\//
...@@ -10,6 +10,6 @@ module Paperclip ...@@ -10,6 +10,6 @@ module Paperclip
end end
end end
Paperclip.io_adapters.register Paperclip::UrlAdapter do |target| Paperclip.io_adapters.register Paperclip::HttpUrlProxyAdapter do |target|
String === target && target =~ Paperclip::UrlAdapter::REGEXP String === target && target =~ Paperclip::HttpUrlProxyAdapter::REGEXP
end end
require './test/helper' require './test/helper'
class UrlProxyTest < Test::Unit::TestCase class HttpUrlProxyAdapterTest < Test::Unit::TestCase
context "a new instance" do context "a new instance" do
setup do setup do
@open_return = StringIO.new("xxx") @open_return = StringIO.new("xxx")
@open_return.stubs(:content_type).returns("image/png") @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" @url = "http://thoughtbot.com/images/thoughtbot-logo.png"
@subject = Paperclip.io_adapters.for(@url) @subject = Paperclip.io_adapters.for(@url)
end end
teardown do
@subject.close
end
should "return a file name" do should "return a file name" do
assert_equal "thoughtbot-logo.png", @subject.original_filename assert_equal "thoughtbot-logo.png", @subject.original_filename
end end
...@@ -56,11 +60,15 @@ class UrlProxyTest < Test::Unit::TestCase ...@@ -56,11 +60,15 @@ class UrlProxyTest < Test::Unit::TestCase
context "a url with query params" do context "a url with query params" do
setup 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" @url = "https://github.com/thoughtbot/paperclip?file=test"
@subject = Paperclip.io_adapters.for(@url) @subject = Paperclip.io_adapters.for(@url)
end end
teardown do
@subject.close
end
should "return a file name" do should "return a file name" do
assert_equal "paperclip", @subject.original_filename assert_equal "paperclip", @subject.original_filename
end end
...@@ -68,11 +76,20 @@ class UrlProxyTest < Test::Unit::TestCase ...@@ -68,11 +76,20 @@ class UrlProxyTest < Test::Unit::TestCase
context "a url with restricted characters in the filename" do context "a url with restricted characters in the filename" do
setup 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" @url = "https://github.com/thoughtbot/paper:clip.jpg"
@subject = Paperclip.io_adapters.for(@url) @subject = Paperclip.io_adapters.for(@url)
end end
teardown do
begin
@subject.close
rescue Exception => e
binding.pry
true
end
end
should "not generate filenames that include restricted characters" do should "not generate filenames that include restricted characters" do
assert_equal "paper_clip.jpg", @subject.original_filename assert_equal "paper_clip.jpg", @subject.original_filename
end 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