mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 15:15:50 +08:00
cbef844a57
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.
51 lines
1.3 KiB
Ruby
51 lines
1.3 KiB
Ruby
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 |