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 specs for entity= setter overrides

Klaus Zanderscd572d8d985e
diff --git a/modules/costs/app/models/cost_entry.rb b/modules/costs/app/models/cost_entry.rb
index fc5e8222f03..96d6b8a90ca 100644
--- a/modules/costs/app/models/cost_entry.rb
+++ b/modules/costs/app/models/cost_entry.rb
@@ -103,6 +103,10 @@ class CostEntry < ApplicationRecord
end
end
+ def entity_gid
+ entity&.to_gid.to_s
+ end
+
def overwritten_costs=(costs)
write_attribute(:overwritten_costs, CostRate.parse_number_string_to_number(costs))
end
diff --git a/modules/costs/spec/models/cost_entry_spec.rb b/modules/costs/spec/models/cost_entry_spec.rb
index e6b271a1ec7..1c25574e9e3 100644
--- a/modules/costs/spec/models/cost_entry_spec.rb
+++ b/modules/costs/spec/models/cost_entry_spec.rb
@@ -158,6 +158,14 @@ RSpec.describe CostEntry do
end
describe "instance" do
+ describe "#entity=" do
+ it "allows setting an entity via GlobalID" do
+ wp = create(:work_package)
+ cost_entry.entity = wp.to_gid.to_s
+ expect(cost_entry.entity).to eq(wp)
+ end
+ end
+
describe "#costs" do
let(:fourth_rate) do
build(:cost_rate, valid_from: date - 1.day,
diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rb
index 9b170376691..5bf5d722c7e 100644
--- a/modules/costs/spec/models/time_entry_spec.rb
+++ b/modules/costs/spec/models/time_entry_spec.rb
@@ -92,6 +92,14 @@ RSpec.describe TimeEntry do
end
end
+ describe "#entity=" do
+ it "allows setting an entity via GlobalID" do
+ meeting = create(:meeting)
+ time_entry.entity = meeting.to_gid.to_s
+ expect(time_entry.entity).to eq(meeting)
+ end
+ end
+
describe "#hours=" do
formats = { "2" => 2.0,
"21.1" => 21.1,