jsonapi-rspec icon indicating copy to clipboard operation
jsonapi-rspec copied to clipboard

Convert have_id matcher argument to string.

Open wildfiler opened this issue 3 years ago • 3 comments

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 avatar Jan 16 '22 08:01 wildfiler

@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 avatar Jan 17 '22 12:01 stas

@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 :)

wildfiler avatar Jan 17 '22 13:01 wildfiler

Nah, all good, please feel free to update it and I'll get it merged and released.

Thank you! :bow:

stas avatar Jan 17 '22 17:01 stas