2013-11-12 01:51:14 +08:00
|
|
|
require "spec_helper"
|
|
|
|
require "avatar_upload_service"
|
|
|
|
|
|
|
|
describe AvatarUploadService do
|
2014-04-15 04:55:57 +08:00
|
|
|
|
|
|
|
let(:logo) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") }
|
|
|
|
|
2013-11-12 01:51:14 +08:00
|
|
|
let(:file) do
|
2014-04-15 04:55:57 +08:00
|
|
|
ActionDispatch::Http::UploadedFile.new({ filename: 'logo.png', tempfile: logo })
|
2013-11-12 01:51:14 +08:00
|
|
|
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
|
2014-04-15 04:55:57 +08:00
|
|
|
avatar_file.filesize.should == 2290
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
|
2014-04-15 04:55:57 +08:00
|
|
|
it "should have a filename" do
|
|
|
|
avatar_file.filename.should == "logo.png"
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
|
2014-04-15 04:55:57 +08:00
|
|
|
it "should have a file" do
|
|
|
|
avatar_file.file.should == file.tempfile
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
|
2014-04-15 04:55:57 +08:00
|
|
|
it "should have a source as 'image'" do
|
|
|
|
avatar_file.source.should == :image
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when file is in the form of a URL" do
|
|
|
|
let(:avatar_file) { AvatarUploadService.new(url, :url) }
|
|
|
|
|
2014-04-15 04:55:57 +08:00
|
|
|
before { FileHelper.stubs(:download).returns(logo) }
|
2013-11-12 01:51:14 +08:00
|
|
|
|
|
|
|
it "should have a filesize" do
|
2014-04-15 04:55:57 +08:00
|
|
|
avatar_file.filesize.should == 2290
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
|
2014-04-15 04:55:57 +08:00
|
|
|
it "should have a filename" do
|
|
|
|
avatar_file.filename.should == "logo.png"
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
|
2014-04-15 04:55:57 +08:00
|
|
|
it "should have a file" do
|
|
|
|
avatar_file.file.should == logo
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
|
2014-04-15 04:55:57 +08:00
|
|
|
it "should have a source as 'url'" do
|
|
|
|
avatar_file.source.should == :url
|
2013-11-12 01:51:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|