mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
backlog bucket xor sprint
This commit is contained in:
@@ -70,6 +70,7 @@ en:
|
||||
share_all_projects_already_taken: "cannot be set because project \"%{name}\" is already sharing with all projects."
|
||||
share_all_projects_already_taken_anonymous: "cannot be set because another project is already sharing with all projects."
|
||||
work_package:
|
||||
backlog_bucket_xor_sprint: "cannot be assigned to both a sprint and a backlog bucket."
|
||||
attributes:
|
||||
blocks_ids:
|
||||
can_only_contain_work_packages_of_current_sprint: "can only contain IDs of work packages in the current sprint."
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
#-- copyright
|
||||
# OpenProject is an open source project management software.
|
||||
# Copyright (C) the OpenProject GmbH
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License version 3.
|
||||
#
|
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
# Copyright (C) 2010-2013 the ChiliProject Team
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# See COPYRIGHT and LICENSE files for more details.
|
||||
#++
|
||||
|
||||
class AddBacklogBucketXorSprintConstraintToWorkPackages < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
add_check_constraint :work_packages,
|
||||
"backlog_bucket_id IS NULL OR sprint_id IS NULL",
|
||||
name: "work_package_backlog_bucket_xor_sprint"
|
||||
end
|
||||
end
|
||||
@@ -46,6 +46,8 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch
|
||||
belongs_to :backlog_bucket, class_name: "Agile::BacklogBucket", optional: true
|
||||
belongs_to :sprint, class_name: "Agile::Sprint", optional: true
|
||||
|
||||
validate :backlog_bucket_xor_sprint
|
||||
|
||||
include OpenProject::Backlogs::List
|
||||
end
|
||||
|
||||
@@ -63,6 +65,14 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch
|
||||
def backlogs_enabled?
|
||||
project&.backlogs_enabled?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def backlog_bucket_xor_sprint
|
||||
return unless backlog_bucket && sprint
|
||||
|
||||
errors.add :base, :backlog_bucket_xor_sprint
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -36,6 +36,66 @@ RSpec.describe WorkPackage do
|
||||
it { is_expected.to belong_to(:sprint).class_name("Agile::Sprint").optional(true) }
|
||||
end
|
||||
|
||||
describe "can't be both in backlog bucket and sprint" do
|
||||
shared_let(:project) { create(:project) }
|
||||
shared_let(:backlog_bucket) { create(:backlog_bucket, project:) }
|
||||
shared_let(:sprint) { create(:agile_sprint, project:) }
|
||||
|
||||
context "when already in a backlog bucket" do
|
||||
let(:work_package) { create(:work_package, project:, backlog_bucket:) }
|
||||
|
||||
it "fails validation when being added to sprint" do
|
||||
work_package.assign_attributes(sprint:)
|
||||
|
||||
expect(work_package).not_to be_valid
|
||||
expect(work_package.errors[:base]).to include(/cannot be assigned to both a sprint and a backlog bucket/)
|
||||
end
|
||||
|
||||
it "fails being added to sprint" do
|
||||
work_package.assign_attributes(sprint:)
|
||||
|
||||
expect do
|
||||
work_package.save!(validate: false)
|
||||
end.to raise_error(ActiveRecord::CheckViolation)
|
||||
end
|
||||
|
||||
it "allows changing backlog bucket" do
|
||||
work_package.update(backlog_bucket: create(:backlog_bucket, project:))
|
||||
end
|
||||
|
||||
it "allows replacing backlog bucket with sprint" do
|
||||
work_package.update(backlog_bucket: nil, sprint:)
|
||||
end
|
||||
end
|
||||
|
||||
context "when already in a sprint" do
|
||||
let(:work_package) { create(:work_package, project:, sprint:) }
|
||||
|
||||
it "fails validation when being added to backlog bucket" do
|
||||
work_package.assign_attributes(backlog_bucket:)
|
||||
|
||||
expect(work_package).not_to be_valid
|
||||
expect(work_package.errors[:base]).to include(/cannot be assigned to both a sprint and a backlog bucket/)
|
||||
end
|
||||
|
||||
it "fails being added to backlog bucket" do
|
||||
work_package.assign_attributes(backlog_bucket:)
|
||||
|
||||
expect do
|
||||
work_package.save!(validate: false)
|
||||
end.to raise_error(ActiveRecord::CheckViolation)
|
||||
end
|
||||
|
||||
it "allows changing sprint" do
|
||||
work_package.update(sprint: create(:agile_sprint, project:))
|
||||
end
|
||||
|
||||
it "allows replacing sprint with backlog bucket" do
|
||||
work_package.update(backlog_bucket:, sprint: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".order_by_position" do
|
||||
let(:work_packages) { create_list(:work_package, 3) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user