nshki / chusaku

Annotate your Rails controllers with route info.
https://rubygems.org/gems/chusaku
MIT License
87 stars 4 forks source link

Missing route name on aliased CRUD actions #34

Closed vlad-pisanov closed 11 months ago

vlad-pisanov commented 11 months ago

Consider this routing (update is aliased as change):

resources :invitations do
  collection do
    put :update, as: :change
  end
end

Chusaku annotates the update action like so (change_invitation is present, but the standard invitation is missing):

# @route PUT /invitations (change_invitations)
# @route PATCH /invitations/:id
# @route PUT /invitations/:id
def update; end

Strangely, if I change it to resources :invitations, only: [:update], everything works as expected: 🤔

# @route PUT /invitations (change_invitations)
# @route PATCH /invitations/:id (invitation)
# @route PUT /invitations/:id (invitation)
def update; end
nshki commented 11 months ago

Thanks for reporting this, @vlad-pisanov! I was able to reproduce what you described, and it does indeed seem to be a bug. I'll spend more time on this and will keep this thread updated.

nshki commented 11 months ago

@vlad-pisanov would you mind giving this potential fix a try?

  1. Change your Gemfile so you're temporarily pointing to the fix branch:

      gem "chusaku", git: "https://github.com/nshki/chusaku.git", branch: "fix/missing-route-names", require: false
  2. Run bundle install.
  3. Run bundle exec chusaku.

Does that give expected output?

vlad-pisanov commented 11 months ago

@nshki it works! 🙌 No regressions either (tested on a very large codebase with thousands of routes)

nshki commented 11 months ago

Fantastic! Thanks for verifying. 😄 Will be releasing a patch shortly!