Fix wrong validation of main file count

Previously, we were always issuing a database query, so that only those files already stored in the database were counted.
This commit is contained in:
Sebastian Serth
2023-09-16 16:18:52 +02:00
parent cc4f1d2ace
commit 1102db9f02

View File

@ -562,7 +562,7 @@ class Exercise < ApplicationRecord
end
def valid_main_file?
if files.main_files.count > 1
if files.count(&:main_file?) > 1
errors.add(:files,
I18n.t('activerecord.errors.models.exercise.at_most_one_main_file'))
end