File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
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
You can’t perform that action at this time.
0 commit comments