fun_with_json_api 0.0.11.3 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/fun_with_json_api/attributes/decimal_attribute.rb +1 -1
- data/lib/fun_with_json_api/find_collection_from_document.rb +2 -2
- data/lib/fun_with_json_api/find_resource_from_document.rb +2 -2
- data/lib/fun_with_json_api/middleware/catch_json_api_parse_errors.rb +1 -1
- data/lib/fun_with_json_api/railtie.rb +4 -10
- data/lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb +2 -2
- data/lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb +2 -2
- data/lib/fun_with_json_api/schema_validators/check_relationship_names.rb +2 -2
- data/lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb +2 -2
- data/lib/fun_with_json_api/version.rb +1 -1
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/log/test.log +1639 -72761
- data/spec/fixtures/active_record.rb +1 -1
- data/spec/fun_with_json_api/controller_methods_spec.rb +3 -3
- data/spec/fun_with_json_api/deserializer_spec.rb +5 -5
- data/spec/fun_with_json_api/railtie_spec.rb +6 -7
- data/spec/requests/request_parsing_spec.rb +29 -14
- data/spec/spec_helper.rb +0 -1
- metadata +47 -60
@@ -37,7 +37,7 @@ describe FunWithJsonApi::ControllerMethods, type: :controller do
|
|
37
37
|
it 'returns a json api error status' do
|
38
38
|
get :index
|
39
39
|
expect(response.status).to eq 403
|
40
|
-
expect(response.content_type).to
|
40
|
+
expect(response.content_type).to include('application/vnd.api+json')
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'renders the exception payload as a json api errors response' do
|
@@ -77,7 +77,7 @@ describe FunWithJsonApi::ControllerMethods, type: :controller do
|
|
77
77
|
it 'returns a json api error status' do
|
78
78
|
get :index
|
79
79
|
expect(response.status).to eq 403
|
80
|
-
expect(response.content_type).to
|
80
|
+
expect(response.content_type).to include('application/vnd.api+json')
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'renders all exception payload items' do
|
@@ -108,7 +108,7 @@ describe FunWithJsonApi::ControllerMethods, type: :controller do
|
|
108
108
|
it 'returns a json api error status' do
|
109
109
|
get :index
|
110
110
|
expect(response.status).to eq 422
|
111
|
-
expect(response.content_type).to
|
111
|
+
expect(response.content_type).to include('application/vnd.api+json')
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'only renders the non-nil params' do
|
@@ -247,19 +247,19 @@ describe FunWithJsonApi::Deserializer do
|
|
247
247
|
context 'with a decimal format' do
|
248
248
|
it 'allows integers' do
|
249
249
|
deserializer = deserializer_with_attribute(:example, format: :decimal)
|
250
|
-
expect(deserializer.parse_example(12)).to eq BigDecimal
|
250
|
+
expect(deserializer.parse_example(12)).to eq BigDecimal('12')
|
251
251
|
end
|
252
252
|
it 'allows floats' do
|
253
253
|
deserializer = deserializer_with_attribute(:example, format: :decimal)
|
254
|
-
expect(deserializer.parse_example(12.34)).to eq BigDecimal
|
254
|
+
expect(deserializer.parse_example(12.34)).to eq BigDecimal('12.34')
|
255
255
|
end
|
256
256
|
it 'allows integer numbers as strings' do
|
257
257
|
deserializer = deserializer_with_attribute(:example, format: :decimal)
|
258
|
-
expect(deserializer.parse_example('12')).to eq BigDecimal
|
258
|
+
expect(deserializer.parse_example('12')).to eq BigDecimal('12')
|
259
259
|
end
|
260
260
|
it 'allows floating point numbers as strings' do
|
261
261
|
deserializer = deserializer_with_attribute(:example, format: :decimal)
|
262
|
-
expect(deserializer.parse_example('12.30')).to eq BigDecimal
|
262
|
+
expect(deserializer.parse_example('12.30')).to eq BigDecimal('12.30')
|
263
263
|
end
|
264
264
|
it 'allows a nil value' do
|
265
265
|
deserializer = deserializer_with_attribute(:example, format: :decimal)
|
@@ -339,7 +339,7 @@ describe FunWithJsonApi::Deserializer do
|
|
339
339
|
context 'with a integer format' do
|
340
340
|
it 'allows integer numbers as strings' do
|
341
341
|
deserializer = deserializer_with_attribute(:example, format: :integer)
|
342
|
-
expect(deserializer.parse_example('12')).to eq BigDecimal
|
342
|
+
expect(deserializer.parse_example('12')).to eq BigDecimal('12')
|
343
343
|
end
|
344
344
|
it 'allows a nil value' do
|
345
345
|
deserializer = deserializer_with_attribute(:example, format: :integer)
|
@@ -6,16 +6,15 @@ describe FunWithJsonApi::Railtie do
|
|
6
6
|
controller do
|
7
7
|
def index
|
8
8
|
# Concatinates /data/id and /data/type from a json_api request
|
9
|
-
render
|
9
|
+
render plain: "#{params[:data][:id]}:#{params['data']['type']}"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'converts the request body into param values' do
|
14
14
|
json_api_data = { data: { id: '42', type: 'foobar' } }
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
'Content-Type' => 'application/vnd.api+json'
|
16
|
+
request.headers['Content-Type'] = 'application/vnd.api+json'
|
17
|
+
get :index, params: json_api_data.as_json
|
19
18
|
expect(response.body).to eq '42:foobar'
|
20
19
|
end
|
21
20
|
end
|
@@ -34,7 +33,7 @@ describe FunWithJsonApi::Railtie do
|
|
34
33
|
expect(response.body).to eq 'passed'
|
35
34
|
end
|
36
35
|
it 'responds to a application/vnd.api+json accept header' do
|
37
|
-
request.
|
36
|
+
request.headers['HTTP_ACCEPT'] = 'application/vnd.api+json'
|
38
37
|
get :index
|
39
38
|
expect(response.body).to eq 'passed'
|
40
39
|
end
|
@@ -51,7 +50,7 @@ describe FunWithJsonApi::Railtie do
|
|
51
50
|
|
52
51
|
it 'renders out the hash as a json_api response' do
|
53
52
|
get :index
|
54
|
-
expect(response.content_type).to
|
53
|
+
expect(response.content_type).to include('application/vnd.api+json')
|
55
54
|
expect(JSON.parse(response.body)).to eq(
|
56
55
|
'data' => { 'id' => '42', 'type' => 'foobar' }
|
57
56
|
)
|
@@ -67,7 +66,7 @@ describe FunWithJsonApi::Railtie do
|
|
67
66
|
|
68
67
|
it 'renders the resource as a json api document' do
|
69
68
|
get :index
|
70
|
-
expect(response.content_type).to
|
69
|
+
expect(response.content_type).to include('application/vnd.api+json')
|
71
70
|
expect(JSON.parse(response.body)).to eq(
|
72
71
|
'data' => {
|
73
72
|
'id' => '42',
|
@@ -4,8 +4,13 @@ describe 'Request Parsing', type: :request do
|
|
4
4
|
it 'converts a json_api request body into param values' do
|
5
5
|
request_data = '{"data":{"id":"42","type":"foobar"}}'
|
6
6
|
|
7
|
-
post '/echo',
|
8
|
-
|
7
|
+
post '/echo',
|
8
|
+
params: request_data,
|
9
|
+
headers: {
|
10
|
+
'Accept': 'application/vnd.api+json',
|
11
|
+
'Content-Type': 'application/vnd.api+json'
|
12
|
+
}
|
13
|
+
|
9
14
|
expect(
|
10
15
|
JSON.parse(response.body, symbolize_names: true)
|
11
16
|
).to eq(data: { id: '42', type: 'foobar' })
|
@@ -24,9 +29,11 @@ describe 'Request Parsing', type: :request do
|
|
24
29
|
context 'when the request has a json api accept header' do
|
25
30
|
it 'renders a json api invalid document response' do
|
26
31
|
post '/echo',
|
27
|
-
invalid_request_data,
|
28
|
-
|
29
|
-
|
32
|
+
params: invalid_request_data,
|
33
|
+
headers: {
|
34
|
+
'Accept': 'application/vnd.api+json',
|
35
|
+
'Content-Type': 'application/vnd.api+json'
|
36
|
+
}
|
30
37
|
|
31
38
|
expect(response.status).to eq 400
|
32
39
|
expect(JSON.parse(response.body, symbolize_names: true)).to eq(
|
@@ -41,9 +48,11 @@ describe 'Request Parsing', type: :request do
|
|
41
48
|
context 'when the request has a json api accept header with utf-8 charset' do
|
42
49
|
it 'renders a json api invalid document response' do
|
43
50
|
post '/echo',
|
44
|
-
invalid_request_data,
|
45
|
-
|
46
|
-
|
51
|
+
params: invalid_request_data,
|
52
|
+
headers: {
|
53
|
+
'Accept': 'application/vnd.api+json; charset=utf-8',
|
54
|
+
'Content-Type': 'application/vnd.api+json; charset=utf-8'
|
55
|
+
}
|
47
56
|
|
48
57
|
expect(response.status).to eq 400
|
49
58
|
expect(JSON.parse(response.body, symbolize_names: true)).to eq(
|
@@ -59,7 +68,9 @@ describe 'Request Parsing', type: :request do
|
|
59
68
|
it 'renders a json api invalid document response' do
|
60
69
|
invalid_request_data = '{"data":{"id":"42","type":"foobar",}}' # extra comma
|
61
70
|
|
62
|
-
post '/echo', invalid_request_data,
|
71
|
+
post '/echo', params: invalid_request_data, headers: {
|
72
|
+
'Content-Type': 'application/vnd.api+json'
|
73
|
+
}
|
63
74
|
|
64
75
|
expect(response.status).to eq 400
|
65
76
|
end
|
@@ -76,9 +87,11 @@ describe 'Request Parsing', type: :request do
|
|
76
87
|
context 'when the request has a json api accept header' do
|
77
88
|
it 'renders a json api invalid document response' do
|
78
89
|
post '/echo',
|
79
|
-
invalid_request_data,
|
80
|
-
|
81
|
-
|
90
|
+
params: invalid_request_data,
|
91
|
+
headers: {
|
92
|
+
'Accept': 'application/vnd.api+json',
|
93
|
+
'Content-Type': 'application/vnd.api+json'
|
94
|
+
}
|
82
95
|
|
83
96
|
expect(response.status).to eq 400
|
84
97
|
end
|
@@ -87,8 +100,10 @@ describe 'Request Parsing', type: :request do
|
|
87
100
|
context 'when the request does not have a json api accept header' do
|
88
101
|
it 'raises a ActionDispatch::ParamsParser::ParseError' do
|
89
102
|
expect do
|
90
|
-
post '/echo', invalid_request_data,
|
91
|
-
|
103
|
+
post '/echo', params: invalid_request_data, headers: {
|
104
|
+
'Content-Type': 'application/vnd.api+json'
|
105
|
+
}
|
106
|
+
end.to raise_error(ActionDispatch::Http::Parameters::ParseError)
|
92
107
|
end
|
93
108
|
end
|
94
109
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_with_json_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Morrall
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: active_model_serializers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.10.0
|
33
|
+
version: 0.10.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.10.0
|
40
|
+
version: 0.10.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: factory_girl_rails
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rubocop
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +191,7 @@ files:
|
|
205
191
|
- lib/tasks/fun_with_json_api_tasks.rake
|
206
192
|
- spec/dummy/README.rdoc
|
207
193
|
- spec/dummy/Rakefile
|
194
|
+
- spec/dummy/app/assets/config/manifest.js
|
208
195
|
- spec/dummy/app/assets/javascripts/application.js
|
209
196
|
- spec/dummy/app/assets/stylesheets/application.css
|
210
197
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -261,7 +248,7 @@ homepage: https://github.com/bmorrall/fun_with_json_api
|
|
261
248
|
licenses:
|
262
249
|
- MIT
|
263
250
|
metadata: {}
|
264
|
-
post_install_message:
|
251
|
+
post_install_message:
|
265
252
|
rdoc_options: []
|
266
253
|
require_paths:
|
267
254
|
- lib
|
@@ -276,63 +263,63 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
263
|
- !ruby/object:Gem::Version
|
277
264
|
version: '0'
|
278
265
|
requirements: []
|
279
|
-
|
280
|
-
|
281
|
-
signing_key:
|
266
|
+
rubygems_version: 3.1.6
|
267
|
+
signing_key:
|
282
268
|
specification_version: 4
|
283
269
|
summary: Provides JSON API-compliant Controller integration
|
284
270
|
test_files:
|
271
|
+
- spec/spec_helper.rb
|
272
|
+
- spec/dummy/app/controllers/application_controller.rb
|
273
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
274
|
+
- spec/dummy/app/assets/config/manifest.js
|
285
275
|
- spec/dummy/app/assets/javascripts/application.js
|
286
276
|
- spec/dummy/app/assets/stylesheets/application.css
|
287
|
-
- spec/dummy/app/controllers/application_controller.rb
|
288
277
|
- spec/dummy/app/helpers/application_helper.rb
|
289
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
290
|
-
- spec/dummy/bin/bundle
|
291
|
-
- spec/dummy/bin/rails
|
292
278
|
- spec/dummy/bin/rake
|
293
279
|
- spec/dummy/bin/setup
|
294
|
-
- spec/dummy/
|
295
|
-
- spec/dummy/
|
296
|
-
- spec/dummy/config/
|
297
|
-
- spec/dummy/config/
|
298
|
-
- spec/dummy/config/
|
280
|
+
- spec/dummy/bin/bundle
|
281
|
+
- spec/dummy/bin/rails
|
282
|
+
- spec/dummy/config/secrets.yml
|
283
|
+
- spec/dummy/config/routes.rb
|
284
|
+
- spec/dummy/config/locales/en.yml
|
299
285
|
- spec/dummy/config/environments/production.rb
|
286
|
+
- spec/dummy/config/environments/development.rb
|
300
287
|
- spec/dummy/config/environments/test.rb
|
301
|
-
- spec/dummy/config/
|
288
|
+
- spec/dummy/config/environment.rb
|
289
|
+
- spec/dummy/config/application.rb
|
290
|
+
- spec/dummy/config/database.yml
|
291
|
+
- spec/dummy/config/boot.rb
|
302
292
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
303
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
304
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
305
|
-
- spec/dummy/config/initializers/inflections.rb
|
306
293
|
- spec/dummy/config/initializers/mime_types.rb
|
294
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
307
295
|
- spec/dummy/config/initializers/session_store.rb
|
308
296
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
309
|
-
- spec/dummy/config/
|
310
|
-
- spec/dummy/config/
|
311
|
-
- spec/dummy/config/
|
297
|
+
- spec/dummy/config/initializers/assets.rb
|
298
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
299
|
+
- spec/dummy/config/initializers/inflections.rb
|
312
300
|
- spec/dummy/config.ru
|
313
|
-
- spec/dummy/
|
314
|
-
- spec/dummy/public/
|
301
|
+
- spec/dummy/Rakefile
|
302
|
+
- spec/dummy/public/favicon.ico
|
315
303
|
- spec/dummy/public/422.html
|
316
304
|
- spec/dummy/public/500.html
|
317
|
-
- spec/dummy/public/
|
318
|
-
- spec/dummy/
|
305
|
+
- spec/dummy/public/404.html
|
306
|
+
- spec/dummy/log/test.log
|
319
307
|
- spec/dummy/README.rdoc
|
320
|
-
- spec/
|
321
|
-
- spec/fun_with_json_api/
|
308
|
+
- spec/requests/request_parsing_spec.rb
|
309
|
+
- spec/fun_with_json_api/deserializer_spec.rb
|
310
|
+
- spec/fun_with_json_api/find_resource_from_document_spec.rb
|
322
311
|
- spec/fun_with_json_api/configuration_spec.rb
|
323
|
-
- spec/fun_with_json_api/
|
312
|
+
- spec/fun_with_json_api/railtie_spec.rb
|
324
313
|
- spec/fun_with_json_api/deserializer_class_methods_spec.rb
|
325
|
-
- spec/fun_with_json_api/deserializer_spec.rb
|
326
|
-
- spec/fun_with_json_api/exception_spec.rb
|
327
314
|
- spec/fun_with_json_api/find_collection_from_document_spec.rb
|
328
|
-
- spec/fun_with_json_api/
|
315
|
+
- spec/fun_with_json_api/exception_spec.rb
|
329
316
|
- spec/fun_with_json_api/pre_deserializer_spec.rb
|
330
|
-
- spec/fun_with_json_api/railtie_spec.rb
|
331
317
|
- spec/fun_with_json_api/schema_validator_spec.rb
|
332
|
-
- spec/fun_with_json_api/schema_validators/check_attribute_names_spec.rb
|
333
318
|
- spec/fun_with_json_api/schema_validators/check_document_id_matches_resource_spec.rb
|
334
|
-
- spec/fun_with_json_api/schema_validators/check_document_type_matches_resource_spec.rb
|
335
319
|
- spec/fun_with_json_api/schema_validators/check_relationships_spec.rb
|
320
|
+
- spec/fun_with_json_api/schema_validators/check_attribute_names_spec.rb
|
321
|
+
- spec/fun_with_json_api/schema_validators/check_document_type_matches_resource_spec.rb
|
322
|
+
- spec/fun_with_json_api/collection_manager_spec.rb
|
323
|
+
- spec/fun_with_json_api/controller_methods_spec.rb
|
324
|
+
- spec/fixtures/active_record.rb
|
336
325
|
- spec/fun_with_json_api_spec.rb
|
337
|
-
- spec/requests/request_parsing_spec.rb
|
338
|
-
- spec/spec_helper.rb
|