2015-05-06 17:33:39 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::AvatarsController do
|
2018-08-30 08:34:41 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-05-06 17:33:39 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
controller.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
2018-08-30 08:34:41 -04:00
|
|
|
describe 'GET #show' do
|
2018-12-17 17:52:17 -05:00
|
|
|
subject { get :show, params: { namespace_id: project.namespace, project_id: project } }
|
2018-01-21 00:00:39 -05:00
|
|
|
|
2018-08-30 08:34:41 -04:00
|
|
|
context 'when repository has no avatar' do
|
|
|
|
it 'shows 404' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository has an avatar' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:avatar_in_git).and_return(filepath)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the avatar is stored in the repository' do
|
|
|
|
let(:filepath) { 'files/images/logo-white.png' }
|
|
|
|
|
2018-12-06 16:22:39 -05:00
|
|
|
context 'when feature flag workhorse_set_content_type is' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(workhorse_set_content_type: flag_value)
|
|
|
|
end
|
2018-08-30 08:34:41 -04:00
|
|
|
|
2018-12-06 16:22:39 -05:00
|
|
|
context 'enabled' do
|
|
|
|
let(:flag_value) { true }
|
|
|
|
|
|
|
|
it 'sends the avatar' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(response.header['Content-Disposition']).to eq('inline')
|
|
|
|
expect(response.header['Content-Type']).to eq 'image/png'
|
|
|
|
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
|
|
|
|
expect(response.header[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'disabled' do
|
|
|
|
let(:flag_value) { false }
|
|
|
|
|
|
|
|
it 'sends the avatar' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(response.header['Content-Type']).to eq('image/png')
|
|
|
|
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
|
|
|
|
expect(response.header[Gitlab::Workhorse::DETECT_HEADER]).to eq nil
|
|
|
|
end
|
|
|
|
end
|
2018-08-30 08:34:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the avatar is stored in lfs' do
|
|
|
|
it_behaves_like 'repository lfs file load' do
|
|
|
|
let(:filename) { 'lfs_object.iso' }
|
|
|
|
let(:filepath) { "files/lfs/#{filename}" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-21 00:00:39 -05:00
|
|
|
end
|
|
|
|
|
2018-08-30 08:34:41 -04:00
|
|
|
describe 'DELETE #destroy' do
|
|
|
|
it 'removes avatar from DB by calling destroy' do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: { namespace_id: project.namespace.id, project_id: project.id }
|
2018-08-30 08:34:41 -04:00
|
|
|
|
|
|
|
expect(project.avatar.present?).to be_falsey
|
|
|
|
expect(project).to be_valid
|
|
|
|
end
|
2015-05-06 17:33:39 -04:00
|
|
|
end
|
|
|
|
end
|