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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
fix specs for create form
Klaus Zanders107097626ac5
diff --git a/modules/costs/app/models/cost_entry.rb b/modules/costs/app/models/cost_entry.rbindex 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 < ApplicationRecordvalidate :validatevalidates :entity_type,- inclusion: { in: ALLOWED_ENTITY_TYPES }+ inclusion: { in: ALLOWED_ENTITY_TYPES },+ allow_blank: truescope :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.rbindex 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 < ApplicationRecordallow_blank: truevalidates :entity_type,- inclusion: { in: ALLOWED_ENTITY_TYPES }+ inclusion: { in: ALLOWED_ENTITY_TYPES },+ allow_blank: truescope :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.rbindex 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 entryif no_project_or_context_changed?- model.project = model.work_package&.project+ model.project = model.entity&.projectendset_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.rbindex 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 APIenddef representer_class(model)+ return if model.nil?+case modelwhen WorkPackage then ::API::V3::WorkPackages::WorkPackageRepresenterwhen Meeting then ::API::V3::Meetings::MeetingRepresenter@@ -51,6 +53,8 @@ module APIenddef representer_type(model)+ return if model.nil?+case modelwhen WorkPackage then :work_packagewhen Meeting then :meeting@@ -60,6 +64,8 @@ module APIenddef title_attribute(model)+ return if model.nil?+case modelwhen WorkPackage then :subjectwhen Meeting then :titlediff --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.rbindex 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 docontext "with empty parameters" doit "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")endit "has a validation error on project" do@@ -104,7 +104,7 @@ RSpec.describe API::V3::TimeEntries::CreateFormAPI, content_type: :json dolet(: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 dohref: 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 doexpect(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 doexpect(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)