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

add test validation for lag

Behrokh Satarnejadd66440ca26ac
diff --git a/app/contracts/relations/base_contract.rb b/app/contracts/relations/base_contract.rb
index 82c4d5edc2e..37a4f452ea8 100644
--- a/app/contracts/relations/base_contract.rb
+++ b/app/contracts/relations/base_contract.rb
@@ -39,6 +39,7 @@ module Relations
validate :validate_to_exists
validate :validate_nodes_relatable
validate :validate_accepted_type
+ validate :validate_lag_numericality
def self.model
Relation
@@ -73,6 +74,13 @@ module Relations
end
end
+ def validate_lag_numericality
+ unless model.lag.nil? || model.lag.between?(0, 2_147_483_647)
+ errors.add :lag, :less_than_or_equal_to if model.lag > 2_147_483_647
+ errors.add :lag, :greater_than_or_equal_to if model.lag < 0
+ end
+ end
+
def visible_work_packages
::WorkPackage.visible(user)
end
diff --git a/spec/models/relation_spec.rb b/spec/models/relation_spec.rb
index 6d8681a5f40..f281e18e0c8 100644
--- a/spec/models/relation_spec.rb
+++ b/spec/models/relation_spec.rb
@@ -35,6 +35,19 @@ RSpec.describe Relation do
let(:type) { "relates" }
let(:relation) { build(:relation, from:, to:, relation_type: type) }
+ it "validates lag numericality" do
+ relation.lag = -1
+ expect(relation).not_to be_valid
+ expect(relation.errors[:lag]).to include("must be greater than or equal to 0.")
+
+ relation.lag = 2_147_483_648
+ expect(relation).not_to be_valid
+ expect(relation.errors[:lag]).to include("must be less than or equal to 2147483647.")
+
+ relation.lag = 1_000
+ expect(relation).to be_valid
+ end
+
describe "all relation types" do
Relation::TYPES.each do |key, type_hash|
let(:type) { key }