Skip to content

Set route validation bind context#3227

Merged
hueniverse merged 2 commits into
hapijs:masterfrom
red-0ne:master
Aug 21, 2016
Merged

Set route validation bind context#3227
hueniverse merged 2 commits into
hapijs:masterfrom
red-0ne:master

Conversation

@red-0ne
Copy link
Copy Markdown
Contributor

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

fixes #3226

@red-0ne
Copy link
Copy Markdown
Contributor Author

red-0ne commented Jun 30, 2016

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

@Marsup
Copy link
Copy Markdown
Contributor

Marsup commented Jun 30, 2016

By covering all the possibilities in your tests.

@nlf
Copy link
Copy Markdown
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

Comment thread lib/validation.js

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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