Skip to content

json_include(nil) returns the base document and may cause false-passing tests #5

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

Closed
Startouf opened this issue Jun 25, 2017 · 0 comments

Comments

@Startouf
Copy link

Startouf commented Jun 25, 2017

I was trying to assert an included jsonapi document with

# Assume `class Foo has_one(:bar, polymorphic: true)`
describe 'foos#show' do
  context 'with included bar' do 
    foo_in_db, bar_in_db = seed_a_foo_with_a_bar # Foo.find(42).bar exists
    get "/foos/42", params: { include: 'bar }
    foo_json = json_item
    bar_included_in_foo_json = json_include(json_included_types.first) 
    expect(json_included_item).to be
    assert_payload(:'bar_payload', bar_in_db, bar_included_in_foo_json)

The problem : there was a bug in my application code (irrelevant here) and json_included_types.first was nil/didn't contain my expected Bar, therefore resulting in a json_include(nil) which did not return an error and instead returned a version of the main json_item (Foo) stripped of its metadata, causing the test to pass when it actually failed

happycollision added a commit to happycollision/jsonapi_spec_helpers that referenced this issue Feb 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant