Skip to content

Commit c73e3df

Browse files
feat: show module links and games in order on the student home
Students see each module's contents through a single ordered list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 62d96a6 commit c73e3df

6 files changed

Lines changed: 35 additions & 13 deletions

File tree

‎app/controllers/student_homes_controller.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def index
99
.order("programs.name")
1010
@active_program = @classroom_programs.find { |cp| cp.id.to_s == params[:classroom_program_id] } || @classroom_programs.first
1111
@published_modules = if @active_program
12-
@active_program.classroom_modules.published.includes(content_module: :links)
12+
@active_program.classroom_modules.published.includes(content_module: { contents: :contentable })
1313
else
1414
[]
1515
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<%# locals: (content:) %>
2+
<li>
3+
<%= render "student_homes/contentables/#{content.contentable_name}", contentable: content.contentable %>
4+
</li>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<%# locals: (contentable:) %>
2+
<%= link_to contentable.title, play_game_path(contentable), class: "link inline-flex items-center gap-1" %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%# locals: (contentable:) %>
2+
<%= link_to "#{contentable.title} ↗", safe_external_url(contentable.url),
3+
target: "_blank", rel: "noopener noreferrer", class: "link inline-flex items-center gap-1" %>

‎app/views/student_homes/index.html.erb‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@
3030
</summary>
3131
<div class="collapse-content">
3232
<ul class="flex flex-col gap-2 pt-2">
33-
<% classroom_module.content_module.links.each do |link| %>
34-
<li>
35-
<%= tag.a link.title + " ↗",
36-
href: safe_external_url(link.url),
37-
target: "_blank",
38-
rel: "noopener noreferrer",
39-
class: "link inline-flex items-center gap-1" %>
40-
</li>
41-
<% end %>
33+
<%= render partial: "student_homes/content", collection: classroom_module.content_module.contents %>
4234
</ul>
4335
</div>
4436
<% end %>

‎test/controllers/student_homes_controller_test.rb‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest
1818
assert_select "summary", text: /Introduction to Health/
1919
end
2020

21-
test "shows links inside published modules" do
21+
test "links open in a new tab" do
2222
get student_homes_url
2323
assert_response :success
24-
link = content_modules(:one).links.first
25-
assert_select "a[target='_blank']", text: /#{link.title}/ if link
24+
assert_select "li a[href='#{links(:one).url}'][target='_blank'][rel='noopener noreferrer']", text: /#{links(:one).title}/
25+
end
26+
27+
test "games link to the play page in the same tab" do
28+
get student_homes_url
29+
assert_response :success
30+
assert_select "li a[href='#{play_game_path(games(:one))}']:not([target])", text: games(:one).title
31+
end
32+
33+
test "shows contents in position order" do
34+
contents(:one).update!(position: 2)
35+
contents(:two).update!(position: 1)
36+
37+
get student_homes_url
38+
titles = listed_titles
39+
assert_operator titles.index(links(:one).title), :<, titles.index(games(:one).title)
2640
end
2741

2842
test "most recently published module has the open attribute" do
@@ -79,4 +93,11 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest
7993
get student_homes_url(classroom_program_id: enrollment.id)
8094
assert_select "a[role='tab'][aria-selected='true'][href*='classroom_program_id=#{enrollment.id}']"
8195
end
96+
97+
private
98+
99+
# The " ↗" suffix marks external links, so strip it to compare plain titles.
100+
def listed_titles
101+
css_select("details li a").map { |a| a.text.delete_suffix(" ↗") }
102+
end
82103
end

0 commit comments

Comments
 (0)