From 59aed4d00e3a6f6102b517f495b3180cbec1f542 Mon Sep 17 00:00:00 2001 From: Ankit Shah Date: Sat, 24 Dec 2016 21:34:07 -0500 Subject: [PATCH] Updated isolated tests to assert correct behavior. (#2010) * Updated isolated tests to assert correct behavior. * Added check to get unsafe params if rails version is great than 5 --- ...register_jsonapi_renderer_test_isolated.rb | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb b/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb index 9ba79e229..616d42b06 100644 --- a/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +++ b/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb @@ -12,7 +12,9 @@ class << self end def render_with_jsonapi_renderer - author = Author.new(params[:data][:attributes]) + unlocked_params = Rails::VERSION::MAJOR >= 5 ? params.to_unsafe_h : params + attributes = unlocked_params[:data].present? ? unlocked_params[:data][:attributes] : {} + author = Author.new(attributes) render jsonapi: author end @@ -59,18 +61,12 @@ def test_jsonapi_parser_not_registered end def test_jsonapi_renderer_not_registered - expected = { - 'data' => { - 'attributes' => { - 'name' => 'Johnny Rico' - }, - 'type' => 'users' - } - } payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}' headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' } post '/render_with_jsonapi_renderer', params: payload, headers: headers - assert expected, response.body + assert_equal 500, response.status + assert_equal '', response.body + assert response.request.env['action_dispatch.exception'].is_a?(ActionView::MissingTemplate) if response.request.present? end def test_jsonapi_parser @@ -113,16 +109,21 @@ def test_jsonapi_parser_registered def test_jsonapi_renderer_registered expected = { 'data' => { - 'attributes' => { - 'name' => 'Johnny Rico' - }, - 'type' => 'users' + 'id' => 'author', + 'type' => 'authors', + 'attributes' => { 'name' => 'Johnny Rico' }, + 'relationships' => { + 'posts' => { 'data' => nil }, + 'roles' => { 'data' => nil }, + 'bio' => { 'data' => nil } + } } } + payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}' headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' } post '/render_with_jsonapi_renderer', params: payload, headers: headers - assert expected, response.body + assert_equal expected.to_json, response.body end def test_jsonapi_parser