jsonapi-rspec
jsonapi-rspec copied to clipboard
Convert have_id matcher argument to string.
What is the current behavior?
According to docs this two lines should be equivalent:
expect(document['data']).to have_id(12)
expect(document['data']).to have_id('12')
But the first line will fail if the id
value in the hash is a string, and the second line will fail if the id
value is another type than a string.
What is the new behavior?
Convert expected value and actual value to a string in the have_id
matcher.
Checklist
Please make sure the following requirements are complete:
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been reviewed and added / updated if needed (for bug fixes / features)
- [ ] All automated checks pass (CI/CD)
@wildfiler I'm afraid your JSONAPI document is invalid if it is using integers: https://jsonapi.org/format/#document-resource-object-identification
Every resource object MUST contain an id member and a type member. The values of the id and type members MUST be strings.
I think the PR makes sense, as long as we convert just the expected
value into string. @wildfiler would you be kind to update your PR please?
@stas Yes, I agree and I did it in the first iteration, but after that, I saw this issue: https://github.com/jsonapi-rb/jsonapi-rspec/issues/29 and related PR: #30
If you think this should not be a problem with id
then I'll change it :)
Nah, all good, please feel free to update it and I'll get it merged and released.
Thank you! :bow: