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
60
60
validates :weight , absence : true , unless : :teacher_defined_assessment?
61
61
validates :file , presence : true if :context . is_a? ( Submission )
62
62
validates :context_type , inclusion : { in : ALLOWED_CONTEXT_TYPES }
63
+ validates :path , uniqueness : { scope : %I[ name file_type context_id context_type role ] }
64
+
63
65
# xml_id_path must be unique within the scope of an exercise.
64
66
# Initially, it may match the record’s id (set while exporting),
65
67
# but it can later diverge as long as uniqueness is preserved.
Original file line number Diff line number Diff line change 137
137
end
138
138
end
139
139
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
140
154
end
You can’t perform that action at this time.
0 commit comments