debian-mirror-gitlab/spec/controllers/projects/avatars_controller_spec.rb

78 lines
2.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::AvatarsController do
2021-01-29 00:20:46 +05:30
describe 'GET #show' do
let_it_be(:project) { create(:project, :public, :repository) }
2015-09-11 14:41:01 +05:30
2021-01-29 00:20:46 +05:30
before do
controller.instance_variable_set(:@project, project)
end
2015-09-11 14:41:01 +05:30
2021-01-29 00:20:46 +05:30
subject { get :show, params: { namespace_id: project.namespace, project_id: project.path } }
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
context 'when repository has no avatar' do
it 'shows 404' do
subject
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-11-20 20:47:30 +05:30
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' }
2019-01-03 12:48:30 +05:30
it 'sends the avatar' do
subject
2018-11-20 20:47:30 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-02-15 15:39:39 +05:30
expect(response.header['Content-Disposition']).to eq('inline')
2019-01-03 12:48:30 +05:30
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
2020-04-22 19:07:51 +05:30
expect(response.header[Gitlab::Workhorse::DETECT_HEADER]).to eq 'true'
2018-11-20 20:47:30 +05:30
end
2020-04-22 19:07:51 +05:30
2021-01-29 00:20:46 +05:30
it 'sets appropriate caching headers' do
sign_in(project.owner)
subject
expect(response.cache_control[:public]).to eq(true)
expect(response.cache_control[:max_age]).to eq(60)
expect(response.cache_control[:no_store]).to be_nil
end
2020-04-22 19:07:51 +05:30
it_behaves_like 'project cache control headers'
2018-11-20 20:47:30 +05:30
end
context 'when the avatar is stored in lfs' do
2020-04-22 19:07:51 +05:30
let(:filename) { 'lfs_object.iso' }
let(:filepath) { "files/lfs/#{filename}" }
it_behaves_like 'a controller that can serve LFS files'
it_behaves_like 'project cache control headers'
2018-11-20 20:47:30 +05:30
end
end
2018-03-17 18:26:18 +05:30
end
2018-11-20 20:47:30 +05:30
describe 'DELETE #destroy' do
2021-01-29 00:20:46 +05:30
let(:project) { create(:project, :repository, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
before do
sign_in(project.owner)
end
2018-11-20 20:47:30 +05:30
it 'removes avatar from DB by calling destroy' do
2021-01-29 00:20:46 +05:30
delete :destroy, params: { namespace_id: project.namespace.path, project_id: project.path }
2018-11-20 20:47:30 +05:30
2021-01-29 00:20:46 +05:30
expect(response).to redirect_to(edit_project_path(project, anchor: 'js-general-project-settings'))
2018-11-20 20:47:30 +05:30
expect(project.avatar.present?).to be_falsey
expect(project).to be_valid
end
2015-09-11 14:41:01 +05:30
end
end