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

fix specs for create form

Klaus Zanders107097626ac5
diff --git a/modules/costs/app/models/cost_entry.rb b/modules/costs/app/models/cost_entry.rb
index 9955eec215e..bb1a9bdc904 100644
--- a/modules/costs/app/models/cost_entry.rb
+++ b/modules/costs/app/models/cost_entry.rb
@@ -54,7 +54,8 @@ class CostEntry < ApplicationRecord
validate :validate
validates :entity_type,
- inclusion: { in: ALLOWED_ENTITY_TYPES }
+ inclusion: { in: ALLOWED_ENTITY_TYPES },
+ allow_blank: true
scope :on_work_packages, ->(work_packages) { where(entity: work_packages) }
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index 3b49b539868..8a82d8e69ef 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -79,7 +79,8 @@ class TimeEntry < ApplicationRecord
allow_blank: true
validates :entity_type,
- inclusion: { in: ALLOWED_ENTITY_TYPES }
+ inclusion: { in: ALLOWED_ENTITY_TYPES },
+ allow_blank: true
scope :on_work_packages, ->(work_packages) { where(entity: work_packages) }
diff --git a/modules/costs/app/services/time_entries/set_attributes_service.rb b/modules/costs/app/services/time_entries/set_attributes_service.rb
index a5a5600db51..e8b8e604a5a 100644
--- a/modules/costs/app/services/time_entries/set_attributes_service.rb
+++ b/modules/costs/app/services/time_entries/set_attributes_service.rb
@@ -38,7 +38,7 @@ module TimeEntries
##
# Update project context if moving time entry
if no_project_or_context_changed?
- model.project = model.work_package&.project
+ model.project = model.entity&.project
end
set_default_attributes(params) if model.new_record?
diff --git a/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb b/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb
index fa753c9c13e..f5356c14ec9 100644
--- a/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb
+++ b/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb
@@ -42,6 +42,8 @@ module API
end
def representer_class(model)
+ return if model.nil?
+
case model
when WorkPackage then ::API::V3::WorkPackages::WorkPackageRepresenter
when Meeting then ::API::V3::Meetings::MeetingRepresenter
@@ -51,6 +53,8 @@ module API
end
def representer_type(model)
+ return if model.nil?
+
case model
when WorkPackage then :work_package
when Meeting then :meeting
@@ -60,6 +64,8 @@ module API
end
def title_attribute(model)
+ return if model.nil?
+
case model
when WorkPackage then :subject
when Meeting then :title
diff --git a/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb b/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb
index ce9352e5e16..9f1c3bf4004 100644
--- a/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb
+++ b/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb
@@ -79,7 +79,7 @@ RSpec.describe API::V3::TimeEntries::CreateFormAPI, content_type: :json do
context "with empty parameters" do
it "has 4 validation errors" do
- expect(subject.body).to have_json_size(3).at_path("_embedded/validationErrors")
+ expect(subject.body).to have_json_size(4).at_path("_embedded/validationErrors")
end
it "has a validation error on project" do
@@ -104,7 +104,7 @@ RSpec.describe API::V3::TimeEntries::CreateFormAPI, content_type: :json do
let(:parameters) do
{
_links: {
- workPackage: {
+ entity: {
href: api_v3_paths.work_package(work_package.id)
},
project: {
@@ -114,7 +114,7 @@ RSpec.describe API::V3::TimeEntries::CreateFormAPI, content_type: :json do
href: api_v3_paths.time_entries_activity(active_activity.id)
}
},
- spentOn: Date.today.to_s,
+ spentOn: Date.current.iso8601,
hours: "PT5H",
comment: {
raw: "some comment"
@@ -138,7 +138,7 @@ RSpec.describe API::V3::TimeEntries::CreateFormAPI, content_type: :json do
expect(body)
.to be_json_eql(api_v3_paths.work_package(work_package.id).to_json)
- .at_path("_embedded/payload/_links/workPackage/href")
+ .at_path("_embedded/payload/_links/entity/href")
expect(body)
.to be_json_eql(api_v3_paths.time_entries_activity(active_activity.id).to_json)
@@ -153,7 +153,7 @@ RSpec.describe API::V3::TimeEntries::CreateFormAPI, content_type: :json do
.at_path("_embedded/payload/comment/raw")
expect(body)
- .to be_json_eql(Date.today.to_s.to_json)
+ .to be_json_eql(Date.current.to_json)
.at_path("_embedded/payload/spentOn")
expect(body)
@@ -172,7 +172,7 @@ RSpec.describe API::V3::TimeEntries::CreateFormAPI, content_type: :json do
expect(body)
.to be_json_eql(wp_path.to_json)
- .at_path("_embedded/schema/workPackage/_links/allowedValues/href")
+ .at_path("_embedded/schema/entity/_links/allowedValues/href")
expect(body)
.to be_json_eql(api_v3_paths.time_entries_available_projects.to_json)