Skip to content
Merged
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
18 changes: 12 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.18.1)
json (2.19.2)
json-schema (6.2.0)
addressable (~> 2.8)
bigdecimal (>= 3.1, < 5)
jwt (2.2.3)
kaminari (1.2.2)
activesupport (>= 4.1.0)
Expand All @@ -280,6 +283,8 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.3)
mcp (0.8.0)
json-schema (>= 4.1)
method_source (1.1.0)
mini_magick (5.3.1)
logger
Expand Down Expand Up @@ -455,18 +460,19 @@ GEM
rspec-support (3.13.7)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.80.1)
rubocop (1.85.1)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
mcp (~> 0.6)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.46.0, < 2.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.0)
rubocop-ast (1.49.1)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-capybara (2.22.1)
Expand All @@ -488,9 +494,9 @@ GEM
rack (>= 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.44.0, < 2.0)
rubocop-rspec (3.6.0)
rubocop-rspec (3.9.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop (~> 1.81)
rubocop-rspec_rails (2.32.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/school_students_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def create_batch
# should assume the entire student import has failed.
def enqueue_batches(students)
# Raise if a batch is already in progress for this school.
raise ConcurrencyExceededForSchool if @school.import_in_progress?
raise CreateStudentsJob::ConcurrencyExceededForSchool if @school.import_in_progress?

@batch = GoodJob::Batch.new(description: @school.id)
@batch.enqueue do
Expand Down
2 changes: 1 addition & 1 deletion app/dashboards/project_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ def display_resource(project)
end

def permitted_attributes
super + [images: []]
super + [{ images: [] }]
end
end
4 changes: 2 additions & 2 deletions app/jobs/create_students_job.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class ConcurrencyExceededForSchool < StandardError; end

class CreateStudentsJob < ApplicationJob
class ConcurrencyExceededForSchool < StandardError; end

retry_on StandardError, wait: :polynomially_longer, attempts: 3 do |_job, e|
Sentry.capture_exception(e)
raise e
Expand Down
6 changes: 3 additions & 3 deletions app/jobs/upload_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
require 'github_api'
require 'locales'

class InvalidDirectoryStructureError < StandardError; end
class DataNotFoundError < StandardError; end

class UploadJob < ApplicationJob
class InvalidDirectoryStructureError < StandardError; end
class DataNotFoundError < StandardError; end

retry_on StandardError, wait: :polynomially_longer, attempts: 3 do |_job, e|
Sentry.capture_exception(e)
raise e
Expand Down
9 changes: 7 additions & 2 deletions app/models/filesystem_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ def self.component(file, dir)
{ name:, extension:, content: code, default: }
end

def self.file_mime_type(file)
Marcel::MimeType.for(File.open(file), name: File.basename(file))
def self.file_mime_type(path)
File.open(path) do |file|
Marcel::MimeType.for(file, name: File.basename(path))
end
end

def self.media(file, dir)
filename = File.basename(file)
# rubocop:disable Style/FileOpen
# This is an issue but we can't easily fix it as the returned IO object is used elsewhere.
io = File.open(dir.join(filename).to_s)
# rubocop:enable Style/FileOpen
{ filename:, io: }
end
end
4 changes: 1 addition & 3 deletions lib/concepts/school_student/create_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
module SchoolStudent
class Error < StandardError; end

class ConcurrencyExceededForSchool < StandardError; end

class CreateBatch
class << self
def call(school:, school_students_params:, token:)
response = OperationResponse.new
response[:job_id] = create_batch(school, school_students_params, token)
response
rescue ConcurrencyExceededForSchool => e
rescue CreateStudentsJob::ConcurrencyExceededForSchool => e
response[:error] = e
response[:error_type] = :job_concurrency_error
response
Expand Down
2 changes: 0 additions & 2 deletions lib/tasks/test_seeds.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require_relative 'seeds_helper'

# rubocop:disable Rails/Output
namespace :test_seeds do
include SeedsHelper

Expand Down Expand Up @@ -72,4 +71,3 @@ namespace :test_seeds do
end
end
end
# rubocop:enable Rails/Output
8 changes: 4 additions & 4 deletions spec/concepts/class_member/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@

it 'assigns the student_id' do
response = described_class.call(school_class:, students:, teachers:)
response_students = response[:class_members].select { |member| member.is_a?(ClassStudent) }
response_students = response[:class_members].grep(ClassStudent)
expect(response_students.map(&:student_id)).to match_array(student_ids)
end

it 'assigns the teacher_id' do
teacher_ids = teachers.map(&:id)
response = described_class.call(school_class:, students:, teachers:)
response_teachers = response[:class_members].select { |member| member.is_a?(ClassTeacher) }
response_teachers = response[:class_members].grep(ClassTeacher)
expect(response_teachers.map(&:teacher_id)).to match_array(teacher_ids)
end

Expand Down Expand Up @@ -160,14 +160,14 @@

it 'assigns the successful students' do
response = described_class.call(school_class:, students: new_students, teachers:)
response_students = response[:class_members].select { |member| member.is_a?(ClassStudent) }
response_students = response[:class_members].grep(ClassStudent)
expect(response_students.map(&:student_id)).to match_array(student_ids)
end

it 'assigns the successful teachers' do
teacher_ids = teachers.map(&:id)
response = described_class.call(school_class:, students: new_students, teachers:)
response_teachers = response[:class_members].select { |member| member.is_a?(ClassTeacher) }
response_teachers = response[:class_members].grep(ClassTeacher)
expect(response_teachers.map(&:teacher_id)).to match_array(teacher_ids)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
end

context "with users that don't exist in Profile" do
unknown_user_id = SecureRandom.uuid
let(:unknown_user_id) { SecureRandom.uuid }

let(:invalid_params) do
{
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/upload_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
it 'raises DataNotFoundError' do
expect do
described_class.perform_now(payload)
end.to raise_error(DataNotFoundError)
end.to raise_error(UploadJob::DataNotFoundError)
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/lib/profile_api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def delete_safeguarding_flag
end

it 'raises 422 exception with the relevant message if 400 status code is returned' do
response = { errors: [message: 'The password is well dodgy'] }
response = { errors: [{ message: 'The password is well dodgy' }] }
stub_request(:post, create_students_url)
.to_return(status: 400, body: response.to_json, headers: { 'content-type' => 'application/json' })

Expand Down Expand Up @@ -284,7 +284,7 @@ def create_school_student
it_behaves_like 'a request that handles an unexpected response status', :post, url: -> { create_students_url }, status: 202

it 'raises 422 exception with the relevant message if 400 status code is returned' do
response = { errors: [message: 'The password is well dodgy'] }
response = { errors: [{ message: 'The password is well dodgy' }] }
stub_request(:post, create_students_url)
.to_return(status: 400, body: response.to_json, headers: { 'content-type' => 'application/json' })

Expand Down Expand Up @@ -356,7 +356,7 @@ def create_school_students
it_behaves_like 'a request that handles an unexpected response status', :post, url: -> { create_students_sso_url }, status: 202

it 'raises 422 exception with the relevant message if 400 status code is returned' do
response = { errors: [message: 'The password is well dodgy'] }
response = { errors: [{ message: 'The password is well dodgy' }] }
stub_request(:post, create_students_sso_url)
.to_return(status: 400, body: response.to_json, headers: { 'content-type' => 'application/json' })

Expand Down Expand Up @@ -478,7 +478,7 @@ def list_school_students
end

it 'raises 422 exception with the relevant message if 400 status code is returned' do
response = { errors: [message: 'The username is well dodgy'] }
response = { errors: [{ message: 'The username is well dodgy' }] }
stub_request(:patch, update_student_url)
.to_return(status: 400, body: response.to_json, headers: { 'content-type' => 'application/json' })

Expand Down
Loading