2015-02-14 10:04:45 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe Projects::UploadService, services: true do
|
2015-02-14 10:04:45 -05:00
|
|
|
describe 'File service' do
|
|
|
|
before do
|
|
|
|
@user = create :user
|
|
|
|
@project = create :project, creator_id: @user.id, namespace: @user.namespace
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for valid gif file' do
|
|
|
|
before do
|
|
|
|
gif = fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif')
|
2015-02-16 13:58:40 -05:00
|
|
|
@link_to_file = upload_file(@project.repository, gif)
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file).to have_key(:alt) }
|
|
|
|
it { expect(@link_to_file).to have_key(:url) }
|
2015-02-14 10:04:45 -05:00
|
|
|
it { expect(@link_to_file).to have_value('banana_sample') }
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file[:url]).to match('banana_sample.gif') }
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
2015-06-22 14:33:01 -04:00
|
|
|
context 'for valid png file' do
|
2015-02-14 10:04:45 -05:00
|
|
|
before do
|
|
|
|
png = fixture_file_upload(Rails.root + 'spec/fixtures/dk.png',
|
|
|
|
'image/png')
|
2015-02-16 13:58:40 -05:00
|
|
|
@link_to_file = upload_file(@project.repository, png)
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file).to have_key(:alt) }
|
|
|
|
it { expect(@link_to_file).to have_key(:url) }
|
2015-02-14 10:04:45 -05:00
|
|
|
it { expect(@link_to_file).to have_value('dk') }
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file[:url]).to match('dk.png') }
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
2015-06-22 14:33:01 -04:00
|
|
|
context 'for valid jpg file' do
|
2015-02-14 10:04:45 -05:00
|
|
|
before do
|
|
|
|
jpg = fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg')
|
2015-02-16 13:58:40 -05:00
|
|
|
@link_to_file = upload_file(@project.repository, jpg)
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file).to have_key(:alt) }
|
|
|
|
it { expect(@link_to_file).to have_key(:url) }
|
2015-02-14 10:04:45 -05:00
|
|
|
it { expect(@link_to_file).to have_value('rails_sample') }
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file[:url]).to match('rails_sample.jpg') }
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for txt file' do
|
|
|
|
before do
|
|
|
|
txt = fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain')
|
2015-02-16 13:58:40 -05:00
|
|
|
@link_to_file = upload_file(@project.repository, txt)
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file).to have_key(:alt) }
|
|
|
|
it { expect(@link_to_file).to have_key(:url) }
|
2015-02-14 10:04:45 -05:00
|
|
|
it { expect(@link_to_file).to have_value('doc_sample.txt') }
|
2015-08-20 14:33:35 -04:00
|
|
|
it { expect(@link_to_file[:url]).to match('doc_sample.txt') }
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
2015-03-20 08:11:12 -04:00
|
|
|
|
|
|
|
context 'for too large a file' do
|
|
|
|
before do
|
|
|
|
txt = fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain')
|
|
|
|
allow(txt).to receive(:size) { 1000.megabytes.to_i }
|
|
|
|
@link_to_file = upload_file(@project.repository, txt)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@link_to_file).to eq(nil) }
|
|
|
|
end
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
2015-02-16 13:58:40 -05:00
|
|
|
def upload_file(repository, file)
|
|
|
|
Projects::UploadService.new(repository, file).execute
|
2015-02-14 10:04:45 -05:00
|
|
|
end
|
|
|
|
end
|