2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-04 22:21:12 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe Projects::DownloadService do
|
2015-08-04 22:21:12 +00:00
|
|
|
describe 'File service' do
|
|
|
|
before do
|
2017-03-27 21:14:01 +00:00
|
|
|
@user = create(:user)
|
2017-08-02 19:55:11 +00:00
|
|
|
@project = create(:project, creator_id: @user.id, namespace: @user.namespace)
|
2015-08-04 22:21:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a URL that is not on whitelist' do
|
|
|
|
before do
|
|
|
|
url = 'https://code.jquery.com/jquery-2.1.4.min.js'
|
|
|
|
@link_to_file = download_file(@project, url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@link_to_file).to eq(nil) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for URLs that are on the whitelist' do
|
|
|
|
before do
|
2019-07-24 02:46:37 +00:00
|
|
|
stub_request(:get, 'http://mycompany.fogbugz.com/rails_sample.jpg').to_return(body: File.read(Rails.root + 'spec/fixtures/rails_sample.jpg'))
|
|
|
|
stub_request(:get, 'http://mycompany.fogbugz.com/doc_sample.txt').to_return(body: File.read(Rails.root + 'spec/fixtures/doc_sample.txt'))
|
2015-08-04 22:21:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'an image file' do
|
|
|
|
before do
|
|
|
|
url = 'http://mycompany.fogbugz.com/rails_sample.jpg'
|
|
|
|
@link_to_file = download_file(@project, url)
|
|
|
|
end
|
|
|
|
|
2016-01-08 16:38:53 +00:00
|
|
|
it { expect(@link_to_file).to have_key(:alt) }
|
|
|
|
it { expect(@link_to_file).to have_key(:url) }
|
|
|
|
it { expect(@link_to_file[:url]).to match('rails_sample.jpg') }
|
|
|
|
it { expect(@link_to_file[:alt]).to eq('rails_sample') }
|
2015-08-04 22:21:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'a txt file' do
|
|
|
|
before do
|
|
|
|
url = 'http://mycompany.fogbugz.com/doc_sample.txt'
|
|
|
|
@link_to_file = download_file(@project, url)
|
|
|
|
end
|
|
|
|
|
2016-01-08 16:38:53 +00:00
|
|
|
it { expect(@link_to_file).to have_key(:alt) }
|
|
|
|
it { expect(@link_to_file).to have_key(:url) }
|
|
|
|
it { expect(@link_to_file[:url]).to match('doc_sample.txt') }
|
|
|
|
it { expect(@link_to_file[:alt]).to eq('doc_sample.txt') }
|
2015-08-04 22:21:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def download_file(repository, url)
|
|
|
|
Projects::DownloadService.new(repository, url).execute
|
|
|
|
end
|
|
|
|
end
|