jsonapi-rb / jsonapi-rspec

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

`have_type` comparison consistency improvements #25

Closed kjuri closed 4 years ago

kjuri commented 4 years ago

What is the current behavior?

Currently, we're assuming that actual type is always a string, which causes test failures whenever type is a symbol. In my case it is caused by those lines of JSONAPI::Serializable::Resource:

        @_type = if (b = self.class.type_block)
                   instance_eval(&b).to_sym
                 else
                   self.class.type_val || :unknown
                 end

It always transforms type to a symbol so the tests fail as have_type compares it to a string.

What is the new behavior?

The actual type is transformed into a string for a comparison consistency.

Checklist

Please make sure the following requirements are complete:

stas commented 4 years ago

@kjuri I'd be happy to merge it, but following the JSONAPI Specs a type should always be a string and it's optional in some cases.

I believe the implementation you are referring to needs to be fixed outside of this library.

Let me know if this makes sense. Thank you though!!! :bow:

kjuri commented 4 years ago

@stas Thanks for clarifying, maybe PR should be done to JSONAPI::Serializable::Resource then :)