Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Reminder note should not be more than 80 chars

Kabiru Mwenja9627c5b8fc7f
diff --git a/app/contracts/reminders/base_contract.rb b/app/contracts/reminders/base_contract.rb
index abdf358a7a1..b539f96f636 100644
--- a/app/contracts/reminders/base_contract.rb
+++ b/app/contracts/reminders/base_contract.rb
@@ -28,6 +28,8 @@
module Reminders
class BaseContract < ::ModelContract
+ MAX_NOTE_CHARS_LENGTH = 80
+
attribute :creator_id
attribute :remindable_id
attribute :remindable_type
@@ -39,6 +41,7 @@ module Reminders
validate :validate_remindable_exists
validate :validate_manage_reminders_permissions
validate :validate_remind_at_is_in_future
+ validate :validate_note_length
def self.model = Reminder
@@ -62,6 +65,12 @@ module Reminders
end
end
+ def validate_note_length
+ if model.note.present? && model.note.length > MAX_NOTE_CHARS_LENGTH
+ errors.add :note, :too_long, count: MAX_NOTE_CHARS_LENGTH
+ end
+ end
+
def validate_manage_reminders_permissions
return if errors.added?(:remindable, :not_found)
diff --git a/spec/contracts/reminders/base_contract_spec.rb b/spec/contracts/reminders/base_contract_spec.rb
index 3005a15155f..1dc9fcd654d 100644
--- a/spec/contracts/reminders/base_contract_spec.rb
+++ b/spec/contracts/reminders/base_contract_spec.rb
@@ -119,5 +119,19 @@ RSpec.describe Reminders::BaseContract do
end
end
+ describe "validate note length" do
+ context "when note is too long" do
+ before { reminder.note = "a" * (described_class::MAX_NOTE_CHARS_LENGTH + 1) }
+
+ it_behaves_like "contract is invalid", note: :too_long
+ end
+
+ context "when note is within the limit" do
+ before { reminder.note = "a" * described_class::MAX_NOTE_CHARS_LENGTH }
+
+ it_behaves_like "contract is valid"
+ end
+ end
+
include_examples "contract reuses the model errors"
end