diff options
Diffstat (limited to 'spec/requests/api/group_avatar_spec.rb')
-rw-r--r-- | spec/requests/api/group_avatar_spec.rb | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/spec/requests/api/group_avatar_spec.rb b/spec/requests/api/group_avatar_spec.rb index be5cfbc234c..50379d29b09 100644 --- a/spec/requests/api/group_avatar_spec.rb +++ b/spec/requests/api/group_avatar_spec.rb @@ -4,17 +4,35 @@ require 'spec_helper' RSpec.describe API::GroupAvatar do def avatar_path(group) - "/groups/#{group.id}/avatar" + "/groups/#{ERB::Util.url_encode(group.full_path)}/avatar" end describe 'GET /groups/:id/avatar' do context 'when the group is public' do - it 'retrieves the avatar successfully' do - group = create(:group, :public, :with_avatar) + let(:group) { create(:group, :public, :with_avatar) } + it 'retrieves the avatar successfully' do get api(avatar_path(group)) expect(response).to have_gitlab_http_status(:ok) + expect(response.headers['Content-Disposition']) + .to eq(%(attachment; filename="dk.png"; filename*=UTF-8''dk.png)) + end + + context 'when the avatar is in the object storage' do + before do + stub_uploads_object_storage(AvatarUploader) + + group.avatar.migrate!(ObjectStorage::Store::REMOTE) + end + + it 'redirects to the file in the object storage' do + get api(avatar_path(group)) + + expect(response).to have_gitlab_http_status(:found) + expect(response.headers['Content-Disposition']) + .to eq(%(attachment; filename="dk.png"; filename*=UTF-8''dk.png)) + end end context 'when the group does not have avatar' do @@ -24,6 +42,18 @@ RSpec.describe API::GroupAvatar do get api(avatar_path(group)) expect(response).to have_gitlab_http_status(:not_found) + expect(response.body) + .to eq(%({"message":"404 Avatar Not Found"})) + end + end + + context 'when the group is a subgroup' do + it 'returns :ok' do + group = create(:group, :nested, :public, :with_avatar, name: 'g1.1') + + get api(avatar_path(group)) + + expect(response).to have_gitlab_http_status(:ok) end end end |