diff --git a/app/models/available_course_lecturer.rb b/app/models/available_course_lecturer.rb index b1fc1593d..aa89450f9 100644 --- a/app/models/available_course_lecturer.rb +++ b/app/models/available_course_lecturer.rb @@ -6,7 +6,7 @@ class AvailableCourseLecturer < ApplicationRecord belongs_to :lecturer, class_name: 'Employee' # validations - validates :coordinator, inclusion: { in: [true, false] } + validates :coordinator, presence: true, inclusion: { in: [true, false] } # scopes scope :coordinator, -> { where(coordinator: true) } diff --git a/test/models/course/available_course_lecturer_test.rb b/test/models/course/available_course_lecturer_test.rb index 0537f16c7..9c8344d76 100644 --- a/test/models/course/available_course_lecturer_test.rb +++ b/test/models/course/available_course_lecturer_test.rb @@ -13,6 +13,13 @@ class AvailableCourseLecturerTest < ActiveSupport::TestCase end end + # validations: presence + test 'should not save available_course_group without coordinator info' do + available_course_lecturers(:ati_group_1_lecturer_john).coordinator = nil + assert_not available_course_lecturers(:ati_group_1_lecturer_john).valid? + assert_not_empty available_course_lecturers(:ati_group_1_lecturer_john).errors[:coordinator] + end + # scopes test 'coordinator scope returns coordinator lecturers' do lecturers = available_course_groups(:ati_group_1).lecturers