-
Notifications
You must be signed in to change notification settings - Fork 4
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
Ensure the validator can handle the payload being JSON #68
Ensure the validator can handle the payload being JSON #68
Conversation
5f6ada0
to
f4f69f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work 👍🏻
A couple of thoughts.
lib/govuk_schemas/validator.rb
Outdated
@payload = payload | ||
ensure_payload_is_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nicer to implement this as a method which returns a JSON string – rather than a method with side effects.
e.g.
@payload = payload | |
ensure_payload_is_json | |
@payload = ensure_json(payload) |
It feels a bit weird to be setting @payload
and then immediately updating it in ensure_payload_is_json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm yea i think that's a good shout actually. Will update now 👍
lib/govuk_schemas/version.rb
Outdated
@@ -1,4 +1,4 @@ | |||
module GovukSchemas | |||
# @private | |||
VERSION = "4.4.0".freeze | |||
VERSION = "4.5.0".freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is more suited to being a patch release rather than a minor release. It seems like this is a bug-fix rather than a new feature. 🤔
VERSION = "4.5.0".freeze | |
VERSION = "4.4.1".freeze |
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea good shout. Will update 👍
At the moment, there's some disparity between how applications that user Minitest and applications that use RSpec pass their payloads. RSpec applications pass the payload as JSON and Minitest applications pass it as a Hash. Currently, the payload is being converted to JSON before being validated by `JSON.fully_validate`. If the object is already JSON then .to_json is called again. This means when JSON.parse is called on the object it does not convert it back to a hash. This commit updates the validator to ensure that the payload is converted to JSON if the object passed is not a string.
f4f69f7
to
72e1e6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍🏻
Description
At the moment, there's some disparity between how applications that user Minitest and applications that use RSpec pass their payloads.
RSpec applications pass the payload as JSON and Minitest applications pass it as a Hash.
Currently, the payload is being converted to JSON before being validated by
JSON.fully_validate
. If the object is already JSON then .to_json is called again. This means when JSON.parse is called withinJSON.fully_validate
on the payload it does not convert it to a hash.This commit updates the validator to ensure that the payload not converted to JSON if it is already a string.
Trello card
https://trello.com/c/Q9O5rXnz/550-stop-using-the-deprecated-govuk-content-schema-test-helpers-gem