Skip to content

Commit

Permalink
Issue merge params
Browse files Browse the repository at this point in the history
  • Loading branch information
blocknotes committed Oct 12, 2023
1 parent 861a8c6 commit 81aecf5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
6 changes: 5 additions & 1 deletion spec/rails/app/controllers/tables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def show
end

def create
render json: find_table, status: 201
if params[:name].blank? || params[:name] == 'some_invalid_name'
render json: { error: 'invalid name parameter' }, status: 422
else
render json: find_table, status: 201
end
end

def update
Expand Down
26 changes: 23 additions & 3 deletions spec/rails/doc/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,12 @@
}
},
"required": [
"name",
"description",
"database_id"
]
},
"example": {
"name": "k0kubun",
"name": "some_invalid_name",
"description": "description",
"database_id": 2
}
Expand Down Expand Up @@ -303,6 +302,27 @@
}
}
}
},
"422": {
"description": "fails to create a table (2)",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
},
"required": [
"error"
]
},
"example": {
"error": "invalid name parameter"
}
}
}
}
}
}
Expand Down Expand Up @@ -784,7 +804,7 @@
"tags": {
"type": "array",
"items": {
}
}
}
},
"required": [
Expand Down
16 changes: 14 additions & 2 deletions spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ paths:
database_id:
type: integer
required:
- name
- description
- database_id
example:
name: k0kubun
name: some_invalid_name
description: description
database_id: 2
responses:
Expand Down Expand Up @@ -211,6 +210,19 @@ paths:
storage_size: 12.3
created_at: '2020-07-17T00:00:00+00:00'
updated_at: '2020-07-17T00:00:00+00:00'
'422':
description: fails to create a table (2)
content:
application/json:
schema:
type: object
properties:
error:
type: string
required:
- error
example:
error: invalid name parameter
"/tables/{id}":
get:
summary: show
Expand Down
17 changes: 17 additions & 0 deletions spec/requests/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@
}.to_json
expect(response.status).to eq(201)
end

it 'fails to create a table' do
post '/tables', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
description: 'description',
database_id: 2,
}.to_json
expect(response.status).to eq(422)
end

it 'fails to create a table (2)' do
post '/tables', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
name: 'some_invalid_name',
description: 'description',
database_id: 2,
}.to_json
expect(response.status).to eq(422)
end
end

describe '#update' do
Expand Down

0 comments on commit 81aecf5

Please sign in to comment.