rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Routing: custom `param` option for `resources` DSL does not apply to statements in block #510

Closed jas14 closed 3 years ago

jas14 commented 4 years ago

Checklist

My Environment

Software Version
Operating System macOS 10.15.5 (Catalina)
Jets 2.3.16
Ruby 2.5.7, 2.5.8

Expected Behaviour

I expect the following route definition:

resources :test, only: [], param: :my_param do
  get :somewhere, on: :member
end

to produce the following routing table:

+----------------+------+-------------------------+-------------------+
|       As       | Verb |          Path           | Controller#action |
+----------------+------+-------------------------+-------------------+
| somewhere_test | GET  | test/:my_param/somewhere | test#somewhere    |
+----------------+------+-------------------------+-------------------+

Current Behavior

The above route definition produces:

+----------------+------+-------------------------+-------------------+
|       As       | Verb |          Path           | Controller#action |
+----------------+------+-------------------------+-------------------+
| somewhere_test | GET  | test/:test_id/somewhere | test#somewhere    |
+----------------+------+-------------------------+-------------------+

The path param is named :test_id instead of :my_param.

Step-by-step reproduction instructions

  1. Create a new Jets project and overwrite config/routes.rb with the sample below.
  2. bundle exec jets routes
  3. Observe the incorrect route

Code Sample

# config/routes.rb
Jets.application.routes.draw do
  resources :test, param: :my_param, only: [] do
    get :somewhere, on: :member
  end
end

I'm happy to also provide a patch to spec/lib/jets/router_spec.rb to easily and quickly reproduce the problem.

jas14 commented 4 years ago

I'm considering adding :param to scope options so we can refer to it in Jets::Router::Scope#full_prefix. Any objections?