Merge pull request #1653 from ScotterC/uri-addressable

URI adapter should use Addressable
This commit is contained in:
Robin Ward 2013-11-15 07:24:57 -08:00
commit e03ae73c5d
2 changed files with 24 additions and 3 deletions

View File

@ -6,14 +6,14 @@ class UriAdapter
def initialize(target) def initialize(target)
raise Discourse::InvalidParameters unless target =~ /^https?:\/\// raise Discourse::InvalidParameters unless target =~ /^https?:\/\//
@target = URI(target) @target = Addressable::URI.parse(target)
@original_filename = ::File.basename(@target.path) @original_filename = ::File.basename(@target.path)
@content = download_content @content = download_content
@tempfile = TempfileFactory.new.generate(@original_filename) @tempfile = TempfileFactory.new.generate(@original_filename)
end end
def download_content def download_content
open(target) open(target.normalize)
end end
def copy_to_tempfile(src) def copy_to_tempfile(src)

View File

@ -14,7 +14,7 @@ describe UriAdapter do
describe "#initialize" do describe "#initialize" do
it "has a target" do it "has a target" do
subject.target.should be_instance_of(URI::HTTP) subject.target.should be_instance_of(Addressable::URI)
end end
it "has content" do it "has content" do
@ -29,6 +29,27 @@ describe UriAdapter do
subject.tempfile.should be_instance_of Tempfile subject.tempfile.should be_instance_of Tempfile
end end
describe "it handles ugly targets" do
let(:ugly_target) { "http://cdn.discourse.org/assets/logo with spaces.png" }
subject { UriAdapter.new(ugly_target) }
it "handles targets" do
subject.target.should be_instance_of(Addressable::URI)
end
it "has content" do
subject.content.should == response
end
it "has an original_filename" do
subject.original_filename.should == "logo with spaces.png"
end
it "has a tempfile" do
subject.tempfile.should be_instance_of Tempfile
end
end
end end
describe "#copy_to_tempfile" do describe "#copy_to_tempfile" do