File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
services/proforma_service Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ class File < ApplicationRecord
6060 validates :weight , absence : true , unless : :teacher_defined_assessment?
6161 validates :file , presence : true if :context . is_a? ( Submission )
6262 validates :context_type , inclusion : { in : ALLOWED_CONTEXT_TYPES }
63+ validates :path , uniqueness : { scope : %I[ name file_type context_id context_type role ] }
64+
6365 # xml_id_path must be unique within the scope of an exercise.
6466 # Initially, it may match the record’s id (set while exporting),
6567 # but it can later diverge as long as uniqueness is preserved.
Original file line number Diff line number Diff line change 137137 end
138138 end
139139 end
140+
141+ context 'when a file with same attributes (path, name file_type context_id context_type role) already exists' do
142+ before do
143+ create ( :file , name : 'static' , context : exercise )
144+ file . validate
145+ end
146+
147+ let ( :exercise ) { create ( :dummy ) }
148+ let ( :file ) { build ( :file , name : 'static' , context : exercise ) }
149+
150+ it 'has an error for path' do
151+ expect ( file . errors [ :path ] ) . to be_present
152+ end
153+ end
140154end
Original file line number Diff line number Diff line change 346346 ProformaXML ::TaskFile . new (
347347 id : 'ms-file-2' ,
348348 content : 'content' ,
349- filename : 'filename .txt' ,
349+ filename : 'filename2 .txt' ,
350350 used_by_grader : 'used_by_grader' ,
351351 visible : 'yes' ,
352352 usage_by_lms : 'display' ,
456456 ProformaXML ::TaskFile . new (
457457 id : 'test_file_id2' ,
458458 content : 'testfile-content' ,
459- filename : 'testfile .txt' ,
459+ filename : 'testfile2 .txt' ,
460460 used_by_grader : 'yes' ,
461461 visible : 'no' ,
462462 usage_by_lms : 'display' ,
You can’t perform that action at this time.
0 commit comments