From 51fc44c2dad74971c2e76f770d9dc686d1ad4067 Mon Sep 17 00:00:00 2001 From: kiragrammel Date: Thu, 14 Sep 2023 11:52:58 +0200 Subject: [PATCH] Allow empty lines for current_content event Fixes CODEOCEAN-VR --- app/models/event/synchronized_editor.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/event/synchronized_editor.rb b/app/models/event/synchronized_editor.rb index a58aeadb..6b1861a0 100644 --- a/app/models/event/synchronized_editor.rb +++ b/app/models/event/synchronized_editor.rb @@ -34,7 +34,8 @@ class Event::SynchronizedEditor < ApplicationRecord validates :range_start_column, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: -> { action_editor_change? } validates :range_end_row, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: -> { action_editor_change? } validates :range_end_column, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: -> { action_editor_change? } - validates :lines, presence: true, if: -> { action_editor_change? || action_current_content? } + validates :lines, presence: true, if: -> { action_editor_change? } + validate :lines_not_nil, if: -> { action_current_content? } def self.create_for_editor_change(event, user, programming_group) event_copy = event.deep_dup @@ -91,3 +92,11 @@ class Event::SynchronizedEditor < ApplicationRecord end private_class_method :data_attribute end + +private + +def lines_not_nil + if lines.nil? + errors.add(:lines, 'cannot be nil') + end +end