2013-04-02 19:17:17 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UploadsController do
|
|
|
|
|
|
|
|
it 'requires you to be logged in' do
|
|
|
|
-> { xhr :post, :create }.should raise_error(Discourse::NotLoggedIn)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'logged in' do
|
|
|
|
|
|
|
|
before do
|
|
|
|
@user = log_in :user
|
|
|
|
end
|
|
|
|
|
|
|
|
context '.create' do
|
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
let(:logo) do
|
|
|
|
ActionDispatch::Http::UploadedFile.new({
|
|
|
|
filename: 'logo.png',
|
|
|
|
type: 'image/png',
|
|
|
|
tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
})
|
2013-04-02 19:17:17 -04:00
|
|
|
end
|
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
let(:logo_dev) do
|
|
|
|
ActionDispatch::Http::UploadedFile.new({
|
|
|
|
filename: 'logo-dev.png',
|
|
|
|
type: 'image/png',
|
|
|
|
tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo-dev.png")
|
|
|
|
})
|
|
|
|
end
|
2013-04-02 19:17:17 -04:00
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
let(:text_file) do
|
|
|
|
ActionDispatch::Http::UploadedFile.new({
|
|
|
|
filename: 'LICENSE.txt',
|
|
|
|
type: 'text/plain',
|
|
|
|
tempfile: File.new("#{Rails.root}/LICENSE.txt")
|
|
|
|
})
|
|
|
|
end
|
2013-04-02 19:17:17 -04:00
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
let(:files) { [ logo_dev, logo ] }
|
2013-04-02 19:17:17 -04:00
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
context 'with a file' do
|
|
|
|
it 'is succesful' do
|
|
|
|
xhr :post, :create, file: logo
|
|
|
|
response.should be_success
|
2013-04-07 11:52:46 -04:00
|
|
|
end
|
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
it 'supports only images' do
|
|
|
|
xhr :post, :create, file: text_file
|
|
|
|
response.status.should eq 415
|
2013-04-02 19:17:17 -04:00
|
|
|
end
|
2013-06-15 03:54:49 -04:00
|
|
|
end
|
2013-04-02 19:17:17 -04:00
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
context 'with some files' do
|
2013-04-02 19:17:17 -04:00
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
it 'is succesful' do
|
|
|
|
xhr :post, :create, files: files
|
|
|
|
response.should be_success
|
|
|
|
end
|
2013-04-02 19:17:17 -04:00
|
|
|
|
2013-06-15 03:54:49 -04:00
|
|
|
it 'takes the first file' do
|
|
|
|
xhr :post, :create, files: files
|
|
|
|
response.body.should match /logo-dev.png/
|
2013-04-02 19:17:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|