@@ -12,7 +12,9 @@ class << self
1212 end
1313
1414 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 )
1618 render jsonapi : author
1719 end
1820
@@ -59,18 +61,12 @@ def test_jsonapi_parser_not_registered
5961 end
6062
6163 def test_jsonapi_renderer_not_registered
62- expected = {
63- 'data' => {
64- 'attributes' => {
65- 'name' => 'Johnny Rico'
66- } ,
67- 'type' => 'users'
68- }
69- }
7064 payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}'
7165 headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
7266 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?
7470 end
7571
7672 def test_jsonapi_parser
@@ -113,16 +109,21 @@ def test_jsonapi_parser_registered
113109 def test_jsonapi_renderer_registered
114110 expected = {
115111 '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+ }
120120 }
121121 }
122+
122123 payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}'
123124 headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
124125 post '/render_with_jsonapi_renderer' , params : payload , headers : headers
125- assert expected , response . body
126+ assert_equal expected . to_json , response . body
126127 end
127128
128129 def test_jsonapi_parser
0 commit comments