Skip to content

Commit da7b82c

Browse files
Add notes internal route
Fix breaking test case
1 parent 4986cfb commit da7b82c

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

railties/lib/rails/application/finisher.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def self.complete(_state)
142142
app.routes.prepend do
143143
get "/rails/info/properties" => "rails/info#properties", internal: true
144144
get "/rails/info/routes" => "rails/info#routes", internal: true
145+
get "/rails/info/notes" => "rails/info#notes", internal: true
145146
get "/rails/info" => "rails/info#index", internal: true
146147
end
147148

railties/lib/rails/info_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def routes
3232
end
3333
end
3434

35+
def notes
36+
@annotations = Rails::SourceAnnotationExtractor.new(
37+
Rails::SourceAnnotationExtractor::Annotation.tags.join("|")
38+
).find(
39+
Rails::SourceAnnotationExtractor::Annotation.directories
40+
)
41+
end
42+
3543
private
3644
def matching_routes(query:, exact_match:)
3745
return [] if query.blank?
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<style>
2+
h2, p {
3+
padding-left: 30px;
4+
}
5+
table {
6+
margin: 0;
7+
border-collapse: collapse;
8+
word-wrap:break-word;
9+
table-layout: fixed;
10+
width:100%;
11+
}
12+
table thead tr {
13+
border-bottom: 2px solid #ddd;
14+
}
15+
table th {
16+
padding-left: 30px;
17+
text-align: left;
18+
}
19+
table thead th.tag, table thead th.line-no {
20+
width: 10%;
21+
}
22+
table tbody tr {
23+
border-bottom: 1px solid #ddd;
24+
}
25+
table tbody tr:nth-child(odd) {
26+
background: #f2f2f2;
27+
}
28+
table td {
29+
padding: 4px 30px;
30+
}
31+
@media (prefers-color-scheme: dark) {
32+
table tbody tr:nth-child(odd) {
33+
background: #282828;
34+
}
35+
}
36+
</style>
37+
38+
<h2>
39+
Notes
40+
</h2>
41+
42+
<table id="route_table" class="table">
43+
<thead>
44+
<th>File Name</th>
45+
<th class="line-no">Line No.</th>
46+
<th class="tag">Tag</th>
47+
<th>Description</th>
48+
</thead>
49+
<tbody>
50+
<% @annotations.each do |file, annotations| %>
51+
<% annotations.each.with_index do |annotation, index| %>
52+
<tr>
53+
<% if index == 0 %>
54+
<th rowspan="<%= annotations.size %>">
55+
<%= file %>
56+
</th>
57+
<% end %>
58+
<td class="line-no"><%= annotation.line %></td>
59+
<td class="tag"><%= annotation.tag %></td>
60+
<td><%= annotation.text %></td>
61+
</tr>
62+
<% end %>
63+
<% end %>
64+
</tbody>
65+
</table>

railties/test/rails_info_controller_test.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def setup
1919
end
2020
get "/rails/info/properties" => "rails/info#properties"
2121
get "/rails/info/routes" => "rails/info#routes"
22+
get "/rails/info/notes" => "rails/info#notes"
2223
post "/rails/:test/properties" => "rails/info#properties"
2324
put "/rails/:test/named_properties" => "rails/info#properties", as: "named_rails_info_properties"
2425
end
@@ -118,10 +119,11 @@ def fuzzy_results
118119
assert exact_results.size == 0, "should not case-insensitive match HTTP Verb methods"
119120

120121
get :routes, params: { query: "GET" }
121-
assert exact_results.size == 3, "should match complete HTTP Verb methods"
122+
assert exact_results.size == 4, "should match complete HTTP Verb methods"
122123
assert exact_results.include? "/test/nested_route(.:format)"
123124
assert exact_results.include? "/rails/info/properties(.:format)"
124125
assert exact_results.include? "/rails/info/routes(.:format)"
126+
assert exact_results.include? "/rails/info/notes(.:format)"
125127
end
126128

127129
test "info controller search returns exact matches for route Controller#Action(s)" do
@@ -140,9 +142,10 @@ def fuzzy_results
140142
assert exact_results.size == 0, "should not match unnamed routes"
141143

142144
get :routes, params: { query: "rails_info" }
143-
assert fuzzy_results.size == 3, "should match incomplete route names"
145+
assert fuzzy_results.size == 4, "should match incomplete route names"
144146
assert fuzzy_results.include? "/rails/info/properties(.:format)"
145147
assert fuzzy_results.include? "/rails/info/routes(.:format)"
148+
assert fuzzy_results.include? "/rails/info/notes(.:format)"
146149
assert fuzzy_results.include? "/rails/:test/named_properties(.:format)"
147150

148151
get :routes, params: { query: "/rails/info/routes" }

0 commit comments

Comments
 (0)