@@ -12,7 +12,9 @@ class << self
12
12
end
13
13
14
14
def render_with_jsonapi_renderer
15
- author = Author . new ( params [ :data ] [ :attributes ] )
15
+ unlocked_params = Rails ::VERSION ::MAJOR >= 5 ? params . to_unsafe_h : params
16
+ attributes = unlocked_params [ :data ] . present? ? unlocked_params [ :data ] [ :attributes ] : { }
17
+ author = Author . new ( attributes )
16
18
render jsonapi : author
17
19
end
18
20
@@ -59,18 +61,12 @@ def test_jsonapi_parser_not_registered
59
61
end
60
62
61
63
def test_jsonapi_renderer_not_registered
62
- expected = {
63
- 'data' => {
64
- 'attributes' => {
65
- 'name' => 'Johnny Rico'
66
- } ,
67
- 'type' => 'users'
68
- }
69
- }
70
64
payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}'
71
65
headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
72
66
post '/render_with_jsonapi_renderer' , params : payload , headers : headers
73
- assert expected , response . body
67
+ assert_equal 500 , response . status
68
+ assert_equal '' , response . body
69
+ assert response . request . env [ 'action_dispatch.exception' ] . is_a? ( ActionView ::MissingTemplate ) if response . request . present?
74
70
end
75
71
76
72
def test_jsonapi_parser
@@ -113,16 +109,21 @@ def test_jsonapi_parser_registered
113
109
def test_jsonapi_renderer_registered
114
110
expected = {
115
111
'data' => {
116
- 'attributes' => {
117
- 'name' => 'Johnny Rico'
118
- } ,
119
- 'type' => 'users'
112
+ 'id' => 'author' ,
113
+ 'type' => 'authors' ,
114
+ 'attributes' => { 'name' => 'Johnny Rico' } ,
115
+ 'relationships' => {
116
+ 'posts' => { 'data' => nil } ,
117
+ 'roles' => { 'data' => nil } ,
118
+ 'bio' => { 'data' => nil }
119
+ }
120
120
}
121
121
}
122
+
122
123
payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}'
123
124
headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
124
125
post '/render_with_jsonapi_renderer' , params : payload , headers : headers
125
- assert expected , response . body
126
+ assert_equal expected . to_json , response . body
126
127
end
127
128
128
129
def test_jsonapi_parser
0 commit comments