Skip to content

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

turn duration into explicit column on wp

ulferts1b04f5192c44
diff --git a/app/models/work_package/scheduling_rules.rb b/app/models/work_package/scheduling_rules.rb
index 46493629d51..9fb429d25a8 100644
--- a/app/models/work_package/scheduling_rules.rb
+++ b/app/models/work_package/scheduling_rules.rb
@@ -62,19 +62,4 @@ module WorkPackage::SchedulingRules
.compact
.max
end
-
- # Returns the time scheduled for this work package.
- #
- # Example:
- # Start Date: 2/26/09, Finish Date: 3/04/09, duration => 7
- # Start Date: 2/26/09, Finish Date: 2/26/09, duration => 1
- # Start Date: 2/26/09, Finish Date: - , duration => 1
- # Start Date: - , Finish Date: 2/26/09, duration => 1
- def duration
- if start_date && due_date
- due_date - start_date + 1
- else
- 1
- end
- end
end
diff --git a/db/migrate/20220505154549_add_duration_to_work_packages.rb b/db/migrate/20220505154549_add_duration_to_work_packages.rb
new file mode 100644
index 00000000000..845599feacf
--- /dev/null
+++ b/db/migrate/20220505154549_add_duration_to_work_packages.rb
@@ -0,0 +1,5 @@
+class AddDurationToWorkPackages < ActiveRecord::Migration[6.1]
+ def change
+ add_column :work_packages, :duration, :integer
+ end
+end
diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rb
index 38d4eff5eb9..0309b50a7ac 100644
--- a/spec/models/work_package_spec.rb
+++ b/spec/models/work_package_spec.rb
@@ -648,53 +648,19 @@ describe WorkPackage, type: :model do
end
describe '#duration' do
- let(:instance) { send(subclass) }
-
- describe "w/ today as start date
- w/ tomorrow as finish date" do
- before do
- work_package.start_date = Date.today
- work_package.due_date = Date.today + 1.day
- end
-
- it 'should have a duration of two' do
- expect(work_package.duration).to eq(2)
- end
- end
-
- describe "w/ today as start date
- w/ today as finish date" do
- before do
- work_package.start_date = Date.today
- work_package.due_date = Date.today
- end
-
- it 'should have a duration of one' do
- expect(work_package.duration).to eq(1)
- end
- end
-
- describe "w/ today as start date
- w/o a finish date" do
- before do
- work_package.start_date = Date.today
- work_package.due_date = nil
- end
-
- it 'should have a duration of one' do
- expect(work_package.duration).to eq(1)
+ context "when not setting a value" do
+ it 'is nil' do
+ expect(work_package.duration).to be_nil
end
end
- describe "w/o a start date
- w today as finish date" do
+ context "when setting the value" do
before do
- work_package.start_date = nil
- work_package.due_date = Date.today
+ work_package.duration = 5
end
- it 'should have a duration of one' do
- expect(work_package.duration).to eq(1)
+ it 'is the value' do
+ expect(work_package.duration).to eq(5)
end
end
end