schema_conformist
schema_conformist copied to clipboard
assert_schema_conform requires status code explicitly as of committee 4.4.0
As of committee 4.4.0, assert_schema_conform requires HTTP status code explicitly.
Ref. https://github.com/interagent/committee/commit/9a388e5e6a5dfe2e4515b07bba5feaf496c83d4c
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?
Sorry for the late reply. These are my ideas:
- Introduce
:expected_statusor something like that to the kwargs of ProcessWithAssertion#process - Set the return value of
super(i.e. the return value of ActionDispatch::Integration::Session#process) in ProcessWithAssertion#process to the expected return code forassert_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