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
Only "re-assign" types for new record convenience
Aaron Contreras4b6d6a039f59
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex 31c644ed7ba..75025cd34dd 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -251,7 +251,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesreassign_categoryset_parent_to_nil- reassign_type unless work_package.type_id_changed?+ assign_default_type unless work_package.typeendend@@ -452,11 +452,9 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesendend- def reassign_type+ def assign_default_typeavailable_types = work_package.project.types.order(:position)- return if available_types.include?(work_package.type) && work_package.type-work_package.type = available_types.firstupdate_durationunify_milestone_datesdiff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex a4231dc0392..122d24a4516 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -2068,35 +2068,25 @@ RSpec.describe WorkPackages::SetAttributesService,endcontext "for type" do- context "when current type exists in new project" do- it "leaves the type" do- subject-- expect(work_package.type)- .to eql type+ context "when the work package has a type already set" do+ let(:work_package) do+ build_stubbed(:work_package, project:, type: initial_type)end- end-- context "when a default type exists in new project" do- let(:new_types) { [other_type, default_type] }- it "uses the first type (by position)" do+ it "leaves the type" dosubjectexpect(work_package.type)- .to eql other_type+ .to eql initial_typeend+ end- it "adds change to system changes" do- subject-- expect(work_package.changed_by_system["type_id"])- .to eql [initial_type.id, other_type.id]+ context "when the work package has no type set" do+ let(:work_package) do+ build_stubbed(:work_package, project:, type: nil)end- end- context "when no default type exists in new project" do- let(:new_types) { [other_type, yet_another_type] }+ let(:new_types) { [other_type] }it "uses the first type (by position)" dosubject@@ -2109,11 +2099,12 @@ RSpec.describe WorkPackages::SetAttributesService,subjectexpect(work_package.changed_by_system["type_id"])- .to eql [initial_type.id, other_type.id]+ .to eql [nil, other_type.id]endend- context "when also setting a new type via attributes" do+ context "and also setting a new type via attributes" do+ let(:new_types) { [yet_another_type] }let(:expected_attributes) { { project: new_project, type: yet_another_type } }it "sets the desired type" dodiff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rbindex d59b9abb340..70bb59189fb 100644--- a/spec/services/work_packages/update_service_integration_spec.rb+++ b/spec/services/work_packages/update_service_integration_spec.rb@@ -337,12 +337,9 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model docontext "with only non default types" dolet(:target_types) { [other_type] }- it "uses the first type" do+ it "is unsuccessful" doexpect(subject)- .to be_success-- expect(subject.result.type)- .to eql other_type+ .to be_failureendend