2013-10-18 10:33:19 -04:00
|
|
|
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
|
2013-11-14 12:58:06 -05:00
|
|
|
subject.target.should be_instance_of(Addressable::URI)
|
2013-10-18 10:33:19 -04:00
|
|
|
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
|
|
|
|
|
2013-11-14 12:58:06 -05:00
|
|
|
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
|
|
|
|
|
2013-10-18 10:33:19 -04:00
|
|
|
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
|