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

Set route validation bind context #3227

Merged
merged 2 commits into from Aug 21, 2016
Merged

Set route validation bind context #3227

merged 2 commits into from Aug 21, 2016

Conversation

red-0ne
Copy link
Contributor

@red-0ne red-0ne commented Jun 30, 2016

fixes #3226

@red-0ne
Copy link
Contributor Author

red-0ne commented Jun 30, 2016

How can I fix lib/validation.js missing coverage on line(s): 142 ?

@Marsup
Copy link
Contributor

Marsup commented Jun 30, 2016

By covering all the possibilities in your tests.

@nlf
Copy link
Member

nlf commented Jun 30, 2016

so that line looks like this:

const bind = request.route.settings.bind || request.route.realm || null;

in order to get full coverage, you need tests where request.route.settings.bind are both truthy and falsey, likewise for request.route.realm. think of it like making sure you can actually reach that final || null

@@ -139,7 +139,8 @@ internals.input = function (source, request, next) {

request._protect.run(postValidate, (exit) => {

return schema(request[source], localOptions, exit);
const bind = request.route.settings.bind || request.route.realm || null;
return schema.call(bind, request[source], localOptions, exit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want call on hot code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call and apply are not slower than bound functions last time I checked, how would you do it ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the whole framework so you always pass a context object rather than relying on this 😄

But seriously, yeah there really isn't a way to do that other than call here.

remove unreachable condition when realm is falsy
@hueniverse hueniverse changed the title fix provide context to route custom validator Set route validation bind context Aug 21, 2016
@hueniverse hueniverse added the bug Bug or defect label Aug 21, 2016
@hueniverse hueniverse added this to the 15.0.0 milestone Aug 21, 2016
@hueniverse hueniverse self-assigned this Aug 21, 2016
@hueniverse hueniverse merged commit bfce5d4 into hapijs:master Aug 21, 2016
hueniverse added a commit that referenced this pull request Aug 21, 2016
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bound context is not available in route validation function:
5 participants