diff --git a/app/models/code_ocean/file.rb b/app/models/code_ocean/file.rb index 956d92a7..7bbba9b5 100644 --- a/app/models/code_ocean/file.rb +++ b/app/models/code_ocean/file.rb @@ -4,16 +4,6 @@ require File.expand_path('../../uploaders/file_uploader', __dir__) require File.expand_path('../../../lib/active_model/validations/boolean_presence_validator', __dir__) module CodeOcean - class FileNameValidator < ActiveModel::Validator - def validate(record) - existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id, - context_id: record.context_id, context_type: record.context_type).to_a - if !existing_files.empty? && (!record.context.is_a?(Exercise) || record.context.new_record?) - record.errors[:base] << 'Duplicate' - end - end - end - class File < ApplicationRecord include DefaultValues diff --git a/app/validators/code_ocean/file_name_validator.rb b/app/validators/code_ocean/file_name_validator.rb new file mode 100644 index 00000000..f9161458 --- /dev/null +++ b/app/validators/code_ocean/file_name_validator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module CodeOcean + class FileNameValidator < ActiveModel::Validator + def validate(record) + existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id, + context_id: record.context_id, context_type: record.context_type).to_a + if !existing_files.empty? && (!record.context.is_a?(Exercise) || record.context.new_record?) + record.errors[:base] << 'Duplicate' + end + end + end +end