Skip to content

Commit a8d0293

Browse files
authored
Add "post" method case in smart merge (#94)
1 parent 4cf8eba commit a8d0293

File tree

8 files changed

+105
-2
lines changed

8 files changed

+105
-2
lines changed

spec/rails/app/controllers/users_controller.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
class UsersController < ApplicationController
2+
def create
3+
res = {
4+
name: params[:name],
5+
relations: {
6+
avatar: {
7+
url: params[:avatar_url],
8+
},
9+
pets: params[:pets] || [],
10+
},
11+
}
12+
render json: res, status: 201
13+
end
14+
215
def show
316
render json: find_user(params[:id])
417
end

spec/rails/config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
defaults format: 'json' do
55
resources :tables, only: [:index, :show, :create, :update, :destroy]
66
resources :images, only: [:index, :show]
7-
resources :users, only: [:show]
7+
resources :users, only: [:show, :create]
88

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

spec/rails/doc/openapi.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ paths:
128128
type: string
129129
database_id:
130130
type: integer
131+
required:
132+
- name
133+
- description
134+
- database_id
131135
example:
132136
name: k0kubun
133137
description: description
@@ -273,6 +277,11 @@ paths:
273277
format: binary
274278
caption:
275279
type: string
280+
required:
281+
- image
282+
- caption
283+
required:
284+
- nested
276285
example:
277286
nested:
278287
image: test.png
@@ -380,6 +389,8 @@ paths:
380389
properties:
381390
no_content:
382391
type: string
392+
required:
393+
- no_content
383394
example:
384395
no_content: 'true'
385396
"/images/{id}":

spec/rails/doc/smart/expected.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,37 @@ paths:
134134
storage_size: 12.3
135135
created_at: '2020-07-17T00:00:00+00:00'
136136
updated_at: '2020-07-17T00:00:00+00:00'
137+
"/users":
138+
post:
139+
summary: create
140+
tags:
141+
- User
142+
requestBody:
143+
content:
144+
application/json:
145+
schema:
146+
type: object
147+
properties:
148+
name:
149+
type: string
150+
avatar_url:
151+
type: string
152+
example:
153+
name: alice
154+
avatar_url: "https://example.com/avatar.png"
155+
responses:
156+
'201':
157+
description: returns an user
158+
content:
159+
application/json:
160+
schema:
161+
"$ref": "#/components/schemas/User"
162+
example:
163+
name: alice
164+
relations:
165+
avatar:
166+
url: "https://example.com/avatar.png"
167+
pets: []
137168
"/users/{id}":
138169
get:
139170
responses:

spec/rails/doc/smart/openapi.yaml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ paths:
102102
example:
103103
message: This field should be updated by rspec
104104
post:
105-
summary: create
105+
summary: This method should be removed!!
106106
tags:
107107
- Table
108108
requestBody:
@@ -119,6 +119,11 @@ paths:
119119
type: integer
120120
no_such_field_request:
121121
type: boolean
122+
required:
123+
- name
124+
- description
125+
- database_id
126+
- no_such_field_request
122127
example:
123128
name: k0kubun
124129
description: description
@@ -198,6 +203,32 @@ paths:
198203
storage_size: 12.3
199204
created_at: '2020-07-17T00:00:00+00:00'
200205
updated_at: '2020-07-17T00:00:00+00:00'
206+
"/users":
207+
post:
208+
summary: Create
209+
tags:
210+
- User
211+
requestBody:
212+
content:
213+
application/json:
214+
schema:
215+
type: object
216+
properties:
217+
name:
218+
type: string
219+
avatar:
220+
"$ref": "#/components/schemas/Avatar"
221+
pets:
222+
type: array
223+
items:
224+
"$ref": "#/components/schemas/Pet"
225+
responses:
226+
'201':
227+
description: returns a user
228+
content:
229+
application/json:
230+
schema:
231+
"$ref": "#/components/schemas/User"
201232
"/users/{id}":
202233
get:
203234
responses:

spec/requests/rails_smart_merge_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@
6060
end
6161

6262
RSpec.describe 'Users', type: :request do
63+
describe '#create' do
64+
it 'returns an user' do
65+
post '/users', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
66+
name: 'alice',
67+
avatar_url: 'https://example.com/avatar.png',
68+
}.to_json
69+
expect(response.status).to eq(201)
70+
end
71+
end
72+
6373
describe '#show' do
6474
it 'returns a user' do
6575
get '/users/1'

spec/roda/doc/openapi.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ paths:
1616
properties:
1717
id:
1818
type: integer
19+
required:
20+
- id
1921
example:
2022
id: 1
2123
responses:

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ def minitest(*args, openapi: false, output: :yaml)
4040
c.syntax = :expect
4141
end
4242
end
43+
44+
SuperDiff.configure do |config|
45+
config.diff_elision_enabled = true
46+
config.diff_elision_maximum = 3
47+
end

0 commit comments

Comments
 (0)