Skip to content

Commit

Permalink
Updated isolated tests to assert correct behavior. (#2010)
Browse files Browse the repository at this point in the history
* Updated isolated tests to assert correct behavior.
* Added check to get unsafe params if rails version is great than 5
  • Loading branch information
akshah123 authored and bf4 committed Jan 6, 2017
1 parent 4a184de commit 3a88c39
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3a88c39

Please sign in to comment.