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

limit time entry comment to the current database value with a rails validation

Klaus Zanders6d2ebd8d1153
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index fdd1d33ef4d..0001ef25d32 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -59,6 +59,10 @@ class TimeEntry < ApplicationRecord
},
allow_nil: true
+ validates :comments,
+ length: { maximum: 255 },
+ allow_blank: true
+
validates :start_time,
presence: true,
if: -> { TimeEntry.must_track_start_and_end_time? }
diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rb
index 10cba11697c..650261693da 100644
--- a/modules/costs/spec/models/time_entry_spec.rb
+++ b/modules/costs/spec/models/time_entry_spec.rb
@@ -484,6 +484,23 @@ RSpec.describe TimeEntry do
end
end
end
+
+ describe "comments" do
+ it "allows blank values" do
+ time_entry.comments = ""
+ expect(time_entry).to be_valid
+ end
+
+ it "allows values with a length of 255 characters" do
+ time_entry.comments = "a" * 255
+ expect(time_entry).to be_valid
+ end
+
+ it "does not allow values with a length of >255 characters" do
+ time_entry.comments = "a" * 256
+ expect(time_entry).not_to be_valid
+ end
+ end
end
describe "#start_timestamp" do