added some tests for uploads

This commit is contained in:
Régis Hanol
2013-04-07 17:52:46 +02:00
parent d5c0dd7fa0
commit 1692350336
5 changed files with 122 additions and 47 deletions

View File

@@ -25,7 +25,7 @@ describe UploadsController do
let(:logo) do
ActionDispatch::Http::UploadedFile.new({
filename: 'logo.png',
content_type: 'image/png',
type: 'image/png',
tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo.png")
})
end
@@ -33,11 +33,19 @@ describe UploadsController do
let(:logo_dev) do
ActionDispatch::Http::UploadedFile.new({
filename: 'logo-dev.png',
content_type: 'image/png',
type: 'image/png',
tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo-dev.png")
})
end
let(:text_file) do
ActionDispatch::Http::UploadedFile.new({
filename: 'LICENSE.txt',
type: 'text/plain',
tempfile: File.new("#{Rails.root}/LICENSE.txt")
})
end
let(:files) { [ logo_dev, logo ] }
context 'with a file' do
@@ -45,6 +53,11 @@ describe UploadsController do
xhr :post, :create, topic_id: 1234, file: logo
response.should be_success
end
it 'supports only images' do
xhr :post, :create, topic_id: 1234, file: text_file
response.status.should eq 415
end
end
context 'with some files' do

View File

@@ -4,6 +4,58 @@ describe Upload do
it { should belong_to :user }
it { should belong_to :topic }
it { should validate_presence_of :original_filename }
it { should validate_presence_of :filesize }
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
end