Add a test for ActionDispatch::underscore

This shows how the predicate behaves, as well as a case where it goes
wrong.
This commit is contained in:
Harry Maclean
2021-11-19 16:05:02 +00:00
committed by Harry Maclean
parent 9c67869875
commit fa28e55645
2 changed files with 18 additions and 0 deletions

View File

@@ -38,3 +38,13 @@ actionDispatchControllerMethods
| app/config/routes.rb:28:3:28:50 | call to match | app/controllers/photos_controller.rb:2:3:3:5 | show |
| app/config/routes.rb:29:3:29:69 | call to match | app/controllers/photos_controller.rb:2:3:3:5 | show |
| app/config/routes.rb:49:5:49:94 | call to post | app/controllers/users/notifications_controller.rb:3:5:4:7 | mark_as_read |
underscore
| Foo | foo |
| Foo::Bar | foo/bar |
| Foo::Bar::Baz | foo/bar/baz |
| Foo::Bar::BazQuux | foo/bar/baz_quux |
| FooBar | foo_bar |
| FooBar::Baz | foo_bar/baz |
| HTTPServerRequest | h_tT_p_server_request |
| LotsOfCapitalLetters | lots_of_capital_letters |
| invalid | invalid |

View File

@@ -16,3 +16,11 @@ query predicate actionDispatchControllerMethods(
) {
m.getARoute() = r
}
query predicate underscore(string input, string output) {
output = ActionDispatch::underscore(input) and
input in [
"Foo", "FooBar", "Foo::Bar", "FooBar::Baz", "Foo::Bar::Baz", "Foo::Bar::BazQuux", "invalid",
"HTTPServerRequest", "LotsOfCapitalLetters"
]
}