FIX: API can provide a URL to create an upload

This commit is contained in:
Régis Hanol
2015-05-20 17:38:06 +02:00
parent c91634c09a
commit bcd98c8f0f
3 changed files with 13 additions and 90 deletions

View File

@ -1,58 +0,0 @@
require "spec_helper"
require "avatar_upload_service"
describe AvatarUploadService do
let(:logo) { file_from_fixtures("logo.png") }
let(:file) do
ActionDispatch::Http::UploadedFile.new({ filename: 'logo.png', tempfile: logo })
end
let(:url) { "http://cdn.discourse.org/assets/logo.png" }
describe "#construct" do
context "when avatar is in the form of a file upload" do
let(:avatar_file) { AvatarUploadService.new(file, :image) }
it "should have a filesize" do
expect(avatar_file.filesize).to be > 0
end
it "should have a filename" do
expect(avatar_file.filename).to eq("logo.png")
end
it "should have a file" do
expect(avatar_file.file).to eq(file.tempfile)
end
it "should have a source as 'image'" do
expect(avatar_file.source).to eq(:image)
end
end
context "when file is in the form of a URL" do
let(:avatar_file) { AvatarUploadService.new(url, :url) }
before { FileHelper.stubs(:download).returns(logo) }
it "should have a filesize" do
expect(avatar_file.filesize).to be > 0
end
it "should have a filename" do
expect(avatar_file.filename).to eq("logo.png")
end
it "should have a file" do
expect(avatar_file.file).to eq(logo)
end
it "should have a source as 'url'" do
expect(avatar_file.source).to eq(:url)
end
end
end
end