From 1102db9f02e0399a28a3907584ba5e07cd9b75eb Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sat, 16 Sep 2023 16:18:52 +0200 Subject: [PATCH] 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. --- app/models/exercise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index fa79eb35..9f3ec6aa 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -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