mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Build out a URI Adapter to allow uploading an avatar via a url
Currently only really accessible via the API. The UriAdapter creates a tempfile from a url and gives a ActionDispatch::HTTP::UploadedFile back to the controller to process as normal. This will help a lot in being able to transfer avatar urls from another app without monkey patching a lot of discourse code.
This commit is contained in:
51
spec/services/uri_adapter_spec.rb
Normal file
51
spec/services/uri_adapter_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe UriAdapter do
|
||||
let(:target) { "http://cdn.discourse.org/assets/logo.png" }
|
||||
let(:response) { StringIO.new(fixture_file("images/logo.png")) }
|
||||
|
||||
before :each do
|
||||
response.stubs(:content_type).returns("image/png")
|
||||
UriAdapter.any_instance.stubs(:open).returns(response)
|
||||
end
|
||||
|
||||
subject { UriAdapter.new(target) }
|
||||
|
||||
describe "#initialize" do
|
||||
|
||||
it "has a target" do
|
||||
subject.target.should be_instance_of(URI::HTTP)
|
||||
end
|
||||
|
||||
it "has content" do
|
||||
subject.content.should == response
|
||||
end
|
||||
|
||||
it "has an original_filename" do
|
||||
subject.original_filename.should == "logo.png"
|
||||
end
|
||||
|
||||
it "has a tempfile" do
|
||||
subject.tempfile.should be_instance_of Tempfile
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#copy_to_tempfile" do
|
||||
it "does not allow files bigger then max_image_size_kb" do
|
||||
SiteSetting.stubs(:max_image_size_kb).returns(1)
|
||||
subject.build_uploaded_file.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "#build_uploaded_file" do
|
||||
it "returns an uploaded file" do
|
||||
file = subject.build_uploaded_file
|
||||
file.should be_instance_of(ActionDispatch::Http::UploadedFile)
|
||||
file.content_type.should == "image/png"
|
||||
file.original_filename.should == "logo.png"
|
||||
file.tempfile.should be_instance_of Tempfile
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user