Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ There are 2 separate sets of models using authentication:
- Students (non-traditional Magic Links) used for Students to access their specific content

## Skills

- Look in the [Skills](./skills) Folder for relevant skills
- [rails-test-fixtures-conventions](./skills/rails-test-fixtures-conventions.md)
- [erb-templates-conventions](./skills/erb-templates-conventions.md)

## Conventions

Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions skills/rails-test-fixtures-conventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Rails Test Fixtures

Goal: keep fixtures few. Too many fixtures = nobody understands the dependency graph.

## Rules

1. **1-2 fixtures per model max**
- Name them `:one` and `:two`
- Plain, valid, boring attributes
- Minimal dependencies
- Add `:two` only to compare two records

2. **Customize in the test, not the fixture**
- `developers(:one).update!(field: value)`
- Only set the field the test cares about
- Extra DB write is fine, readability wins

3. **Use a custom helper method for when needed**
- Create a method like `create_thing` that allows customizing attributes

4. **New named fixture = last resort**
- Only for deep/complex required associations
- Give it a real name, not `:three` (e.g. `:paying_customer`)
- Max 1-2 per model
2 changes: 1 addition & 1 deletion test/controllers/classroom_modules_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ClassroomModulesControllerTest < ActionDispatch::IntegrationTest
setup do
@classroom_module = classroom_modules(:one)
sign_in_as users(:admin)
sign_in_as users(:one)
end

test "update sets publish_on and responds with turbo stream" do
Expand Down
18 changes: 9 additions & 9 deletions test/controllers/classrooms_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ClassroomsControllerTest < ActionDispatch::IntegrationTest
setup do
@classroom = classrooms(:one)
sign_in_as users(:admin)
sign_in_as users(:one)
end

test "should get edit" do
Expand All @@ -27,7 +27,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest
end

test "should add a program enrollment" do
program = programs(:"3dw")
program = programs(:two)

