Skip to content

Commit a8a181e

Browse files
author
Stanislav Colotinschi
committed
Skip avatar URL from custom image renderer if email is empty
This might happen when the Assembla commit was made in a non-standard way
1 parent 285f9d2 commit a8a181e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/travis/api/v3/renderer/custom_image.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ class Renderer::CustomImage < ModelRenderer
66

77
def created_by
88
return nil unless user = model.created_by
9+
910
{
1011
'@type' => 'user',
1112
'@href' => "/v3/user/#{user.id}",
1213
'@representation' => 'minimal'.freeze,
1314
'id' => user.id,
1415
'login' => user.login,
1516
'name' => user.name,
16-
'avatar_url' => user.avatar_url
17-
}
17+
}.tap do |data|
18+
data['avatar_url'] = user.avatar_url if user.email.present?
19+
end
1820
end
1921
end
2022
end

spec/v3/services/custom_images/for_owner_spec.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,28 @@
1717
let!(:custom_image_log) { FactoryBot.create(:custom_image_log, custom_image: custom_image, sender_id: user.id) }
1818

1919
context 'when user has custom images' do
20-
it 'returns custom images' do
21-
get("/v3/owner/#{user.login}/custom_images", {}, json_headers.merge('HTTP_AUTHORIZATION' => "token #{user_token}"))
20+
subject { get("/v3/owner/#{user.login}/custom_images", {}, json_headers.merge('HTTP_AUTHORIZATION' => "token #{user_token}")) }
2221

22+
it 'returns custom images' do
23+
subject
2324
expect(last_response).to be_ok
24-
expect(JSON.parse(last_response.body)['custom_images'].first).to include(
25+
custom_image_response = JSON.parse(last_response.body)['custom_images'].first
26+
expect(custom_image_response).to include(
2527
'id' => custom_image.id,
2628
'name' => custom_image.name,
2729
'size_bytes' => custom_image.size_bytes
2830
)
31+
expect(custom_image_response['created_by']['avatar_url']).to be_present
32+
end
33+
34+
context 'when user email is blank' do
35+
before { user.update(email: nil) }
36+
37+
it 'skips avatar_url' do
38+
subject
39+
expect(last_response).to be_ok
40+
expect(JSON.parse(last_response.body)['custom_images'].first['created_by']).not_to have_key('avatar_url')
41+
end
2942
end
3043
end
3144

0 commit comments

Comments
 (0)