discourse/spec/models/upload_spec.rb

62 lines
1.2 KiB
Ruby
Raw Normal View History

2013-02-06 03:16:51 +08:00
require 'spec_helper'
describe Upload do
it { should belong_to :user }
it { should belong_to :topic }
2013-04-07 23:52:46 +08:00
2013-02-06 03:16:51 +08:00
it { should validate_presence_of :original_filename }
it { should validate_presence_of :filesize }
2013-04-07 23:52:46 +08:00
context '.create_for' do
let(:user_id) { 1 }
let(:topic_id) { 42 }
let(:logo) do
ActionDispatch::Http::UploadedFile.new({
filename: 'logo.png',
content_type: 'image/png',
tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo.png")
})
end
it "uses imgur when it is enabled" do
SiteSetting.stubs(:enable_imgur?).returns(true)
Upload.expects(:create_on_imgur).with(user_id, logo, topic_id)
Upload.create_for(user_id, logo, topic_id)
end
it "uses s3 when it is enabled" do
SiteSetting.stubs(:enable_s3_uploads?).returns(true)
Upload.expects(:create_on_s3).with(user_id, logo, topic_id)
Upload.create_for(user_id, logo, topic_id)
end
it "uses local storage otherwise" do
Upload.expects(:create_locally).with(user_id, logo, topic_id)
Upload.create_for(user_id, logo, topic_id)
end
context 'imgur' do
# TODO
end
context 's3' do
# TODO
end
context 'local' do
# TODO
end
end
2013-02-06 03:16:51 +08:00
end