From 81aecf59315452af11eda95124f35a328be62166 Mon Sep 17 00:00:00 2001 From: Mattia Roccoberton Date: Thu, 12 Oct 2023 17:00:54 +0200 Subject: [PATCH] Issue merge params --- .../app/controllers/tables_controller.rb | 6 ++++- spec/rails/doc/openapi.json | 26 ++++++++++++++++--- spec/rails/doc/openapi.yaml | 16 ++++++++++-- spec/requests/rails_spec.rb | 17 ++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/spec/rails/app/controllers/tables_controller.rb b/spec/rails/app/controllers/tables_controller.rb index 46dfc16d..a9d60466 100644 --- a/spec/rails/app/controllers/tables_controller.rb +++ b/spec/rails/app/controllers/tables_controller.rb @@ -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 diff --git a/spec/rails/doc/openapi.json b/spec/rails/doc/openapi.json index 07f98407..7913e420 100644 --- a/spec/rails/doc/openapi.json +++ b/spec/rails/doc/openapi.json @@ -218,13 +218,12 @@ } }, "required": [ - "name", "description", "database_id" ] }, "example": { - "name": "k0kubun", + "name": "some_invalid_name", "description": "description", "database_id": 2 } @@ -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" + } + } + } } } } @@ -784,7 +804,7 @@ "tags": { "type": "array", "items": { - } +} } }, "required": [ diff --git a/spec/rails/doc/openapi.yaml b/spec/rails/doc/openapi.yaml index 3ea218c6..25b2b3e6 100644 --- a/spec/rails/doc/openapi.yaml +++ b/spec/rails/doc/openapi.yaml @@ -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: @@ -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 diff --git a/spec/requests/rails_spec.rb b/spec/requests/rails_spec.rb index c6b61558..75bf56f3 100644 --- a/spec/requests/rails_spec.rb +++ b/spec/requests/rails_spec.rb @@ -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