Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow path => controller#action in Routes #102

Merged
merged 1 commit into from
Aug 8, 2019

Conversation

panthomakos
Copy link
Contributor

The 'path' => 'controller#action' is a supported short-hand syntax
for Rails routes as documented here. The current type is too
restrictive and does not support this valid syntax. This change modifies
the first argument type so that it supports the Hash syntax.

@panthomakos panthomakos requested a review from a team August 6, 2019 16:03
@ghost ghost requested review from DarkDimius and removed request for a team August 6, 2019 16:03
@panthomakos
Copy link
Contributor Author

Might be worth considering adding a test-suite for some of these routes. For example, a simple routes.rb file with some variations that could be type-checked.

@connorshea
Copy link
Contributor

Yup, that's what #42 is for. Though I suppose we could still have files that use the library and make sure all valid input is allowed 🤔 That shouldn't be as hard as porting the test harness over to this repo.

The `'path' => 'controller#action'` is a supported short-hand syntax
for Rails routes as documented [here][1]. The current type is too
restrictive and does not support this valid syntax. This change modifies
the first argument type so that it supports the Hash syntax.

[1]: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb#L1605
@panthomakos
Copy link
Contributor Author

I rebased on master and included tests that fail before the change:

lib/actionpack/test/actionpack_test.rb:40: Expected T.any(String, Symbol) but found {String("about") => String("static_pages#about")} for argument name https://srb.help/7002
    40 |  get 'about' => 'static_pages#about'
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    lib/actionpack/all/actionpack.rbi:151: Method ActionDispatch::Routing::Mapper::HttpHelpers#get has specified name as T.any(String, Symbol)
     151 |      name: T.any(String, Symbol),
                ^^^^
  Got {String("about") => String("static_pages#about")} originating from:
    lib/actionpack/test/actionpack_test.rb:40:
    40 |  get 'about' => 'static_pages#about'
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 1

Copy link
Collaborator

@DarkDimius DarkDimius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for the tests!

@DarkDimius DarkDimius merged commit 0d1d348 into sorbet:master Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants