jsonapi-rb / jsonapi-rspec

RSpec matchers for JSON:API spec
https://rubygems.org/gems/jsonapi-rspec
MIT License
123 stars 24 forks source link

Convert have_id matcher argument to string. #31

Open wildfiler opened 2 years ago

wildfiler commented 2 years ago

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:

stas commented 2 years ago

@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?

wildfiler commented 2 years ago

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

stas commented 2 years ago

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

Thank you! :bow: