-
Notifications
You must be signed in to change notification settings - Fork 23
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
Inconsistentcy, have_jsonapi_attributes should not allow symbols #17
Comments
@nattfodd thanks for reporting this... but could you please explain or provide an example what exactly is the problem here? I'm not sure I understand where's the inconsistency? Are you trying to say that |
Here is an example: class ProductSerializer
include FastJsonapi::ObjectSerializer
attributes :title, :price
end
describe ProductSerializer do
let(:product) { FactoryBot.create(:product) }
it 'has title & price attributes' do
data = ProductSerializer.new(product).serializable_json[:data]
expect(data).to have_jsonapi_attributes(:title, :price) # fails
expect(data.with_indifferent_access).to have_jsonapi_attributes(:title, :price) # works
expect(data).to have_jsonapi_attributes('title', 'price') # also works
end
end The first expectation |
Thanks @nattfodd, makes sense now. Patches welcome btw 🙃 |
@nattfodd please give the latest version a test, there's a new option to configure the matchers to be indifferent to symbols/strings. |
@nattfodd I'm closing this as part of 56226ed Since the JSON:API requires a valid JSON document which means string keys, the marchers will always try to do the conversion where spec enforces it: |
FastJsonapi serializer returns keys as symbols with
MySerializer.new(data).serializable_hash
, including:attributes
. It's pretty unobvious that you can sayexpect(data).to have_jsonapi_attributes(:foo, :bar)
but yourdata
object should be{ 'attributes' => { foo: 1, bar: 2 } }
with "attribute" key being precisely a string.jsonapi-rspec/lib/jsonapi/rspec/attributes.rb
Line 18 in c68657c
The text was updated successfully, but these errors were encountered: