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
This commit is contained in:
Ankit Shah 2016-12-24 21:34:07 -05:00 committed by Benjamin Fleischer
parent 4e430132db
commit f246741cc5

View File

@ -12,7 +12,9 @@ class JsonApiRendererTest < ActionDispatch::IntegrationTest
end end
def render_with_jsonapi_renderer 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 render jsonapi: author
end end
@ -59,18 +61,12 @@ class JsonApiRendererTest < ActionDispatch::IntegrationTest
end end
def test_jsonapi_renderer_not_registered def test_jsonapi_renderer_not_registered
expected = {
'data' => {
'attributes' => {
'name' => 'Johnny Rico'
},
'type' => 'users'
}
}
payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}' payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}'
headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' } headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
post '/render_with_jsonapi_renderer', params: payload, headers: headers 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 end
def test_jsonapi_parser def test_jsonapi_parser
@ -113,16 +109,21 @@ class JsonApiRendererTest < ActionDispatch::IntegrationTest
def test_jsonapi_renderer_registered def test_jsonapi_renderer_registered
expected = { expected = {
'data' => { 'data' => {
'attributes' => { 'id' => 'author',
'name' => 'Johnny Rico' 'type' => 'authors',
}, 'attributes' => { 'name' => 'Johnny Rico' },
'type' => 'users' 'relationships' => {
'posts' => { 'data' => nil },
'roles' => { 'data' => nil },
'bio' => { 'data' => nil }
}
} }
} }
payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}' payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "authors"}}'
headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' } headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
post '/render_with_jsonapi_renderer', params: payload, headers: headers post '/render_with_jsonapi_renderer', params: payload, headers: headers
assert expected, response.body assert_equal expected.to_json, response.body
end end
def test_jsonapi_parser def test_jsonapi_parser