gitlab-org--gitlab-foss/spec/controllers/projects/avatars_controller_spec.rb
Luke Duncalfe c7dcbc03bb CE backport for changes in EE MR 13389
This backports to ce a refactor of the shared example 'a controller that
can serve LFS files'.

The ee MR that contains the original refactor is
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/13389

The reason for the refactor was mostly the removal of the outer context
as it didn't need to be there, and prevented let(:lfs_oid) from being
overwritten.

The shared example was also renamed to be more descriptive.
2019-06-06 14:22:41 +12:00

58 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe Projects::AvatarsController do
let(:project) { create(:project, :repository) }
before do
controller.instance_variable_set(:@project, project)
end
describe 'GET #show' do
subject { get :show, params: { namespace_id: project.namespace, project_id: project } }
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' }
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[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
expect(response.header[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
end
end
context 'when the avatar is stored in lfs' do
it_behaves_like 'a controller that can serve LFS files' do
let(:filename) { 'lfs_object.iso' }
let(:filepath) { "files/lfs/#{filename}" }
end
end
end
end
describe 'DELETE #destroy' do
it 'removes avatar from DB by calling destroy' do
delete :destroy, params: { namespace_id: project.namespace.id, project_id: project.id }
expect(project.avatar.present?).to be_falsey
expect(project).to be_valid
end
end
end