jsonapi-resources 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/jsonapi/acts_as_resource_controller.rb +10 -1
- data/lib/jsonapi/configuration.rb +5 -0
- data/lib/jsonapi/error.rb +13 -0
- data/lib/jsonapi/operation.rb +1 -1
- data/lib/jsonapi/request.rb +27 -5
- data/lib/jsonapi/resources/version.rb +1 -1
- data/test/controllers/controller_test.rb +216 -15
- data/test/integration/requests/request_test.rb +65 -0
- data/test/unit/serializer/serializer_test.rb +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9dfa52ac05f532050b9740a884e624b27f40dcc
|
4
|
+
data.tar.gz: 515bc38bde0559a474dcfbc7ec9891a9cc79d1eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c47e723f53c1b0d30ef1ab99f19841b5c1bb6ed808a441739d3d065e3e7ef57513881f7644a579766eb652df57d280a98eaa6c44f3d57c53f7158a5a045e50e5
|
7
|
+
data.tar.gz: 2644748a35a9e4de7554be0627068a044611600f43195ddf41fd28be1f33cd5df4d047605d74f950efccd9df3b48a968f2e42dd3c6846195fb5916cf126a182a
|
data/README.md
CHANGED
@@ -1282,6 +1282,12 @@ JSONAPI.configure do |config|
|
|
1282
1282
|
config.allow_sort = true
|
1283
1283
|
config.allow_filter = true
|
1284
1284
|
|
1285
|
+
# How to handle unsupported attributes and relationships which are provided in the request
|
1286
|
+
# true => raises an error
|
1287
|
+
# false => allows the request to continue. A warning is included in the response meta data indicating
|
1288
|
+
# the fields which were ignored. This is useful for client libraries which send extra parameters.
|
1289
|
+
config.raise_if_parameters_not_allowed = true
|
1290
|
+
|
1285
1291
|
# :none, :offset, :paged, or a custom paginator name
|
1286
1292
|
config.default_paginator = :none
|
1287
1293
|
|
@@ -87,6 +87,7 @@ module JSONAPI
|
|
87
87
|
|
88
88
|
def setup_request
|
89
89
|
@request = JSONAPI::Request.new(params, context: context, key_formatter: key_formatter)
|
90
|
+
|
90
91
|
render_errors(@request.errors) unless @request.errors.empty?
|
91
92
|
rescue => e
|
92
93
|
handle_exceptions(e)
|
@@ -121,6 +122,14 @@ module JSONAPI
|
|
121
122
|
{}
|
122
123
|
end
|
123
124
|
|
125
|
+
def base_meta
|
126
|
+
if @request.nil? || @request.warnings.empty?
|
127
|
+
base_response_meta
|
128
|
+
else
|
129
|
+
base_response_meta.merge(warnings: @request.warnings)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
124
133
|
def base_response_links
|
125
134
|
{}
|
126
135
|
end
|
@@ -147,7 +156,7 @@ module JSONAPI
|
|
147
156
|
base_url: base_url,
|
148
157
|
key_formatter: key_formatter,
|
149
158
|
route_formatter: route_formatter,
|
150
|
-
base_meta:
|
159
|
+
base_meta: base_meta,
|
151
160
|
base_links: base_response_links,
|
152
161
|
resource_serializer_klass: resource_serializer_klass,
|
153
162
|
request: @request
|
@@ -8,6 +8,7 @@ module JSONAPI
|
|
8
8
|
:key_formatter,
|
9
9
|
:route_format,
|
10
10
|
:route_formatter,
|
11
|
+
:raise_if_parameters_not_allowed,
|
11
12
|
:operations_processor,
|
12
13
|
:allow_include,
|
13
14
|
:allow_sort,
|
@@ -38,6 +39,8 @@ module JSONAPI
|
|
38
39
|
self.allow_sort = true
|
39
40
|
self.allow_filter = true
|
40
41
|
|
42
|
+
self.raise_if_parameters_not_allowed = true
|
43
|
+
|
41
44
|
# :none, :offset, :paged, or a custom paginator name
|
42
45
|
self.default_paginator = :none
|
43
46
|
|
@@ -105,6 +108,8 @@ module JSONAPI
|
|
105
108
|
attr_writer :always_include_to_one_linkage_data
|
106
109
|
|
107
110
|
attr_writer :always_include_to_many_linkage_data
|
111
|
+
|
112
|
+
attr_writer :raise_if_parameters_not_allowed
|
108
113
|
end
|
109
114
|
|
110
115
|
class << self
|
data/lib/jsonapi/error.rb
CHANGED
@@ -17,4 +17,17 @@ module JSONAPI
|
|
17
17
|
@status = options[:status]
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
class Warning
|
22
|
+
attr_accessor :title, :detail, :code
|
23
|
+
def initialize(options = {})
|
24
|
+
@title = options[:title]
|
25
|
+
@detail = options[:detail]
|
26
|
+
@code = if JSONAPI.configuration.use_text_errors
|
27
|
+
TEXT_ERRORS[options[:code]]
|
28
|
+
else
|
29
|
+
options[:code]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
20
33
|
end
|
data/lib/jsonapi/operation.rb
CHANGED
@@ -175,7 +175,7 @@ module JSONAPI
|
|
175
175
|
def options
|
176
176
|
opts = {}
|
177
177
|
opts.merge!(pagination_params: pagination_params) if JSONAPI.configuration.top_level_links_include_pagination
|
178
|
-
opts.merge!(record_count:
|
178
|
+
opts.merge!(record_count: record_count) if JSONAPI.configuration.top_level_meta_include_record_count
|
179
179
|
opts
|
180
180
|
end
|
181
181
|
|
data/lib/jsonapi/request.rb
CHANGED
@@ -5,13 +5,14 @@ module JSONAPI
|
|
5
5
|
class Request
|
6
6
|
attr_accessor :fields, :include, :filters, :sort_criteria, :errors, :operations,
|
7
7
|
:resource_klass, :context, :paginator, :source_klass, :source_id,
|
8
|
-
:include_directives, :params
|
8
|
+
:include_directives, :params, :warnings
|
9
9
|
|
10
10
|
def initialize(params = nil, options = {})
|
11
11
|
@params = params
|
12
12
|
@context = options[:context]
|
13
13
|
@key_formatter = options.fetch(:key_formatter, JSONAPI.configuration.key_formatter)
|
14
14
|
@errors = []
|
15
|
+
@warnings = []
|
15
16
|
@operations = []
|
16
17
|
@fields = {}
|
17
18
|
@filters = {}
|
@@ -487,11 +488,21 @@ module JSONAPI
|
|
487
488
|
case key.to_s
|
488
489
|
when 'relationships'
|
489
490
|
value.each_key do |links_key|
|
490
|
-
|
491
|
+
unless formatted_allowed_fields.include?(links_key.to_sym)
|
492
|
+
params_not_allowed.push(links_key)
|
493
|
+
unless JSONAPI.configuration.raise_if_parameters_not_allowed
|
494
|
+
value.delete links_key
|
495
|
+
end
|
496
|
+
end
|
491
497
|
end
|
492
498
|
when 'attributes'
|
493
|
-
value.each do |attr_key,
|
494
|
-
|
499
|
+
value.each do |attr_key, attr_value|
|
500
|
+
unless formatted_allowed_fields.include?(attr_key.to_sym)
|
501
|
+
params_not_allowed.push(attr_key)
|
502
|
+
unless JSONAPI.configuration.raise_if_parameters_not_allowed
|
503
|
+
value.delete attr_key
|
504
|
+
end
|
505
|
+
end
|
495
506
|
end
|
496
507
|
when 'type', 'id'
|
497
508
|
else
|
@@ -499,7 +510,18 @@ module JSONAPI
|
|
499
510
|
end
|
500
511
|
end
|
501
512
|
|
502
|
-
|
513
|
+
if params_not_allowed.length > 0
|
514
|
+
if JSONAPI.configuration.raise_if_parameters_not_allowed
|
515
|
+
fail JSONAPI::Exceptions::ParametersNotAllowed.new(params_not_allowed)
|
516
|
+
else
|
517
|
+
params_not_allowed_warnings = params_not_allowed.map do |key|
|
518
|
+
JSONAPI::Warning.new(code: JSONAPI::PARAM_NOT_ALLOWED,
|
519
|
+
title: 'Param not allowed',
|
520
|
+
detail: "#{key} is not allowed.")
|
521
|
+
end
|
522
|
+
self.warnings.concat(params_not_allowed_warnings)
|
523
|
+
end
|
524
|
+
end
|
503
525
|
end
|
504
526
|
|
505
527
|
# TODO: Please remove after `updateable_fields` is removed
|
@@ -5,6 +5,10 @@ def set_content_type_header!
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class PostsControllerTest < ActionController::TestCase
|
8
|
+
def setup
|
9
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = true
|
10
|
+
end
|
11
|
+
|
8
12
|
def test_index
|
9
13
|
get :index
|
10
14
|
assert_response :success
|
@@ -401,6 +405,40 @@ class PostsControllerTest < ActionController::TestCase
|
|
401
405
|
assert_match /asdfg is not allowed/, response.body
|
402
406
|
end
|
403
407
|
|
408
|
+
def test_create_extra_param_allow_extra_params
|
409
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = false
|
410
|
+
|
411
|
+
set_content_type_header!
|
412
|
+
post :create,
|
413
|
+
{
|
414
|
+
data: {
|
415
|
+
type: 'posts',
|
416
|
+
attributes: {
|
417
|
+
asdfg: 'aaaa',
|
418
|
+
title: 'JR is Great',
|
419
|
+
body: 'JSONAPIResources is the greatest thing since unsliced bread.'
|
420
|
+
},
|
421
|
+
relationships: {
|
422
|
+
author: {data: {type: 'people', id: '3'}}
|
423
|
+
}
|
424
|
+
},
|
425
|
+
include: 'author'
|
426
|
+
}
|
427
|
+
|
428
|
+
assert_response :created
|
429
|
+
assert json_response['data'].is_a?(Hash)
|
430
|
+
assert_equal '3', json_response['data']['relationships']['author']['data']['id']
|
431
|
+
assert_equal 'JR is Great', json_response['data']['attributes']['title']
|
432
|
+
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['attributes']['body']
|
433
|
+
|
434
|
+
assert_equal 1, json_response['meta']["warnings"].count
|
435
|
+
assert_equal "Param not allowed", json_response['meta']["warnings"][0]["title"]
|
436
|
+
assert_equal "asdfg is not allowed.", json_response['meta']["warnings"][0]["detail"]
|
437
|
+
assert_equal 105, json_response['meta']["warnings"][0]["code"]
|
438
|
+
ensure
|
439
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = true
|
440
|
+
end
|
441
|
+
|
404
442
|
def test_create_with_invalid_data
|
405
443
|
set_content_type_header!
|
406
444
|
post :create,
|
@@ -575,6 +613,42 @@ class PostsControllerTest < ActionController::TestCase
|
|
575
613
|
assert_match /subject/, json_response['errors'][0]['detail']
|
576
614
|
end
|
577
615
|
|
616
|
+
def test_create_simple_unpermitted_attributes_allow_extra_params
|
617
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = false
|
618
|
+
|
619
|
+
set_content_type_header!
|
620
|
+
post :create,
|
621
|
+
{
|
622
|
+
data: {
|
623
|
+
type: 'posts',
|
624
|
+
attributes: {
|
625
|
+
title: 'JR is Great',
|
626
|
+
subject: 'JR is SUPER Great',
|
627
|
+
body: 'JSONAPIResources is the greatest thing since unsliced bread.'
|
628
|
+
},
|
629
|
+
relationships: {
|
630
|
+
author: {data: {type: 'people', id: '3'}}
|
631
|
+
}
|
632
|
+
},
|
633
|
+
include: 'author'
|
634
|
+
}
|
635
|
+
|
636
|
+
assert_response :created
|
637
|
+
assert json_response['data'].is_a?(Hash)
|
638
|
+
assert_equal '3', json_response['data']['relationships']['author']['data']['id']
|
639
|
+
assert_equal 'JR is Great', json_response['data']['attributes']['title']
|
640
|
+
assert_equal 'JR is Great', json_response['data']['attributes']['subject']
|
641
|
+
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['attributes']['body']
|
642
|
+
|
643
|
+
|
644
|
+
assert_equal 1, json_response['meta']["warnings"].count
|
645
|
+
assert_equal "Param not allowed", json_response['meta']["warnings"][0]["title"]
|
646
|
+
assert_equal "subject is not allowed.", json_response['meta']["warnings"][0]["detail"]
|
647
|
+
assert_equal 105, json_response['meta']["warnings"][0]["code"]
|
648
|
+
ensure
|
649
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = true
|
650
|
+
end
|
651
|
+
|
578
652
|
def test_create_with_links_to_many_type_ids
|
579
653
|
set_content_type_header!
|
580
654
|
post :create,
|
@@ -704,6 +778,48 @@ class PostsControllerTest < ActionController::TestCase
|
|
704
778
|
assert_equal title, post_object.title
|
705
779
|
end
|
706
780
|
|
781
|
+
def test_update_with_links_allow_extra_params
|
782
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = false
|
783
|
+
|
784
|
+
set_content_type_header!
|
785
|
+
javascript = Section.find_by(name: 'javascript')
|
786
|
+
|
787
|
+
put :update,
|
788
|
+
{
|
789
|
+
id: 3,
|
790
|
+
data: {
|
791
|
+
id: '3',
|
792
|
+
type: 'posts',
|
793
|
+
attributes: {
|
794
|
+
title: 'A great new Post',
|
795
|
+
subject: 'A great new Post',
|
796
|
+
},
|
797
|
+
relationships: {
|
798
|
+
section: {data: {type: 'sections', id: "#{javascript.id}"}},
|
799
|
+
tags: {data: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
|
800
|
+
}
|
801
|
+
},
|
802
|
+
include: 'tags,author,section'
|
803
|
+
}
|
804
|
+
|
805
|
+
assert_response :success
|
806
|
+
assert json_response['data'].is_a?(Hash)
|
807
|
+
assert_equal '3', json_response['data']['relationships']['author']['data']['id']
|
808
|
+
assert_equal javascript.id.to_s, json_response['data']['relationships']['section']['data']['id']
|
809
|
+
assert_equal 'A great new Post', json_response['data']['attributes']['title']
|
810
|
+
assert_equal 'AAAA', json_response['data']['attributes']['body']
|
811
|
+
assert matches_array?([{'type' => 'tags', 'id' => '3'}, {'type' => 'tags', 'id' => '4'}],
|
812
|
+
json_response['data']['relationships']['tags']['data'])
|
813
|
+
|
814
|
+
|
815
|
+
assert_equal 1, json_response['meta']["warnings"].count
|
816
|
+
assert_equal "Param not allowed", json_response['meta']["warnings"][0]["title"]
|
817
|
+
assert_equal "subject is not allowed.", json_response['meta']["warnings"][0]["detail"]
|
818
|
+
assert_equal 105, json_response['meta']["warnings"][0]["code"]
|
819
|
+
ensure
|
820
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = true
|
821
|
+
end
|
822
|
+
|
707
823
|
def test_update_remove_links
|
708
824
|
set_content_type_header!
|
709
825
|
put :update,
|
@@ -1150,6 +1266,38 @@ class PostsControllerTest < ActionController::TestCase
|
|
1150
1266
|
assert_match /asdfg is not allowed/, response.body
|
1151
1267
|
end
|
1152
1268
|
|
1269
|
+
def test_update_extra_param_in_links_allow_extra_params
|
1270
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = false
|
1271
|
+
JSONAPI.configuration.use_text_errors = true
|
1272
|
+
|
1273
|
+
set_content_type_header!
|
1274
|
+
javascript = Section.find_by(name: 'javascript')
|
1275
|
+
|
1276
|
+
put :update,
|
1277
|
+
{
|
1278
|
+
id: 3,
|
1279
|
+
data: {
|
1280
|
+
type: 'posts',
|
1281
|
+
id: '3',
|
1282
|
+
attributes: {
|
1283
|
+
title: 'A great new Post'
|
1284
|
+
},
|
1285
|
+
relationships: {
|
1286
|
+
asdfg: 'aaaa'
|
1287
|
+
}
|
1288
|
+
}
|
1289
|
+
}
|
1290
|
+
|
1291
|
+
assert_response :success
|
1292
|
+
assert_equal "A great new Post", json_response["data"]["attributes"]["title"]
|
1293
|
+
assert_equal "Param not allowed", json_response["meta"]["warnings"][0]["title"]
|
1294
|
+
assert_equal "asdfg is not allowed.", json_response["meta"]["warnings"][0]["detail"]
|
1295
|
+
assert_equal "PARAM_NOT_ALLOWED", json_response["meta"]["warnings"][0]["code"]
|
1296
|
+
ensure
|
1297
|
+
JSONAPI.configuration.raise_if_parameters_not_allowed = true
|
1298
|
+
JSONAPI.configuration.use_text_errors = false
|
1299
|
+
end
|
1300
|
+
|
1153
1301
|
def test_update_missing_param
|
1154
1302
|
set_content_type_header!
|
1155
1303
|
javascript = Section.find_by(name: 'javascript')
|
@@ -1550,6 +1698,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1550
1698
|
get :index, {sort: 'not_in_record'}
|
1551
1699
|
assert_response 400
|
1552
1700
|
assert_equal 'INVALID_SORT_CRITERIA', json_response['errors'][0]['code']
|
1701
|
+
ensure
|
1553
1702
|
JSONAPI.configuration.use_text_errors = false
|
1554
1703
|
end
|
1555
1704
|
|
@@ -1605,6 +1754,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1605
1754
|
|
1606
1755
|
def test_create_expense_entries_underscored
|
1607
1756
|
set_content_type_header!
|
1757
|
+
original_config = JSONAPI.configuration.dup
|
1608
1758
|
JSONAPI.configuration.json_key_format = :underscored_key
|
1609
1759
|
|
1610
1760
|
post :create,
|
@@ -1632,10 +1782,13 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1632
1782
|
|
1633
1783
|
delete :destroy, {id: json_response['data']['id']}
|
1634
1784
|
assert_response :no_content
|
1785
|
+
ensure
|
1786
|
+
JSONAPI.configuration = original_config
|
1635
1787
|
end
|
1636
1788
|
|
1637
1789
|
def test_create_expense_entries_camelized_key
|
1638
1790
|
set_content_type_header!
|
1791
|
+
original_config = JSONAPI.configuration.dup
|
1639
1792
|
JSONAPI.configuration.json_key_format = :camelized_key
|
1640
1793
|
|
1641
1794
|
post :create,
|
@@ -1663,10 +1816,13 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1663
1816
|
|
1664
1817
|
delete :destroy, {id: json_response['data']['id']}
|
1665
1818
|
assert_response :no_content
|
1819
|
+
ensure
|
1820
|
+
JSONAPI.configuration = original_config
|
1666
1821
|
end
|
1667
1822
|
|
1668
1823
|
def test_create_expense_entries_dasherized_key
|
1669
1824
|
set_content_type_header!
|
1825
|
+
original_config = JSONAPI.configuration.dup
|
1670
1826
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
1671
1827
|
|
1672
1828
|
post :create,
|
@@ -1694,6 +1850,8 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1694
1850
|
|
1695
1851
|
delete :destroy, {id: json_response['data']['id']}
|
1696
1852
|
assert_response :no_content
|
1853
|
+
ensure
|
1854
|
+
JSONAPI.configuration = original_config
|
1697
1855
|
end
|
1698
1856
|
end
|
1699
1857
|
|
@@ -1710,6 +1868,7 @@ class IsoCurrenciesControllerTest < ActionController::TestCase
|
|
1710
1868
|
|
1711
1869
|
def test_create_currencies_client_generated_id
|
1712
1870
|
set_content_type_header!
|
1871
|
+
original_config = JSONAPI.configuration.dup
|
1713
1872
|
JSONAPI.configuration.json_key_format = :underscored_route
|
1714
1873
|
|
1715
1874
|
post :create,
|
@@ -1733,6 +1892,8 @@ class IsoCurrenciesControllerTest < ActionController::TestCase
|
|
1733
1892
|
|
1734
1893
|
delete :destroy, {id: json_response['data']['id']}
|
1735
1894
|
assert_response :no_content
|
1895
|
+
ensure
|
1896
|
+
JSONAPI.configuration = original_config
|
1736
1897
|
end
|
1737
1898
|
|
1738
1899
|
def test_currencies_primary_key_sort
|
@@ -1750,6 +1911,7 @@ class IsoCurrenciesControllerTest < ActionController::TestCase
|
|
1750
1911
|
end
|
1751
1912
|
|
1752
1913
|
def test_currencies_json_key_underscored_sort
|
1914
|
+
original_config = JSONAPI.configuration.dup
|
1753
1915
|
JSONAPI.configuration.json_key_format = :underscored_key
|
1754
1916
|
get :index, {sort: 'country_name'}
|
1755
1917
|
assert_response :success
|
@@ -1765,9 +1927,12 @@ class IsoCurrenciesControllerTest < ActionController::TestCase
|
|
1765
1927
|
assert_equal 'United States', json_response['data'][0]['attributes']['country_name']
|
1766
1928
|
assert_equal 'Euro Member Countries', json_response['data'][1]['attributes']['country_name']
|
1767
1929
|
assert_equal 'Canada', json_response['data'][2]['attributes']['country_name']
|
1930
|
+
ensure
|
1931
|
+
JSONAPI.configuration = original_config
|
1768
1932
|
end
|
1769
1933
|
|
1770
1934
|
def test_currencies_json_key_dasherized_sort
|
1935
|
+
original_config = JSONAPI.configuration.dup
|
1771
1936
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
1772
1937
|
get :index, {sort: 'country-name'}
|
1773
1938
|
assert_response :success
|
@@ -1783,9 +1948,12 @@ class IsoCurrenciesControllerTest < ActionController::TestCase
|
|
1783
1948
|
assert_equal 'United States', json_response['data'][0]['attributes']['country-name']
|
1784
1949
|
assert_equal 'Euro Member Countries', json_response['data'][1]['attributes']['country-name']
|
1785
1950
|
assert_equal 'Canada', json_response['data'][2]['attributes']['country-name']
|
1951
|
+
ensure
|
1952
|
+
JSONAPI.configuration = original_config
|
1786
1953
|
end
|
1787
1954
|
|
1788
1955
|
def test_currencies_json_key_custom_json_key_sort
|
1956
|
+
original_config = JSONAPI.configuration.dup
|
1789
1957
|
JSONAPI.configuration.json_key_format = :upper_camelized_key
|
1790
1958
|
get :index, {sort: 'CountryName'}
|
1791
1959
|
assert_response :success
|
@@ -1801,30 +1969,41 @@ class IsoCurrenciesControllerTest < ActionController::TestCase
|
|
1801
1969
|
assert_equal 'United States', json_response['data'][0]['attributes']['CountryName']
|
1802
1970
|
assert_equal 'Euro Member Countries', json_response['data'][1]['attributes']['CountryName']
|
1803
1971
|
assert_equal 'Canada', json_response['data'][2]['attributes']['CountryName']
|
1972
|
+
ensure
|
1973
|
+
JSONAPI.configuration = original_config
|
1804
1974
|
end
|
1805
1975
|
|
1806
1976
|
def test_currencies_json_key_underscored_filter
|
1977
|
+
original_config = JSONAPI.configuration.dup
|
1807
1978
|
JSONAPI.configuration.json_key_format = :underscored_key
|
1808
1979
|
get :index, {filter: {country_name: 'Canada'}}
|
1809
1980
|
assert_response :success
|
1810
1981
|
assert_equal 1, json_response['data'].size
|
1811
1982
|
assert_equal 'Canada', json_response['data'][0]['attributes']['country_name']
|
1983
|
+
ensure
|
1984
|
+
JSONAPI.configuration = original_config
|
1812
1985
|
end
|
1813
1986
|
|
1814
1987
|
def test_currencies_json_key_camelized_key_filter
|
1988
|
+
original_config = JSONAPI.configuration.dup
|
1815
1989
|
JSONAPI.configuration.json_key_format = :camelized_key
|
1816
1990
|
get :index, {filter: {'countryName' => 'Canada'}}
|
1817
1991
|
assert_response :success
|
1818
1992
|
assert_equal 1, json_response['data'].size
|
1819
1993
|
assert_equal 'Canada', json_response['data'][0]['attributes']['countryName']
|
1994
|
+
ensure
|
1995
|
+
JSONAPI.configuration = original_config
|
1820
1996
|
end
|
1821
1997
|
|
1822
1998
|
def test_currencies_json_key_custom_json_key_filter
|
1999
|
+
original_config = JSONAPI.configuration.dup
|
1823
2000
|
JSONAPI.configuration.json_key_format = :upper_camelized_key
|
1824
2001
|
get :index, {filter: {'CountryName' => 'Canada'}}
|
1825
2002
|
assert_response :success
|
1826
2003
|
assert_equal 1, json_response['data'].size
|
1827
2004
|
assert_equal 'Canada', json_response['data'][0]['attributes']['CountryName']
|
2005
|
+
ensure
|
2006
|
+
JSONAPI.configuration = original_config
|
1828
2007
|
end
|
1829
2008
|
end
|
1830
2009
|
|
@@ -1851,6 +2030,7 @@ class PeopleControllerTest < ActionController::TestCase
|
|
1851
2030
|
end
|
1852
2031
|
|
1853
2032
|
def test_update_link_with_dasherized_type
|
2033
|
+
original_config = JSONAPI.configuration.dup
|
1854
2034
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
1855
2035
|
set_content_type_header!
|
1856
2036
|
put :update,
|
@@ -1870,6 +2050,8 @@ class PeopleControllerTest < ActionController::TestCase
|
|
1870
2050
|
}
|
1871
2051
|
}
|
1872
2052
|
assert_response :success
|
2053
|
+
ensure
|
2054
|
+
JSONAPI.configuration = original_config
|
1873
2055
|
end
|
1874
2056
|
|
1875
2057
|
def test_create_validations_missing_attribute
|
@@ -1933,6 +2115,7 @@ class PeopleControllerTest < ActionController::TestCase
|
|
1933
2115
|
end
|
1934
2116
|
|
1935
2117
|
def test_get_related_resource
|
2118
|
+
original_config = JSONAPI.configuration.dup
|
1936
2119
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
1937
2120
|
JSONAPI.configuration.route_format = :underscored_key
|
1938
2121
|
get :get_related_resource, {post_id: '2', relationship: 'author', source:'posts'}
|
@@ -1986,6 +2169,8 @@ class PeopleControllerTest < ActionController::TestCase
|
|
1986
2169
|
},
|
1987
2170
|
json_response
|
1988
2171
|
)
|
2172
|
+
ensure
|
2173
|
+
JSONAPI.configuration = original_config
|
1989
2174
|
end
|
1990
2175
|
|
1991
2176
|
def test_get_related_resource_nil
|
@@ -2195,6 +2380,7 @@ end
|
|
2195
2380
|
|
2196
2381
|
class FactsControllerTest < ActionController::TestCase
|
2197
2382
|
def test_type_formatting
|
2383
|
+
original_config = JSONAPI.configuration.dup
|
2198
2384
|
JSONAPI.configuration.json_key_format = :camelized_key
|
2199
2385
|
get :show, {id: '1'}
|
2200
2386
|
assert_response :success
|
@@ -2208,9 +2394,12 @@ class FactsControllerTest < ActionController::TestCase
|
|
2208
2394
|
assert_equal '2000-01-01T20:00:00Z', json_response['data']['attributes']['bedtime']
|
2209
2395
|
assert_equal 'abc', json_response['data']['attributes']['photo']
|
2210
2396
|
assert_equal false, json_response['data']['attributes']['cool']
|
2397
|
+
ensure
|
2398
|
+
JSONAPI.configuration = original_config
|
2211
2399
|
end
|
2212
2400
|
|
2213
2401
|
def test_create_with_invalid_data
|
2402
|
+
original_config = JSONAPI.configuration.dup
|
2214
2403
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
2215
2404
|
set_content_type_header!
|
2216
2405
|
post :create,
|
@@ -2242,6 +2431,8 @@ class FactsControllerTest < ActionController::TestCase
|
|
2242
2431
|
assert_equal "/data/attributes/bio", json_response['errors'][1]['source']['pointer']
|
2243
2432
|
assert_equal "can't be blank", json_response['errors'][1]['title']
|
2244
2433
|
assert_equal "bio - can't be blank", json_response['errors'][1]['detail']
|
2434
|
+
ensure
|
2435
|
+
JSONAPI.configuration = original_config
|
2245
2436
|
end
|
2246
2437
|
end
|
2247
2438
|
|
@@ -2447,25 +2638,25 @@ class Api::V2::BooksControllerTest < ActionController::TestCase
|
|
2447
2638
|
def test_books_banned_non_book_admin
|
2448
2639
|
$test_user = Person.find(1)
|
2449
2640
|
Api::V2::BookResource.paginator :offset
|
2641
|
+
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2450
2642
|
count_queries do
|
2451
|
-
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2452
2643
|
get :index, {page: {offset: 50, limit: 12}}
|
2453
|
-
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2454
2644
|
end
|
2455
2645
|
assert_response :success
|
2456
2646
|
assert_equal 12, json_response['data'].size
|
2457
2647
|
assert_equal 'Book 50', json_response['data'][0]['attributes']['title']
|
2458
2648
|
assert_equal 901, json_response['meta']['record-count']
|
2459
2649
|
assert_query_count(2)
|
2650
|
+
ensure
|
2651
|
+
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2460
2652
|
end
|
2461
2653
|
|
2462
2654
|
def test_books_banned_non_book_admin_includes_switched
|
2463
2655
|
$test_user = Person.find(1)
|
2464
2656
|
Api::V2::BookResource.paginator :offset
|
2657
|
+
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2465
2658
|
count_queries do
|
2466
|
-
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2467
2659
|
get :index, {page: {offset: 0, limit: 12}, include: 'book-comments'}
|
2468
|
-
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2469
2660
|
end
|
2470
2661
|
|
2471
2662
|
assert_response :success
|
@@ -2476,15 +2667,16 @@ class Api::V2::BooksControllerTest < ActionController::TestCase
|
|
2476
2667
|
assert_equal 'book-comments', json_response['included'][0]['type']
|
2477
2668
|
assert_equal 901, json_response['meta']['record-count']
|
2478
2669
|
assert_query_count(3)
|
2670
|
+
ensure
|
2671
|
+
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2479
2672
|
end
|
2480
2673
|
|
2481
2674
|
def test_books_banned_non_book_admin_includes_nested_includes
|
2482
2675
|
$test_user = Person.find(1)
|
2676
|
+
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2483
2677
|
Api::V2::BookResource.paginator :offset
|
2484
2678
|
count_queries do
|
2485
|
-
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2486
2679
|
get :index, {page: {offset: 0, limit: 12}, include: 'book-comments.author'}
|
2487
|
-
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2488
2680
|
end
|
2489
2681
|
assert_response :success
|
2490
2682
|
assert_equal 12, json_response['data'].size
|
@@ -2492,51 +2684,56 @@ class Api::V2::BooksControllerTest < ActionController::TestCase
|
|
2492
2684
|
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
|
2493
2685
|
assert_equal 901, json_response['meta']['record-count']
|
2494
2686
|
assert_query_count(4)
|
2687
|
+
ensure
|
2688
|
+
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2495
2689
|
end
|
2496
2690
|
|
2497
2691
|
def test_books_banned_admin
|
2498
2692
|
$test_user = Person.find(5)
|
2499
2693
|
Api::V2::BookResource.paginator :offset
|
2500
|
-
|
2501
|
-
|
2694
|
+
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2695
|
+
count_queries do
|
2502
2696
|
get :index, {page: {offset: 50, limit: 12}, filter: {banned: 'true'}}
|
2503
|
-
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2504
2697
|
end
|
2505
2698
|
assert_response :success
|
2506
2699
|
assert_equal 12, json_response['data'].size
|
2507
2700
|
assert_equal 'Book 651', json_response['data'][0]['attributes']['title']
|
2508
2701
|
assert_equal 99, json_response['meta']['record-count']
|
2509
2702
|
assert_query_count(2)
|
2703
|
+
ensure
|
2704
|
+
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2510
2705
|
end
|
2511
2706
|
|
2512
2707
|
def test_books_not_banned_admin
|
2513
2708
|
$test_user = Person.find(5)
|
2514
2709
|
Api::V2::BookResource.paginator :offset
|
2710
|
+
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2515
2711
|
count_queries do
|
2516
|
-
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2517
2712
|
get :index, {page: {offset: 50, limit: 12}, filter: {banned: 'false'}}
|
2518
|
-
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2519
2713
|
end
|
2520
2714
|
assert_response :success
|
2521
2715
|
assert_equal 12, json_response['data'].size
|
2522
2716
|
assert_equal 'Book 50', json_response['data'][0]['attributes']['title']
|
2523
2717
|
assert_equal 901, json_response['meta']['record-count']
|
2524
2718
|
assert_query_count(2)
|
2719
|
+
ensure
|
2720
|
+
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2525
2721
|
end
|
2526
2722
|
|
2527
2723
|
def test_books_banned_non_book_admin_overlapped
|
2528
2724
|
$test_user = Person.find(1)
|
2529
2725
|
Api::V2::BookResource.paginator :offset
|
2726
|
+
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2530
2727
|
count_queries do
|
2531
|
-
JSONAPI.configuration.top_level_meta_include_record_count = true
|
2532
2728
|
get :index, {page: {offset: 590, limit: 20}}
|
2533
|
-
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2534
2729
|
end
|
2535
2730
|
assert_response :success
|
2536
2731
|
assert_equal 20, json_response['data'].size
|
2537
2732
|
assert_equal 'Book 590', json_response['data'][0]['attributes']['title']
|
2538
2733
|
assert_equal 901, json_response['meta']['record-count']
|
2539
2734
|
assert_query_count(2)
|
2735
|
+
ensure
|
2736
|
+
JSONAPI.configuration.top_level_meta_include_record_count = false
|
2540
2737
|
end
|
2541
2738
|
|
2542
2739
|
def test_books_included_exclude_unapproved
|
@@ -2625,6 +2822,7 @@ class Api::V4::BooksControllerTest < ActionController::TestCase
|
|
2625
2822
|
end
|
2626
2823
|
|
2627
2824
|
def test_books_offset_pagination_meta
|
2825
|
+
original_config = JSONAPI.configuration.dup
|
2628
2826
|
JSONAPI.configuration.operations_processor = :counting_active_record
|
2629
2827
|
Api::V4::BookResource.paginator :offset
|
2630
2828
|
get :index, {page: {offset: 50, limit: 12}}
|
@@ -2632,10 +2830,12 @@ class Api::V4::BooksControllerTest < ActionController::TestCase
|
|
2632
2830
|
assert_equal 12, json_response['data'].size
|
2633
2831
|
assert_equal 'Book 50', json_response['data'][0]['attributes']['title']
|
2634
2832
|
assert_equal 901, json_response['meta']['totalRecords']
|
2635
|
-
|
2833
|
+
ensure
|
2834
|
+
JSONAPI.configuration = original_config
|
2636
2835
|
end
|
2637
2836
|
|
2638
2837
|
def test_books_operation_links
|
2838
|
+
original_config = JSONAPI.configuration.dup
|
2639
2839
|
JSONAPI.configuration.operations_processor = :counting_active_record
|
2640
2840
|
Api::V4::BookResource.paginator :offset
|
2641
2841
|
get :index, {page: {offset: 50, limit: 12}}
|
@@ -2644,7 +2844,8 @@ class Api::V4::BooksControllerTest < ActionController::TestCase
|
|
2644
2844
|
assert_equal 'Book 50', json_response['data'][0]['attributes']['title']
|
2645
2845
|
assert_equal 5, json_response['links'].size
|
2646
2846
|
assert_equal 'https://test_corp.com', json_response['links']['spec']
|
2647
|
-
|
2847
|
+
ensure
|
2848
|
+
JSONAPI.configuration = original_config
|
2648
2849
|
end
|
2649
2850
|
end
|
2650
2851
|
|
@@ -38,37 +38,50 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_get_underscored_key
|
41
|
+
original_config = JSONAPI.configuration.dup
|
41
42
|
JSONAPI.configuration.json_key_format = :underscored_key
|
42
43
|
get '/iso_currencies'
|
43
44
|
assert_equal 200, status
|
44
45
|
assert_equal 3, json_response['data'].size
|
46
|
+
ensure
|
47
|
+
JSONAPI.configuration = original_config
|
45
48
|
end
|
46
49
|
|
47
50
|
def test_get_underscored_key_filtered
|
51
|
+
original_config = JSONAPI.configuration.dup
|
48
52
|
JSONAPI.configuration.json_key_format = :underscored_key
|
49
53
|
get '/iso_currencies?filter[country_name]=Canada'
|
50
54
|
assert_equal 200, status
|
51
55
|
assert_equal 1, json_response['data'].size
|
52
56
|
assert_equal 'Canada', json_response['data'][0]['attributes']['country_name']
|
57
|
+
ensure
|
58
|
+
JSONAPI.configuration = original_config
|
53
59
|
end
|
54
60
|
|
55
61
|
def test_get_camelized_key_filtered
|
62
|
+
original_config = JSONAPI.configuration.dup
|
56
63
|
JSONAPI.configuration.json_key_format = :camelized_key
|
57
64
|
get '/iso_currencies?filter[countryName]=Canada'
|
58
65
|
assert_equal 200, status
|
59
66
|
assert_equal 1, json_response['data'].size
|
60
67
|
assert_equal 'Canada', json_response['data'][0]['attributes']['countryName']
|
68
|
+
ensure
|
69
|
+
JSONAPI.configuration = original_config
|
61
70
|
end
|
62
71
|
|
63
72
|
def test_get_camelized_route_and_key_filtered
|
73
|
+
original_config = JSONAPI.configuration.dup
|
64
74
|
JSONAPI.configuration.json_key_format = :camelized_key
|
65
75
|
get '/api/v4/isoCurrencies?filter[countryName]=Canada'
|
66
76
|
assert_equal 200, status
|
67
77
|
assert_equal 1, json_response['data'].size
|
68
78
|
assert_equal 'Canada', json_response['data'][0]['attributes']['countryName']
|
79
|
+
ensure
|
80
|
+
JSONAPI.configuration = original_config
|
69
81
|
end
|
70
82
|
|
71
83
|
def test_get_camelized_route_and_links
|
84
|
+
original_config = JSONAPI.configuration.dup
|
72
85
|
JSONAPI.configuration.json_key_format = :camelized_key
|
73
86
|
JSONAPI.configuration.route_format = :camelized_route
|
74
87
|
get '/api/v4/expenseEntries/1/relationships/isoCurrency'
|
@@ -82,6 +95,8 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
82
95
|
'id' => 'USD'
|
83
96
|
}
|
84
97
|
}, json_response)
|
98
|
+
ensure
|
99
|
+
JSONAPI.configuration = original_config
|
85
100
|
end
|
86
101
|
|
87
102
|
def test_put_single_without_content_type
|
@@ -398,6 +413,19 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
398
413
|
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=41', json_response['links']['last']
|
399
414
|
end
|
400
415
|
|
416
|
+
def test_pagination_related_resources_links_meta
|
417
|
+
Api::V2::BookResource.paginator :offset
|
418
|
+
Api::V2::BookCommentResource.paginator :offset
|
419
|
+
JSONAPI.configuration.top_level_meta_include_record_count = true
|
420
|
+
get '/api/v2/books/1/book_comments?page[limit]=10'
|
421
|
+
assert_equal 51, json_response['meta']['record_count']
|
422
|
+
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=0', json_response['links']['first']
|
423
|
+
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=10', json_response['links']['next']
|
424
|
+
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=41', json_response['links']['last']
|
425
|
+
ensure
|
426
|
+
JSONAPI.configuration.top_level_meta_include_record_count = false
|
427
|
+
end
|
428
|
+
|
401
429
|
def test_pagination_related_resources_without_related
|
402
430
|
Api::V2::BookResource.paginator :offset
|
403
431
|
Api::V2::BookCommentResource.paginator :offset
|
@@ -511,6 +539,7 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
511
539
|
end
|
512
540
|
|
513
541
|
def test_flow_self_formatted_route_1
|
542
|
+
original_config = JSONAPI.configuration.dup
|
514
543
|
JSONAPI.configuration.route_format = :dasherized_route
|
515
544
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
516
545
|
get '/api/v6/purchase-orders'
|
@@ -521,9 +550,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
521
550
|
get po_1['links']['self']
|
522
551
|
assert_equal 200, status
|
523
552
|
assert_hash_equals po_1, json_response['data']
|
553
|
+
ensure
|
554
|
+
JSONAPI.configuration = original_config
|
524
555
|
end
|
525
556
|
|
526
557
|
def test_flow_self_formatted_route_2
|
558
|
+
original_config = JSONAPI.configuration.dup
|
527
559
|
JSONAPI.configuration.route_format = :underscored_route
|
528
560
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
529
561
|
get '/api/v7/purchase_orders'
|
@@ -535,9 +567,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
535
567
|
get po_1['links']['self']
|
536
568
|
assert_equal 200, status
|
537
569
|
assert_hash_equals po_1, json_response['data']
|
570
|
+
ensure
|
571
|
+
JSONAPI.configuration = original_config
|
538
572
|
end
|
539
573
|
|
540
574
|
def test_flow_self_formatted_route_3
|
575
|
+
original_config = JSONAPI.configuration.dup
|
541
576
|
JSONAPI.configuration.route_format = :underscored_route
|
542
577
|
JSONAPI.configuration.json_key_format = :underscored_key
|
543
578
|
get '/api/v7/purchase_orders'
|
@@ -549,9 +584,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
549
584
|
get po_1['links']['self']
|
550
585
|
assert_equal 200, status
|
551
586
|
assert_hash_equals po_1, json_response['data']
|
587
|
+
ensure
|
588
|
+
JSONAPI.configuration = original_config
|
552
589
|
end
|
553
590
|
|
554
591
|
def test_post_formatted_keys
|
592
|
+
original_config = JSONAPI.configuration.dup
|
555
593
|
JSONAPI.configuration.route_format = :dasherized_route
|
556
594
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
557
595
|
post '/api/v6/purchase-orders',
|
@@ -565,9 +603,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
565
603
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
566
604
|
|
567
605
|
assert_equal 201, status
|
606
|
+
ensure
|
607
|
+
JSONAPI.configuration = original_config
|
568
608
|
end
|
569
609
|
|
570
610
|
def test_post_formatted_keys_different_route_key_1
|
611
|
+
original_config = JSONAPI.configuration.dup
|
571
612
|
JSONAPI.configuration.route_format = :dasherized_route
|
572
613
|
JSONAPI.configuration.json_key_format = :underscored_key
|
573
614
|
post '/api/v6/purchase-orders',
|
@@ -581,9 +622,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
581
622
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
582
623
|
|
583
624
|
assert_equal 201, status
|
625
|
+
ensure
|
626
|
+
JSONAPI.configuration = original_config
|
584
627
|
end
|
585
628
|
|
586
629
|
def test_post_formatted_keys_different_route_key_2
|
630
|
+
original_config = JSONAPI.configuration.dup
|
587
631
|
JSONAPI.configuration.route_format = :underscored_route
|
588
632
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
589
633
|
post '/api/v7/purchase_orders',
|
@@ -597,9 +641,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
597
641
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
598
642
|
|
599
643
|
assert_equal 201, status
|
644
|
+
ensure
|
645
|
+
JSONAPI.configuration = original_config
|
600
646
|
end
|
601
647
|
|
602
648
|
def test_post_formatted_keys_wrong_format
|
649
|
+
original_config = JSONAPI.configuration.dup
|
603
650
|
JSONAPI.configuration.route_format = :dasherized_route
|
604
651
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
605
652
|
post '/api/v6/purchase-orders',
|
@@ -613,9 +660,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
613
660
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
614
661
|
|
615
662
|
assert_equal 400, status
|
663
|
+
ensure
|
664
|
+
JSONAPI.configuration = original_config
|
616
665
|
end
|
617
666
|
|
618
667
|
def test_patch_formatted_dasherized
|
668
|
+
original_config = JSONAPI.configuration.dup
|
619
669
|
JSONAPI.configuration.route_format = :dasherized_route
|
620
670
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
621
671
|
patch '/api/v6/purchase-orders/1',
|
@@ -633,6 +683,7 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
633
683
|
end
|
634
684
|
|
635
685
|
def test_patch_formatted_dasherized_links
|
686
|
+
original_config = JSONAPI.configuration.dup
|
636
687
|
JSONAPI.configuration.route_format = :dasherized_route
|
637
688
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
638
689
|
patch '/api/v6/line-items/1',
|
@@ -652,9 +703,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
652
703
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
653
704
|
|
654
705
|
assert_equal 200, status
|
706
|
+
ensure
|
707
|
+
JSONAPI.configuration = original_config
|
655
708
|
end
|
656
709
|
|
657
710
|
def test_patch_formatted_dasherized_replace_to_many
|
711
|
+
original_config = JSONAPI.configuration.dup
|
658
712
|
JSONAPI.configuration.route_format = :dasherized_route
|
659
713
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
660
714
|
patch '/api/v6/purchase-orders/2?include=line-items,order-flags',
|
@@ -680,9 +734,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
680
734
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
681
735
|
|
682
736
|
assert_equal 200, status
|
737
|
+
ensure
|
738
|
+
JSONAPI.configuration = original_config
|
683
739
|
end
|
684
740
|
|
685
741
|
def test_post_to_many_link
|
742
|
+
original_config = JSONAPI.configuration.dup
|
686
743
|
JSONAPI.configuration.route_format = :dasherized_route
|
687
744
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
688
745
|
post '/api/v6/purchase-orders/3/relationships/line-items',
|
@@ -694,9 +751,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
694
751
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
695
752
|
|
696
753
|
assert_equal 204, status
|
754
|
+
ensure
|
755
|
+
JSONAPI.configuration = original_config
|
697
756
|
end
|
698
757
|
|
699
758
|
def test_patch_to_many_link
|
759
|
+
original_config = JSONAPI.configuration.dup
|
700
760
|
JSONAPI.configuration.route_format = :dasherized_route
|
701
761
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
702
762
|
patch '/api/v6/purchase-orders/3/relationships/order-flags',
|
@@ -708,9 +768,12 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
708
768
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
709
769
|
|
710
770
|
assert_equal 204, status
|
771
|
+
ensure
|
772
|
+
JSONAPI.configuration = original_config
|
711
773
|
end
|
712
774
|
|
713
775
|
def test_patch_to_one
|
776
|
+
original_config = JSONAPI.configuration.dup
|
714
777
|
JSONAPI.configuration.route_format = :dasherized_route
|
715
778
|
JSONAPI.configuration.json_key_format = :dasherized_key
|
716
779
|
patch '/api/v6/line-items/5/relationships/purchase-order',
|
@@ -719,6 +782,8 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
719
782
|
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
720
783
|
|
721
784
|
assert_equal 204, status
|
785
|
+
ensure
|
786
|
+
JSONAPI.configuration = original_config
|
722
787
|
end
|
723
788
|
|
724
789
|
def test_include_parameter_allowed
|
@@ -964,6 +964,7 @@ class SerializerTest < ActionDispatch::IntegrationTest
|
|
964
964
|
JSONAPI::ResourceSerializer.new(PostResource,
|
965
965
|
include: ['comments', 'comments.tags']).serialize_to_hash(posts)
|
966
966
|
)
|
967
|
+
ensure
|
967
968
|
JSONAPI.configuration.always_include_to_one_linkage_data = false
|
968
969
|
end
|
969
970
|
|
@@ -1410,9 +1411,6 @@ class SerializerTest < ActionDispatch::IntegrationTest
|
|
1410
1411
|
end
|
1411
1412
|
|
1412
1413
|
def test_serializer_camelized_with_value_formatters
|
1413
|
-
# JSONAPI.configuration.json_key_format = :camelized_key
|
1414
|
-
# JSONAPI.configuration.route_format = :camelized_route
|
1415
|
-
|
1416
1414
|
assert_hash_equals(
|
1417
1415
|
{
|
1418
1416
|
data: {
|
@@ -1618,6 +1616,7 @@ class SerializerTest < ActionDispatch::IntegrationTest
|
|
1618
1616
|
end
|
1619
1617
|
|
1620
1618
|
def test_serializer_booleans
|
1619
|
+
original_config = JSONAPI.configuration.dup
|
1621
1620
|
JSONAPI.configuration.json_key_format = :underscored_key
|
1622
1621
|
|
1623
1622
|
preferences = PreferencesResource.new(Preferences.find(1))
|
@@ -1651,9 +1650,12 @@ class SerializerTest < ActionDispatch::IntegrationTest
|
|
1651
1650
|
},
|
1652
1651
|
JSONAPI::ResourceSerializer.new(PreferencesResource).serialize_to_hash(preferences)
|
1653
1652
|
)
|
1653
|
+
ensure
|
1654
|
+
JSONAPI.configuration = original_config
|
1654
1655
|
end
|
1655
1656
|
|
1656
1657
|
def test_serializer_data_types
|
1658
|
+
original_config = JSONAPI.configuration.dup
|
1657
1659
|
JSONAPI.configuration.json_key_format = :underscored_key
|
1658
1660
|
|
1659
1661
|
facts = FactResource.new(Fact.find(1))
|
@@ -1681,6 +1683,8 @@ class SerializerTest < ActionDispatch::IntegrationTest
|
|
1681
1683
|
},
|
1682
1684
|
JSONAPI::ResourceSerializer.new(FactResource).serialize_to_hash(facts)
|
1683
1685
|
)
|
1686
|
+
ensure
|
1687
|
+
JSONAPI.configuration = original_config
|
1684
1688
|
end
|
1685
1689
|
|
1686
1690
|
def test_serializer_to_one
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gebhardt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-08-
|
12
|
+
date: 2015-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|