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
Add specs for creating work packages with an invalid filter on the work package view. Simplify the wp set attributes service logic for clearing invalid statuses
Dombi Attilaad5d91923646
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex 2728acc2653..95a6a194602 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -168,16 +168,9 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesenddef set_default_status- remove_status_if_invalidwork_package.status ||= Status.defaultend- def remove_status_if_invalid- if work_package.type && !work_package.type.statuses.exists?(model.status_id)- work_package.status = nil- end- end-def set_default_prioritywork_package.priority ||= IssuePriority.active.defaultend@@ -334,7 +327,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesdef reassign_invalid_status_if_type_changed# Checks that the issue can not be moved to a type with the status unchanged# and the target type does not have this status- if work_package.type_id_changed? && !work_package.status_id_changed?+ if work_package.type_id_changed?reassign_status work_package.type.statuses(include_default: true)endenddiff --git a/spec/features/work_packages/new/attributes_from_filter_spec.rb b/spec/features/work_packages/new/attributes_from_filter_spec.rbindex a065c648524..750570573ec 100644--- a/spec/features/work_packages/new/attributes_from_filter_spec.rb+++ b/spec/features/work_packages/new/attributes_from_filter_spec.rb@@ -33,9 +33,8 @@ RSpec.describe 'Work package create uses attributes from filters', js: true, sellet(:type_bug) { create(:type_bug) }let(:type_task) { create(:type_task) }let(:project) { create(:project, types: [type_task, type_bug]) }- let(:status) { create(:default_status) }- let!(:status) { create(:default_status) }+ let!(:default_status) { create(:default_status) }let!(:priority) { create(:priority, is_default: true) }let(:wp_table) { Pages::WorkPackagesTable.new(project) }@@ -51,7 +50,7 @@ RSpec.describe 'Work package create uses attributes from filters', js: true, selquery.add_filter(*filter)end- query.column_names = ['id', 'subject', 'type', 'assigned_to']+ query.column_names = ['id', 'subject', 'type', 'assigned_to', 'status']query.save!endend@@ -179,4 +178,101 @@ RSpec.describe 'Work package create uses attributes from filters', js: true, selexpect(wp.type_id).to eq type_bug.idendend++ context 'with status filter' do+ let(:closed_status) { create(:closed_status) }+ let!(:bug_workflow) { create(:workflow, type: type_bug, old_status: closed_status) }+ let(:filters) do+ [['status_id', '=', [closed_status.id]]]+ end++ it 'uses the status filter in inline-create and split view' do+ # When the chosen type ( type_task ) does not have a workflow for the status (closed_status)+ # of the filter, it uses the default status instead (Regression #36719)+ wp_table.click_inline_create++ # Expect type set to task+ type_field = wp_table.edit_field(nil, :type)+ type_field.expect_state_text type_task.name.upcase++ # Expect status set to status+ status_field = wp_table.edit_field(nil, :status)+ status_field.expect_state_text default_status.name++ # Save the WP+ subject_field = wp_table.edit_field(nil, :subject)+ subject_field.set_value 'Foobar!'+ subject_field.submit_by_enter++ wp_table.expect_toast(+ message: 'Successful creation. Click here to open this work package in fullscreen view.'+ )+ wp_table.dismiss_toaster!++ wp = WorkPackage.last+ expect(wp.subject).to eq 'Foobar!'+ expect(wp.type_id).to eq type_task.id+ expect(wp.status_id).to eq default_status.id++ # When the chosen type (type_bug) has a workflow for the status (closed_status)+ # of the filter, it uses that status++ # Open split view create+ split_view_create.click_create_wp_button(type_bug)++ subject_field = split_view_create.edit_field :subject+ subject_field.expect_active!+ subject_field.set_value 'Split Foobar!'++ # Type field IS NOT synced+ type_field = split_view_create.edit_field :type+ type_field.expect_state_text type_bug.name.upcase++ # Status is synced+ status_field = split_view_create.edit_field :status+ status_field.expect_display_value(closed_status.name.humanize)++ within '.work-packages--edit-actions' do+ click_button 'Save'+ end++ wp_table.expect_toast(message: 'Successful creation.')++ wp = WorkPackage.last+ expect(wp.subject).to eq 'Split Foobar!'+ expect(wp.type_id).to eq type_bug.id+ expect(wp.status_id).to eq closed_status.id++ Pages::SplitWorkPackage.new(wp, project).close++ # When the chosen type (type_task) does not have a workflow for the status (closed_status)+ # of the filter, it uses the default status instead (Regression #36719)++ # Open split view create+ split_view_create.click_create_wp_button(type_task)++ subject_field = split_view_create.edit_field :subject+ subject_field.expect_active!+ subject_field.set_value 'Split Foobar!'++ # Type field IS NOT synced+ type_field = split_view_create.edit_field :type+ type_field.expect_state_text type_task.name.upcase++ # Status is synced+ status_field = split_view_create.edit_field :status+ status_field.expect_display_value(default_status.name.humanize)++ within '.work-packages--edit-actions' do+ click_button 'Save'+ end++ wp_table.expect_toast(message: 'Successful creation.')++ wp = WorkPackage.last+ expect(wp.subject).to eq 'Split Foobar!'+ expect(wp.type_id).to eq type_task.id+ expect(wp.status_id).to eq default_status.id+ end+ endenddiff --git a/spec/support/pages/work_packages/abstract_work_package.rb b/spec/support/pages/work_packages/abstract_work_package.rbindex 7da079828d5..f5d2eddba9a 100644--- a/spec/support/pages/work_packages/abstract_work_package.rb+++ b/spec/support/pages/work_packages/abstract_work_package.rb@@ -136,7 +136,7 @@ module Pagescontainer = '#work-package-activites-container'container += " #activity-#{number}" if number- expect(page).to have_selector(container + ' .op-user-activity--user-line', text: user.name)+ expect(page).to have_selector("#{container} .op-user-activity--user-line", text: user.name)enddef expect_activity_message(message)@@ -207,7 +207,9 @@ module PagesDateEditField.new container, key, is_milestone: work_package&.milestone?when :descriptionTextEditorField.new container, key- when :status+ # The AbstractWorkPackageCreate pages do not require a special WorkPackageStatusField,+ # because the status field on the create pages is a simple EditField.+ when :status && !is_a?(AbstractWorkPackageCreate)WorkPackageStatusField.new containerelseEditField.new container, key