Beta
Basic Router With Named Segments
Loading description...
Data Structures
Regular Expressions
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
Needs true random tests. The current "random" tests just consists of different values of the same route.
Also needs more fixed tests. There is only ever 1 route hash tested for the kata.
The methological and design of the kata is incorrect: segments refer to URL segments, which is the path of the URL further delimited by dashes. Hence a method named
.segments
should not return the named hash, it should return an array of the URL segments. The named segments would be the params captured by the route.Even then, storing the params in the object as a mutable state on
Router
is insane design, because it doesn't belong toRouter
, but specific to a request itself. Instead of returning["CommentsController", :edit]
and storing{ slug: "test-post", id: "12" }
into.segments
the method should really return["CommentsController", :edit, { slug: "test-post", id: "12" }]
(with empty hash ornil
as the third element when no named segments exist). Every MVC framework does this so the action will actually get the params as it is invoked by the framework.Test.expect
should not be used.Took me a bit. but figured it out. thank you!
Thank you for the fun Kata!
The explanation could use a little work. Maybe break down the methods into separate sections.
I also think that the fact that you have to save the
request_info
in an instance variable in theroute?
method is kinda ganky.Thank you! I finally got around to improving the description.
In retrospect, I am guessing that the intention is for the solution to handle various different ROUTES hashes in this format rather than the example ROUTES hash exclusively. If my interpretation is correct, some additional test cases would be beneficial to weed out solutions that do not handle variations.
Yes, indeed the solution should handle any sort of route in that hash. I'll add more varying test cases. Thanks for the feedback!
Cool. Thanks for the fun and engaging kata.
This is fun! I finally got around to improving the description and adding more tests. Thanks!