Add singular resource routing and specs#247
Conversation
rsamoilov
left a comment
There was a problem hiding this comment.
Hi @anuj-pal27,
Left several comments. Apart from that, looks good 👍
| return | ||
| end | ||
|
|
||
| _module, _path, _only, _except, _param = opts.values_at(:module, :path, :only, :except, :param) |
There was a problem hiding this comment.
_param doesn't seem to be used in this method.
There was a problem hiding this comment.
Thanks for the review! You're right, I'll remove _param from the values_at call since singular resources don't use a param in the URL.
|
|
||
| resource = _resources[0].to_s | ||
| __resource_scope(resource, _path, _module) do | ||
| get("/new", to: "#{resource}#new") if actions.include?(:new) |
There was a problem hiding this comment.
Do we actually need the new route? I'm not so sure.
There was a problem hiding this comment.
I added it based on the issue description which mentioned the /new route. I don’t think we need the new route here. Rage is API-only and resources already doesn’t generate new/edit, so generating GET /resource/new would be inconsistent and mostly useful for HTML form flows. I’ll remove :new from the default actions and drop the /new route.
| get("/new", to: "#{resource}#new") if actions.include?(:new) | ||
| post("/", to: "#{resource}#create") if actions.include?(:create) | ||
| get("/", to: "#{resource}#show") if actions.include?(:show) | ||
| patch("/", to: "#{resource}#update") if actions.include?(:update) | ||
| put("/", to: "#{resource}#update") if actions.include?(:update) | ||
| delete("/", to: "#{resource}#destroy") if actions.include?(:destroy) |
There was a problem hiding this comment.
We need to ensure resource is pluralised here - Rails maps singular resources to plural controllers.
You can use to_singular as a reference when implementing this. Feel free to keep it simple - Active Support is almost always loaded.
Summary
Implements the singular resource route helper in the router DSL and updates the spec suite to validate all supported options and behaviors.
Changes
Testing
fix #119