Skip to content

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

Closed
@Startouf

Description

@Startouf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions