Skip to content

Commit 16525a2

Browse files
committed
Added test case for empty array
1 parent b201fe0 commit 16525a2

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

spec/rails/app/controllers/images_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@ def show
44
QBoAAAAASUVORK5CYII='.unpack('m').first
55
send_data png, type: 'image/png', disposition: 'inline'
66
end
7+
8+
def index
9+
list = [
10+
{
11+
'name': 'file.png',
12+
'tags': [], # Keep this empty to check empty array is accepted
13+
}
14+
]
15+
render json: list
16+
end
717
end

spec/rails/config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
defaults format: 'json' do
55
resources :tables, only: [:index, :show, :create, :update, :destroy]
6-
resources :images, only: [:show]
6+
resources :images, only: [:index, :show]
77

88
get '/test_block' => ->(_env) { [200, { 'Content-Type' => 'text/plain' }, ['A TEST']] }
99
end

spec/rails/doc/openapi.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,47 @@
645645
}
646646
}
647647
}
648+
},
649+
"/images": {
650+
"get": {
651+
"summary": "index",
652+
"tags": [
653+
"Image"
654+
],
655+
"responses": {
656+
"200": {
657+
"description": "can return an object with an attribute of empty array",
658+
"content": {
659+
"application/json": {
660+
"schema": {
661+
"type": "array",
662+
"items": {
663+
"type": "object",
664+
"properties": {
665+
"name": {
666+
"type": "string"
667+
},
668+
"tags": {
669+
"type": "array",
670+
"items": {
671+
}
672+
}
673+
}
674+
}
675+
},
676+
"example": [
677+
{
678+
"name": "file.png",
679+
"tags": [
680+
681+
]
682+
}
683+
]
684+
}
685+
}
686+
}
687+
}
688+
}
648689
}
649690
}
650691
}

spec/rails/doc/openapi.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,26 @@ paths:
422422
schema:
423423
type: string
424424
example: AN ENGINE TEST
425+
"/images":
426+
get:
427+
summary: index
428+
tags:
429+
- Image
430+
responses:
431+
'200':
432+
description: can return an object with an attribute of empty array
433+
content:
434+
application/json:
435+
schema:
436+
type: array
437+
items:
438+
type: object
439+
properties:
440+
name:
441+
type: string
442+
tags:
443+
type: array
444+
items: {}
445+
example:
446+
- name: file.png
447+
tags: []

spec/requests/rails_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@
120120
expect(response.status).to eq(200)
121121
end
122122
end
123+
124+
describe '#index' do
125+
it 'can return an object with an attribute of empty array' do
126+
get '/images'
127+
expect(response.status).to eq(200)
128+
end
129+
end
123130
end
124131

125132
RSpec.describe 'Extra routes', type: :request do

0 commit comments

Comments
 (0)