From 234d910ee168013e10978a5dba3b55c5d79149de Mon Sep 17 00:00:00 2001 From: Jamie Benstead Date: Tue, 25 Aug 2026 13:46:53 +0100 Subject: [PATCH] Return the project locale on lesson JSON Lets callers confirm which locale a lesson's project was created in. --- app/views/api/lessons/_lesson.json.jbuilder | 3 ++- .../creating_a_batch_of_lessons_spec.rb | 27 +++++++++++++++++++ spec/features/lesson/listing_lessons_spec.rb | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/views/api/lessons/_lesson.json.jbuilder b/app/views/api/lessons/_lesson.json.jbuilder index c46dc21dc..1f01ca81e 100644 --- a/app/views/api/lessons/_lesson.json.jbuilder +++ b/app/views/api/lessons/_lesson.json.jbuilder @@ -19,7 +19,8 @@ if lesson.project json.project( lesson.project, :identifier, - :project_type + :project_type, + :locale ) end diff --git a/spec/features/lesson/creating_a_batch_of_lessons_spec.rb b/spec/features/lesson/creating_a_batch_of_lessons_spec.rb index bead3a881..25da08862 100644 --- a/spec/features/lesson/creating_a_batch_of_lessons_spec.rb +++ b/spec/features/lesson/creating_a_batch_of_lessons_spec.rb @@ -75,6 +75,33 @@ end end + context 'when a locale is supplied for each project' do + let(:lesson_project_params) do + [ + { + name: 'Lesson 1', + school_id: school.id, + project_attributes: { name: 'Project 1', project_type: Project::Types::CODE_EDITOR_SCRATCH, locale: 'fr-FR' } + }, + { + name: 'Lesson 2', + school_id: school.id, + project_attributes: { name: 'Project 2', project_type: Project::Types::CODE_EDITOR_SCRATCH, locale: 'fr-FR' } + } + ] + end + + it 'persists the locale on each created project' do + expect(Project.where(locale: 'fr-FR').count).to eq(2) + end + + it 'returns the locale on each project so callers can confirm it' do + data = JSON.parse(response.body, symbolize_names: true) + + expect(data.map { |entry| entry.dig(:project, :locale) }).to all(eq('fr-FR')) + end + end + context 'when some entries are invalid' do let(:lesson_projects) do lesson_project_params + [{ diff --git a/spec/features/lesson/listing_lessons_spec.rb b/spec/features/lesson/listing_lessons_spec.rb index 625f2699f..399d2ef6c 100644 --- a/spec/features/lesson/listing_lessons_spec.rb +++ b/spec/features/lesson/listing_lessons_spec.rb @@ -45,7 +45,7 @@ it 'responds with the project JSON' do get('/api/lessons', headers:) data = JSON.parse(response.body, symbolize_names: true) - expected_project = JSON.parse(lesson.project.to_json(only: %i[identifier project_type]), symbolize_names: true) + expected_project = JSON.parse(lesson.project.to_json(only: %i[identifier project_type locale]), symbolize_names: true) expect(data.first[:project]).to eq(expected_project) end