2013-11-11 12:51:14 -05:00
|
|
|
require "spec_helper"
|
|
|
|
require "avatar_upload_service"
|
|
|
|
|
|
|
|
describe AvatarUploadService do
|
2014-04-14 16:55:57 -04:00
|
|
|
|
2014-07-14 11:34:23 -04:00
|
|
|
let(:logo) { file_from_fixtures("logo.png") }
|
2014-04-14 16:55:57 -04:00
|
|
|
|
2013-11-11 12:51:14 -05:00
|
|
|
let(:file) do
|
2014-04-14 16:55:57 -04:00
|
|
|
ActionDispatch::Http::UploadedFile.new({ filename: 'logo.png', tempfile: logo })
|
2013-11-11 12:51:14 -05: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
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.filesize).to be > 0
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
|
2014-04-14 16:55:57 -04:00
|
|
|
it "should have a filename" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.filename).to eq("logo.png")
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
|
2014-04-14 16:55:57 -04:00
|
|
|
it "should have a file" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.file).to eq(file.tempfile)
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
|
2014-04-14 16:55:57 -04:00
|
|
|
it "should have a source as 'image'" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.source).to eq(:image)
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when file is in the form of a URL" do
|
|
|
|
let(:avatar_file) { AvatarUploadService.new(url, :url) }
|
|
|
|
|
2014-04-14 16:55:57 -04:00
|
|
|
before { FileHelper.stubs(:download).returns(logo) }
|
2013-11-11 12:51:14 -05:00
|
|
|
|
|
|
|
it "should have a filesize" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.filesize).to be > 0
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
|
2014-04-14 16:55:57 -04:00
|
|
|
it "should have a filename" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.filename).to eq("logo.png")
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
|
2014-04-14 16:55:57 -04:00
|
|
|
it "should have a file" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.file).to eq(logo)
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
|
2014-04-14 16:55:57 -04:00
|
|
|
it "should have a source as 'url'" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(avatar_file.source).to eq(:url)
|
2013-11-11 12:51:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|