-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Updated isolated tests to assert correct behavior. #2010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8d18374
921ffac
baf58c7
57a4fc2
2debd58
b712de3
377ea05
c4a27b2
822e1b2
ffde106
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,11 @@ def render_with_jsonapi_renderer | |
render jsonapi: author | ||
end | ||
|
||
def render_with_jsonapi_fields | ||
post = Post.new(params[:data][:attributes]) | ||
render jsonapi: post, fields: {posts: ['title']} | ||
end | ||
|
||
def parse | ||
self.class.last_request_parameters = request.request_parameters | ||
head :ok | ||
|
@@ -58,21 +63,6 @@ def test_jsonapi_parser_not_registered | |
assert_nil parsers[Mime[:jsonapi]] | ||
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 | ||
end | ||
|
||
def test_jsonapi_parser | ||
assert_parses( | ||
{}, | ||
|
@@ -111,18 +101,20 @@ def test_jsonapi_parser_registered | |
end | ||
|
||
def test_jsonapi_renderer_registered | ||
expected = { | ||
'data' => { | ||
'attributes' => { | ||
'name' => 'Johnny Rico' | ||
}, | ||
'type' => 'users' | ||
} | ||
} | ||
expected = {'name' => 'Johnny Rico'} | ||
|
||
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, JSON.parse(response.body)["data"]["attributes"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was because actual response has tons of other things added to it like meta, relationships which was not part of this test and would break anytime a new element is added. |
||
end | ||
|
||
def test_jsonapi_renderer_registered_withfields | ||
expected = {'title' => 'This is a test' } | ||
payload = '{"data": {"attributes": {"title": "This is a test","body": "Of an emergency alert system."}, "type": "posts"},"fields": { "posts" : ["title"] } }' | ||
headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' } | ||
post '/render_with_jsonapi_fields?fields[posts][]=title', params: payload, headers: headers | ||
assert_equal expected, JSON.parse(response.body)["data"]["attributes"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this test belongs here. (typo in name as well). This test appears to be testing usage of the jsonapi renderer, where all this file is doing is testing registering it, which is why it's isolated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point. I will remove it. |
||
end | ||
|
||
def test_jsonapi_parser | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should include a uuid here. how about
"id": ""36c9c04e-86b1-4636-a5b0-8616672d1765"
will make the expectation simpler. JSON API recommends that if a client wants to create an id on post, to use a uuid.You've been working on this PR a while now, and the main goal of it is done. Thanks! I can do some of the other things I'd like in a followup :)