Skip to content

Commit fa28e55

Browse files
committed
Add a test for ActionDispatch::underscore
This shows how the predicate behaves, as well as a case where it goes wrong.
1 parent 9c67869 commit fa28e55

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ruby/ql/test/library-tests/frameworks/ActionDispatch.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ actionDispatchControllerMethods
3838
| app/config/routes.rb:28:3:28:50 | call to match | app/controllers/photos_controller.rb:2:3:3:5 | show |
3939
| app/config/routes.rb:29:3:29:69 | call to match | app/controllers/photos_controller.rb:2:3:3:5 | show |
4040
| app/config/routes.rb:49:5:49:94 | call to post | app/controllers/users/notifications_controller.rb:3:5:4:7 | mark_as_read |
41+
underscore
42+
| Foo | foo |
43+
| Foo::Bar | foo/bar |
44+
| Foo::Bar::Baz | foo/bar/baz |
45+
| Foo::Bar::BazQuux | foo/bar/baz_quux |
46+
| FooBar | foo_bar |
47+
| FooBar::Baz | foo_bar/baz |
48+
| HTTPServerRequest | h_tT_p_server_request |
49+
| LotsOfCapitalLetters | lots_of_capital_letters |
50+
| invalid | invalid |

ruby/ql/test/library-tests/frameworks/ActionDispatch.ql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ query predicate actionDispatchControllerMethods(
1616
) {
1717
m.getARoute() = r
1818
}
19+
20+
query predicate underscore(string input, string output) {
21+
output = ActionDispatch::underscore(input) and
22+
input in [
23+
"Foo", "FooBar", "Foo::Bar", "FooBar::Baz", "Foo::Bar::Baz", "Foo::Bar::BazQuux", "invalid",
24+
"HTTPServerRequest", "LotsOfCapitalLetters"
25+
]
26+
}

0 commit comments

Comments
 (0)