File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
lib/travis/api/v3/renderer
spec/v3/services/custom_images Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -6,15 +6,17 @@ class Renderer::CustomImage < ModelRenderer
6
6
7
7
def created_by
8
8
return nil unless user = model . created_by
9
+
9
10
{
10
11
'@type' => 'user' ,
11
12
'@href' => "/v3/user/#{ user . id } " ,
12
13
'@representation' => 'minimal' . freeze ,
13
14
'id' => user . id ,
14
15
'login' => user . login ,
15
16
'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
18
20
end
19
21
end
20
22
end
Original file line number Diff line number Diff line change 17
17
let! ( :custom_image_log ) { FactoryBot . create ( :custom_image_log , custom_image : custom_image , sender_id : user . id ) }
18
18
19
19
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 } " ) ) }
22
21
22
+ it 'returns custom images' do
23
+ subject
23
24
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 (
25
27
'id' => custom_image . id ,
26
28
'name' => custom_image . name ,
27
29
'size_bytes' => custom_image . size_bytes
28
30
)
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
29
42
end
30
43
end
31
44
You can’t perform that action at this time.
0 commit comments