-
-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add query param to path even if default value is passed #1239
Add query param to path even if default value is passed #1239
Conversation
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.
Thanks for submitting! These macros are a beast to figure out so am not 100% sure how this is working. Do you think you could leave some comments about what it is doing and what the data looks like?
Also one suggestion to add a spec to make sure the defaults are not included if not given explicitly
spec/lucky/action_spec.cr
Outdated
it "is added to the path even if the value matches default" do | ||
OptionalParams::Index.path(with_default: "default").should eq "/optional_params?with_default=default" | ||
end | ||
|
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.
Could you add a spec for this that makes sure that the default is not shown if not explicitly given? I'm imagining something like this:
it "is added to the path even if the value matches default" do | |
OptionalParams::Index.path(with_default: "default").should eq "/optional_params?with_default=default" | |
end | |
it "is added to the path if the value matches default and is explicitly given" do | |
OptionalParams::Index.path(with_default: "default").should eq "/optional_params?with_default=default" | |
end | |
it "is not added to the path if not explicitly given" do | |
OptionalParams::Index.path(with_default: "default").should eq "/optional_params" | |
end | |
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 great! Thank you :D
Purpose
Fixes #1201
When attempting to get a path, if you happened to pass in a value to a query param that matched the default value, it was not added to the resulting url.
Description
This change removes all references to the default value of a param when building a path.
Here is a comparison of the route method output. It is formatted and has comments removed.
Before
After
Checklist
crystal tool format spec src
./script/setup
./script/test