Skip to content
Open
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
38 changes: 26 additions & 12 deletions spec/lib/tasks/for_education_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

require 'rails_helper'
require 'rake'
require 'climate_control'
require 'securerandom'

RSpec.describe 'for_education', type: :task do
let(:creator_id) { '583ba872-b16e-46e1-9f7d-df89d267550d' } # [email protected]
let(:teacher_id) { 'bbb9b8fd-f357-4238-983d-6f87b99bdbb2' } # [email protected]
let(:student_1) { 'e52de409-9210-4e94-b08c-dd11439e07d9' } # student
let(:student_2) { '0d488bec-b10d-46d3-b6f3-4cddf5d90c71' } # student
let(:school_id) { 'e52de409-9210-4e94-b08c-dd11439e07d9' }
before do
# Ensure the school id is unique, to avoid conflicts
stub_const('SeedsHelper::TEST_SCHOOL', school_id)
end
Comment on lines +9 to +12
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The before hook at the top level will execute for all test contexts, but school_id is defined using let which is lazily evaluated. This can cause issues with RSpec's evaluation order. Consider using let! for school_id to ensure it's evaluated before the before hook, or move the stub_const into individual test contexts where school_id is actually used.

Copilot uses AI. Check for mistakes.

let(:creator_id) { 'f83ba872-b16e-46e1-9f7d-df89d267550d' }
let(:teacher_id) { 'ccc9b8fd-f357-4238-983d-6f87b99bdbb2' }
Comment on lines +14 to +15
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded UUIDs for creator_id and teacher_id do not match the actual TEST_USERS values from SeedsHelper (which uses 583ba872-b16e-46e1-9f7d-df89d267550d for jane_doe and bbb9b8fd-f357-4238-983d-6f87b99bdbb2 for john_doe). Consider using the actual SeedsHelper::TEST_USERS values or documenting why different UUIDs are being used for testing.

Suggested change
let(:creator_id) { 'f83ba872-b16e-46e1-9f7d-df89d267550d' }
let(:teacher_id) { 'ccc9b8fd-f357-4238-983d-6f87b99bdbb2' }
let(:creator_id) { '583ba872-b16e-46e1-9f7d-df89d267550d' } # jane_doe from SeedsHelper
let(:teacher_id) { 'bbb9b8fd-f357-4238-983d-6f87b99bdbb2' } # john_doe from SeedsHelper

Copilot uses AI. Check for mistakes.
let(:student_1) { 'e52de409-9210-4e94-b08c-dd11439e07d9' } # jane.smith from SeedsHelper
let(:student_2) { '0d488bec-b10d-46d3-b6f3-4cddf5d90c71' } # john.smith from SeedsHelper
let(:school_id) { SecureRandom.uuid }

describe ':destroy_seed_data' do
let(:task) { Rake::Task['for_education:destroy_seed_data'] }
Expand All @@ -24,7 +31,9 @@
end

it 'destroys all seed data' do
task.invoke
ClimateControl.modify SEEDING_CREATOR_ID: creator_id, SEEDING_TEACHER_ID: teacher_id do
task.invoke
end
Comment on lines +34 to +36
Copy link
Contributor

@loiswells97 loiswells97 Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean these values weren't getting picked up before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they were getting picked up, but state was bleeding between tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand how this fixes the bleed in that case 🤔

expect(Role.where(user_id: [creator_id, teacher_id, student_1, student_2])).not_to exist
expect(School.where(creator_id:)).not_to exist
expect(ClassStudent.where(student_id: student_1)).not_to exist
Expand All @@ -39,7 +48,9 @@
let(:task) { Rake::Task['for_education:seed_an_unverified_school'] }

it 'creates an unverified school' do
task.invoke
ClimateControl.modify SEEDING_CREATOR_ID: creator_id do
task.invoke
end
expect(School.find_by(creator_id:).verified_at).to be_nil
end
end
Expand All @@ -48,7 +59,9 @@
let(:task) { Rake::Task['for_education:seed_a_verified_school'] }

it 'creates a verified school' do
task.invoke
ClimateControl.modify SEEDING_CREATOR_ID: creator_id do
task.invoke
end
expect(School.find_by(creator_id:).verified_at).to be_truthy
end
end
Expand All @@ -58,8 +71,9 @@
let(:school) { School.find_by(creator_id:) }

before do
Rake::Task['for_education:destroy_seed_data'].invoke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this no longer needed? Or was it never needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't have been needed, given DatabaseCleaner cleans the db between runs...but I think the concurrency was the prob...using unique ids fixes that

task.invoke
ClimateControl.modify SEEDING_CREATOR_ID: creator_id, SEEDING_TEACHER_ID: teacher_id do
task.invoke
end
end

it 'creates a verified school' do
Expand All @@ -71,8 +85,8 @@
end

it 'adds two lessons to the school' do
lesson = Lesson.where(school_id: school.id)
expect(lesson.length).to eq(2)
lessons = Lesson.where(school_id: school.id)
expect(lessons.count).to eq(2)
end

it 'adds two projects' do
Expand Down
Loading