mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
added some tests for uploads
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user