assert_difference "ClassroomProgram.count" do
patch classroom_url(@classroom), params: {
Expand Down Expand Up @@ -59,7 +59,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest

test "should remove an enrollment" do
enrollment = classroom_programs(:one)
@classroom.classroom_programs.create!(program: programs(:"3dw"), level: "basic")
@classroom.classroom_programs.create!(program: programs(:two), level: "basic")

assert_difference "ClassroomProgram.count", -1 do
patch classroom_url(@classroom), params: {
Expand Down Expand Up @@ -89,7 +89,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest
end

test "is invalid when a program is selected without a level" do
program = programs(:"3dw")
program = programs(:two)

assert_no_difference "ClassroomProgram.count" do
patch classroom_url(@classroom), params: {
Expand All @@ -104,7 +104,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest
end

test "generates modules when a new enrollment is added" do
program = programs(:"3dw")
program = programs(:two)

assert_difference "ClassroomModule.count" do
patch classroom_url(@classroom), params: {
Expand All @@ -116,7 +116,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest
end

cp = @classroom.classroom_programs.find_by!(program: program)
assert cp.classroom_modules.exists?(content_module: content_modules(:moderate_wellness))
assert cp.classroom_modules.exists?(content_module: content_modules(:two))
end

test "is invalid when changing a level that has scheduled modules" do
Expand Down Expand Up @@ -159,7 +159,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest

test "should create classroom" do
school = schools(:one)
program = programs(:kyh)
program = programs(:one)
teacher = Teacher.create!(name: "Teacher 3", school: school)

assert_difference "Classroom.count" do
Expand All @@ -185,7 +185,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest
post school_classrooms_url(school), params: {
classroom: {
name: "Classroom 4",
classroom_programs_attributes: [ { program_id: programs(:kyh).id, level: "basic" } ]
classroom_programs_attributes: [ { program_id: programs(:one).id, level: "basic" } ]
}
}

Expand All @@ -201,7 +201,7 @@ class ClassroomsControllerTest < ActionDispatch::IntegrationTest
post school_classrooms_url(school), params: {
classroom: {
name: "Classroom 5",
classroom_programs_attributes: [ { program_id: programs(:kyh).id, level: "basic" } ]
classroom_programs_attributes: [ { program_id: programs(:one).id, level: "basic" } ]
}
}
end
Expand Down
12 changes: 6 additions & 6 deletions test/controllers/content_modules_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class ContentModulesControllerTest < ActionDispatch::IntegrationTest
setup do
@content_module = content_modules(:intro)
sign_in_as users(:admin)
@content_module = content_modules(:one)
sign_in_as users(:one)
end

test "should get index" do
Expand All @@ -12,7 +12,7 @@ class ContentModulesControllerTest < ActionDispatch::IntegrationTest
end

test "index marks the active program tab as selected" do
program = programs(:kyh)
program = programs(:one)
get content_modules_url(program_id: program.id)
assert_select "a[role='tab'][aria-selected='true'][href*='program_id=#{program.id}']"
end
Expand All @@ -25,7 +25,7 @@ class ContentModulesControllerTest < ActionDispatch::IntegrationTest
test "should create content module" do
assert_difference "ContentModule.count" do
post content_modules_url, params: {
content_module: { name: "New Module", program_id: programs(:kyh).id, level: "moderate", position: 1 }
content_module: { name: "New Module", program_id: programs(:one).id, level: "moderate", position: 1 }
}
end
assert_redirected_to content_modules_url
Expand All @@ -34,7 +34,7 @@ class ContentModulesControllerTest < ActionDispatch::IntegrationTest
test "should not create with missing name" do
assert_no_difference "ContentModule.count" do
post content_modules_url, params: {
content_module: { name: "", program_id: programs(:kyh).id, level: "basic" }
content_module: { name: "", program_id: programs(:one).id, level: "basic" }
}
end
assert_response :unprocessable_entity
Expand Down Expand Up @@ -65,7 +65,7 @@ class ContentModulesControllerTest < ActionDispatch::IntegrationTest
end

test "should destroy content module" do
content_module = ContentModule.create!(program: programs(:kyh), level: "basic", name: "To Delete")
content_module = ContentModule.create!(program: programs(:one), level: "basic", name: "To Delete")
assert_difference "ContentModule.count", -1 do
delete content_module_url(content_module)
end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/games_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class GamesControllerTest < ActionDispatch::IntegrationTest
setup do
@game = games(:one)
@content_module = content_modules(:intro)
sign_in_as users(:admin)
@content_module = content_modules(:one)
sign_in_as users(:one)
end

test "should get index" do
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/links_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class LinksControllerTest < ActionDispatch::IntegrationTest
setup do
@link = links(:survey_one)
@mod = content_modules(:intro)
sign_in_as users(:admin)
@link = links(:one)
@mod = content_modules(:one)
sign_in_as users(:one)
end

test "should get new" do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/schools_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class SchoolsControllerTest < ActionDispatch::IntegrationTest
setup do
@school = schools(:one)
sign_in_as users(:admin)
sign_in_as users(:one)
end

test "should get index" do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"

class SessionsControllerTest < ActionDispatch::IntegrationTest
setup { @user = users(:admin) }
setup { @user = users(:one) }

test "new" do
get new_session_path
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/student_home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class StudentHomeControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
student_sign_in_as(students(:ada))
student_sign_in_as(students(:one))

get student_homes_path
assert_response :success
Expand Down
12 changes: 6 additions & 6 deletions test/controllers/student_homes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class StudentHomesControllerTest < ActionDispatch::IntegrationTest
setup do
@student = students(:ada)
@student = students(:one)
student_sign_in_as @student
end

Expand All @@ -21,14 +21,14 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest
test "shows links inside published modules" do
get student_homes_url
assert_response :success
link = content_modules(:intro).links.first
link = content_modules(:one).links.first
assert_select "a[target='_blank']", text: /#{link.title}/ if link
end

test "most recently published module has the open attribute" do
# Add a second published module so there's a distinct "most recent"
second_module = ContentModule.create!(
program: programs(:kyh), level: "basic", name: "Second Module", position: 2
program: programs(:one), level: "basic", name: "Second Module", position: 2
)
classroom_programs(:one).classroom_modules.create!(
content_module: second_module, publish_on: Date.current
Expand All @@ -40,7 +40,7 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest

test "all modules published on the same latest date have the open attribute" do
second_module = ContentModule.create!(
program: programs(:kyh), level: "basic", name: "Second Module", position: 2
program: programs(:one), level: "basic", name: "Second Module", position: 2
)
classroom_modules(:one).update!(publish_on: Date.current)
classroom_programs(:one).classroom_modules.create!(
Expand All @@ -64,7 +64,7 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest

test "shows tab bar when classroom has multiple program enrollments" do
classroom_programs(:one).classroom.classroom_programs.create!(
program: programs(:"3dw"), level: "moderate"
program: programs(:two), level: "moderate"
)

get student_homes_url
Expand All @@ -74,7 +74,7 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest

test "tab switching shows the selected program as active" do
enrollment = classroom_programs(:one)
enrollment.classroom.classroom_programs.create!(program: programs(:"3dw"), level: "moderate")
enrollment.classroom.classroom_programs.create!(program: programs(:two), level: "moderate")

get student_homes_url(classroom_program_id: enrollment.id)
assert_select "a[role='tab'][aria-selected='true'][href*='classroom_program_id=#{enrollment.id}']"
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/student_sessions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"

class StudentSessionsControllerTest < ActionDispatch::IntegrationTest
setup { @student = students(:ada) }
setup { @student = students(:one) }

test "new" do
get new_student_session_path
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/students_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class StudentsControllerTest < ActionDispatch::IntegrationTest
setup do
@school = schools(:one)
@student = students(:ada)
sign_in_as users(:admin)
@student = students(:one)
sign_in_as users(:one)
end

test "should get index" do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/teachers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class TeachersControllerTest < ActionDispatch::IntegrationTest
setup do
@school = schools(:one)
sign_in_as users(:admin)
sign_in_as users(:one)
end

test "should get index" do
Expand Down
7 changes: 1 addition & 6 deletions test/fixtures/classroom_modules.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
one:
classroom_program: one
content_module: intro
publish_on: 2026-05-01

scheduled:
classroom_program: two
content_module: moderate_wellness
content_module: one
publish_on: 2026-05-01
4 changes: 2 additions & 2 deletions test/fixtures/classroom_programs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
one:
classroom: one
program: kyh
program: one
level: basic

two:
classroom: two
program: 3dw
program: two
level: moderate
14 changes: 4 additions & 10 deletions test/fixtures/content_modules.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
intro:
program: kyh
one:
program: one
level: basic
name: Introduction to Health
position: 1

moderate_wellness:
program: 3dw
two:
program: two
level: moderate
name: Moderate Wellness
position: 1

advanced_wellness:
program: 3dw
level: advanced
name: Advanced Wellness
position: 1
4 changes: 2 additions & 2 deletions test/fixtures/game_attempts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ one:
outcome: completed
started_at: 2026-08-29 11:53:38
finished_at: 2026-08-29 11:53:38
student: ada
student: one
game: one
token: onetoken

Expand All @@ -14,6 +14,6 @@ two:
outcome: expired
started_at: 2026-08-29 11:53:38
finished_at: 2026-08-29 11:53:38
student: grace
student: two
game: two
token: twotoken
4 changes: 2 additions & 2 deletions test/fixtures/games.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
one:
title: Game 1
slug: game-1
content_module: intro
content_module: one
description: MyText

two:
title: Game 2
slug: game-2
content_module: moderate_wellness
content_module: one
description: MyText
11 changes: 2 additions & 9 deletions test/fixtures/links.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
survey_one:
content_module: intro
one:
content_module: one
title: Health Survey
url: https://example.com/survey/1
link_type: survey
position: 1

survey_two:
content_module: intro
title: Health Survey 2
url: https://example.com/survey/2
link_type: survey
position: 2
Loading