Skip to content

assert_payload tests can become false positives on empty attributes payload and nil json_item #8

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

Open
Startouf opened this issue Jul 26, 2017 · 1 comment

Comments

@Startouf
Copy link

Startouf commented Jul 26, 2017

I have special payload/serialized result in my app made almost entirely of relationships and no attributes (a conversation = list of messages + references to senders, etc.)

Therefore, my test payload declaration was empty.

In my test, the payload assertion was passing although the return from the controller was nil / the test should have failed

In a nutshell :

# spec/payloads/messaging/conversation.rb
JsonapiSpecHelpers::Payload.register(:'messaging/conversation') do
# empty, only relationships
end

# spec/requests/messaging/conversations_controller.rb
...
json_item = {"id"=>nil, "jsonapi_type"=>nil}
assert_payload(:'messaging/conversation', conversation, json_item)
# Would pass !
@Startouf Startouf changed the title assert_payload tests can pass on empty attributes payload and nil json_item assert_payload tests can become false positives on empty attributes payload and nil json_item Jul 26, 2017
@richmolj
Copy link
Contributor

Yeah, this is a good point. Currently we validate all the payload keys, but not id/type. We should add that. I can get to that within a week or so.

happycollision added a commit to happycollision/jsonapi_spec_helpers that referenced this issue Feb 24, 2018
happycollision added a commit to happycollision/jsonapi_spec_helpers that referenced this issue Feb 24, 2018
Fixes jsonapi-suite#8

This produces a failure when the json id doesn't match the record id or when there is no jsonapi_type present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants