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
Define a 'scheduling mode' column in table_helpers
Christophe Bliardbac76b9f6a5c
diff --git a/spec/migrations/update_scheduling_mode_and_lags_spec.rb b/spec/migrations/update_scheduling_mode_and_lags_spec.rbindex 89da634d80b..266b5fbef31 100644--- a/spec/migrations/update_scheduling_mode_and_lags_spec.rb+++ b/spec/migrations/update_scheduling_mode_and_lags_spec.rb@@ -53,9 +53,9 @@ RSpec.describe UpdateSchedulingModeAndLags, type: :model dodescribe "journal creation" docontext "when scheduling mode is changed by the migration" dolet_work_packages(<<~TABLE)- subject | schedule manually- wp already manual | true- wp automatic | false+ subject | scheduling mode+ wp already manual | manual+ wp automatic | automaticTABLEbefore do@@ -96,15 +96,15 @@ RSpec.describe UpdateSchedulingModeAndLags, type: :model do# spec from #42388, "Migration from an earlier version" sectioncontext "for work packages with no predecessors" dolet_work_packages(<<~TABLE)- subject | start date | due date | schedule manually- wp automatic 1 | 2024-11-20 | 2024-11-21 | false- wp automatic 2 | | 2024-11-21 | false- wp automatic 3 | 2024-11-20 | | false- wp automatic 4 | | | false- wp manual 1 | 2024-11-20 | 2024-11-21 | true- wp manual 2 | | 2024-11-21 | true- wp manual 3 | 2024-11-20 | | true- wp manual 4 | | | true+ subject | start date | due date | scheduling mode+ wp automatic 1 | 2024-11-20 | 2024-11-21 | automatic+ wp automatic 2 | | 2024-11-21 | automatic+ wp automatic 3 | 2024-11-20 | | automatic+ wp automatic 4 | | | automatic+ wp manual 1 | 2024-11-20 | 2024-11-21 | manual+ wp manual 2 | | 2024-11-21 | manual+ wp manual 3 | 2024-11-20 | | manual+ wp manual 4 | | | manualTABLEit "switches to manual scheduling" dodiff --git a/spec/support/table_helpers/column.rb b/spec/support/table_helpers/column.rbindex 49700ba01bc..2c5fb667a44 100644--- a/spec/support/table_helpers/column.rb+++ b/spec/support/table_helpers/column.rb@@ -36,6 +36,7 @@ require_relative "column_type/hierarchy"require_relative "column_type/percentage"require_relative "column_type/properties"require_relative "column_type/schedule"+require_relative "column_type/scheduling_mode"require_relative "column_type/status"require_relative "column_type/subject"@@ -53,6 +54,7 @@ module TableHelpershierarchy: ColumnType::Hierarchy,properties: ColumnType::Properties,schedule: ColumnType::Schedule,+ schedule_manually: ColumnType::SchedulingMode,status: ColumnType::Status,subject: ColumnType::Subject,__fallback__: ColumnType::Generic@@ -88,6 +90,8 @@ module TableHelpers:due_datewhen /.*MTWTFSS.*/:schedule+ when /\s*scheduling mode\s*/+ :schedule_manuallywhen /\s*properties\s*/:propertieswhen /status/, /hierarchy/diff --git a/spec/support/table_helpers/column_type/scheduling_mode.rb b/spec/support/table_helpers/column_type/scheduling_mode.rbnew file mode 100644index 00000000000..5eea667f356--- /dev/null+++ b/spec/support/table_helpers/column_type/scheduling_mode.rb@@ -0,0 +1,67 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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.+#++++module TableHelpers+ module ColumnType+ # Column to specify scheduling mode of a work package.+ #+ # Can take values 'manual' or 'automatic' to set `schedule_manually`+ # attribute to `true` or `false` respectively.+ #+ # Example:+ #+ # | subject | scheduling mode |+ # | wp 1 | manual |+ # | wp 2 | automatic |+ class SchedulingMode < Generic+ def format(value)+ if value+ "manual"+ else+ "automatic"+ end+ end++ def parse(raw_value)+ case raw_value.downcase.strip+ when ""+ nil+ when "manual", "true"+ true+ when "automatic", "false"+ false+ else+ raise "Invalid scheduling mode: #{raw_value.strip}. " \+ "Expected 'manual' or 'automatic'."+ end+ end+ end+ end+enddiff --git a/spec/support_spec/table_helpers/column_type/scheduling_mode_spec.rb b/spec/support_spec/table_helpers/column_type/scheduling_mode_spec.rbnew file mode 100644index 00000000000..71066b450c0--- /dev/null+++ b/spec/support_spec/table_helpers/column_type/scheduling_mode_spec.rb@@ -0,0 +1,96 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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.+#++++require "spec_helper"++module TableHelpers::ColumnType+ RSpec.describe SchedulingMode do+ subject(:column_type) { described_class.new }+ def parsed_attributes(table)+ work_packages_data = TableHelpers::TableParser.new.parse(table)+ work_packages_data.pluck(:attributes)+ end++ describe "#parse" do+ it "maps 'manual' to `schedule_manually: true`" do+ expect(parsed_attributes(<<~TABLE))+ | scheduling mode |+ | manual |+ TABLE+ .to eq([{ schedule_manually: true }])+ end++ it "maps 'automatic' to `schedule_manually: false`" do+ expect(parsed_attributes(<<~TABLE))+ | scheduling mode |+ | automatic |+ TABLE+ .to eq([{ schedule_manually: false }])+ end++ it "maps empty value to `schedule_manually: nil` (which means automatic too)" do+ expect(parsed_attributes(<<~TABLE))+ | scheduling mode |+ | |+ TABLE+ .to eq([{ schedule_manually: nil }])+ end++ it "can still use 'schedule manually' as column name with `true` and `false` as values" do+ expect(parsed_attributes(<<~TABLE))+ | schedule manually |+ | true |+ | false |+ | |+ TABLE+ .to eq([{ schedule_manually: true }, { schedule_manually: false }, { schedule_manually: nil }])+ end++ it "raises an error if value is invalid" do+ expect { parsed_attributes(<<~TABLE) }+ | scheduling mode |+ | foo |+ TABLE+ .to raise_error("Invalid scheduling mode: foo. Expected 'manual' or 'automatic'.")+ end+ end++ describe "#format" do+ it "maps `true` to 'manual'" do+ expect(column_type.format(true)).to eq "manual"+ end++ it "maps `false` and `nil` to 'automatic'" do+ expect(column_type.format(false)).to eq "automatic"+ expect(column_type.format(nil)).to eq "automatic"+ end+ end+ end+end