Skip to content
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

assert_schema_conform requires status code explicitly as of committee 4.4.0 #24

Open
kajisha opened this issue Dec 22, 2021 · 1 comment

Comments

@kajisha
Copy link
Collaborator

kajisha commented Dec 22, 2021

As of committee 4.4.0, assert_schema_conform requires HTTP status code explicitly.
Ref. interagent/committee@9a388e5

But schema_conformist calls assert_schema_conform without status code in https://github.com/kymmt90/schema_conformist/blob/master/lib/schema_conformist/process_with_assertion.rb#L10

I think that we need a discussion how to deal with newly introduced assert_schema_conform/1.

@kymmt90 What do you think about this?

@kymmt90
Copy link
Owner

kymmt90 commented Dec 30, 2021

Sorry for the late reply. These are my ideas:

  1. Introduce :expected_status or something like that to the kwargs of ProcessWithAssertion#process
  2. Set the return value of super(i.e. the return value of ActionDispatch::Integration::Session#process) in ProcessWithAssertion#process to the expected return code for assert_schema_conform

1 is a straightforward but redundant solution. We have to set expected status code value for each request:

# ProcessWithAssertion
def process(method, path, **kwargs)
  super(method, path, kwargs.except(:expected_status))

  return if schema_conformist_ignored_path?(path)

  assert_schema_conform(kwargs[:expected_status])
end

# in test
test 'GET /products' do
  get products_url, as: :json, expected_status: 200
end

On the other hand, 2 is a solution which is a little bit inappropriate in the meaning of the "expected status code" but keeps current behavior:

# ProcessWithAssertion
def process(method, path, **kwargs)
  status = super

  return if schema_conformist_ignored_path?(path)

  assert_schema_conform(status)
end

# in test
test 'GET /products' do
  get products_url, as: :json
end

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

2 participants