-
Notifications
You must be signed in to change notification settings - Fork 64
/
rails_smart_merge_spec.rb
126 lines (110 loc) · 3.51 KB
/
rails_smart_merge_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# frozen_string_literal: true
ENV['TZ'] ||= 'UTC'
ENV['RAILS_ENV'] ||= 'test'
ENV['OPENAPI_OUTPUT'] ||= 'json'
require File.expand_path('../rails/config/environment', __dir__)
require 'rspec/rails'
RSpec::OpenAPI.request_headers = %w[X-Authorization-Token]
RSpec::OpenAPI.response_headers = %w[X-Cursor]
RSpec::OpenAPI.path = File.expand_path("../rails/doc/smart/openapi.#{ENV.fetch('OPENAPI_OUTPUT', nil)}", __dir__)
RSpec::OpenAPI.comment = <<~COMMENT
This file is auto-generated by rspec-openapi https://github.com/k0kubun/rspec-openapi
When you write a spec in spec/requests, running the spec with `OPENAPI=1 rspec` will
update this file automatically. You can also manually edit this file.
COMMENT
RSpec::OpenAPI.servers = [{ url: 'http://localhost:3000' }]
RSpec::OpenAPI.security_schemes = {
'Scheme1' => {
description: 'Authentication scheme',
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
}
RSpec::OpenAPI.info = {
description: 'My beautiful API',
license: {
name: 'Apache 2.0',
url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
},
}
# Small subset of `rails_spec.rb` with slight changes
RSpec.describe 'Tables', type: :request do
describe '#index', openapi: { required_request_params: 'show_columns', operation_id: 'table-index' } do
context it 'returns a list of tables' do
it 'with flat query parameters' do
# These new params replace them in old spec
get '/tables', params: { page: '42', per: '10', show_columns: true },
headers: { authorization: 'k0kubun', 'X-Authorization-Token': 'token' }
response.set_header('X-Cursor', 100)
expect(response.status).to eq(200)
end
end
it 'does not return tables if unauthorized' do
get '/tables'
expect(response.status).to eq(401)
end
end
describe '#show' do
it 'returns a table with changes !!!' do
get '/tables/1', headers: { authorization: 'k0kubun' }
expect(response.status).to eq(200)
end
end
end
RSpec.describe 'Users', type: :request do
describe '#create' do
it 'accepts missing avatar_url' do
post '/users', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
name: 'alice',
}.to_json
expect(response.status).to eq(201)
end
it 'accepts nested object' do
post '/users', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
name: 'alice',
foo: {
bar: {
baz: 42,
},
},
}.to_json
expect(response.status).to eq(201)
end
it 'returns an user' do
post '/users', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
name: 'alice',
avatar_url: 'https://example.com/avatar.png',
}.to_json
expect(response.status).to eq(201)
end
end
describe '#show' do
it 'returns a user' do
get '/users/1'
expect(response.status).to eq(200)
end
it 'returns a user whose fields may be missing' do
get '/users/2'
expect(response.status).to eq(200)
end
end
describe '#active' do
it 'returns a boolean' do
get '/users/1/active'
expect(response.status).to eq(200)
end
end
end
RSpec.describe 'Pages', type: :request do
describe '#get' do
it 'return HTML' do
get '/pages'
expect(response.status).to eq(200)
end
it 'return no content' do
get '/pages?head=1'
expect(response.status).to eq(204)
end
end
end