From c69ab69c465112bdb04c1030f163309268846084 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Thu, 12 May 2016 14:39:00 +0200 Subject: [PATCH] Fix exercise update --- app/models/code_ocean/file.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/code_ocean/file.rb b/app/models/code_ocean/file.rb index 7b00cbdd..58440f1b 100644 --- a/app/models/code_ocean/file.rb +++ b/app/models/code_ocean/file.rb @@ -6,9 +6,11 @@ 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: record.context).to_a + context_id: record.context_id, context_type: record.context_type).to_a unless existing_files.empty? - record.errors[:base] << 'Duplicate' + if (not record.context.is_a?(Exercise)) || (record.context.new_record?) + record.errors[:base] << 'Duplicate' + end end end end