From 8d5b62b5cd5ab797d6ee11ca26ddbfcccda852fb Mon Sep 17 00:00:00 2001 From: ulferts Date: Wed, 4 May 2022 15:33:20 +0200 Subject: [PATCH] remove behind_schedule methods since they are unused --- app/models/version.rb | 11 ---- app/models/work_package.rb | 8 --- .../work_package_scheduling_spec.rb | 61 ------------------- spec_legacy/unit/version_spec.rb | 52 ---------------- 4 files changed, 132 deletions(-) diff --git a/app/models/version.rb b/app/models/version.rb index b2de329603..94ddbc35c7 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -100,17 +100,6 @@ class Version < ApplicationRecord effective_date && (effective_date <= Date.today) && open_issues_count.zero? end - def behind_schedule? - if completed_percent == 100 - false - elsif due_date && start_date - done_date = start_date + ((due_date - start_date + 1) * completed_percent / 100).floor - done_date <= Date.today - else - false # No issues so it's not late - end - end - # Returns the completion percentage of this version based on the amount of open/closed issues # and the time spent on the open issues. def completed_percent diff --git a/app/models/work_package.rb b/app/models/work_package.rb index 8da46d1c28..4b21d56670 100644 --- a/app/models/work_package.rb +++ b/app/models/work_package.rb @@ -350,14 +350,6 @@ class WorkPackage < ApplicationRecord end end - # Is the amount of work done less than it should for the finish date - def behind_schedule? - return false if start_date.nil? || due_date.nil? - - done_date = start_date + (duration * done_ratio / 100).floor - done_date <= Date.today - end - # check if user is allowed to edit WorkPackage Journals. # see Acts::Journalized::Permissions#journal_editable_by def journal_editable_by?(journal, user) diff --git a/spec/models/work_package/work_package_scheduling_spec.rb b/spec/models/work_package/work_package_scheduling_spec.rb index b9bb62de59..c1d94f0edf 100644 --- a/spec/models/work_package/work_package_scheduling_spec.rb +++ b/spec/models/work_package/work_package_scheduling_spec.rb @@ -85,65 +85,4 @@ describe WorkPackage, type: :model do it_behaves_like 'on time' end end - - describe '#behind_schedule?' do - let(:work_package) do - create(:work_package, - start_date: start_date, - due_date: due_date, - done_ratio: done_ratio) - end - - shared_examples_for 'behind schedule' do - subject { work_package.behind_schedule? } - - it { is_expected.to be_truthy } - end - - shared_examples_for 'in schedule' do - subject { work_package.behind_schedule? } - - it { is_expected.to be_falsey } - end - - context 'no start date' do - let(:start_date) { nil } - let(:due_date) { 1.day.from_now.to_date } - let(:done_ratio) { 0 } - - it_behaves_like 'in schedule' - end - - context 'no end date' do - let(:start_date) { 1.day.from_now.to_date } - let(:due_date) { nil } - let(:done_ratio) { 0 } - - it_behaves_like 'in schedule' - end - - context "more done than it's calendar time" do - let(:start_date) { 50.day.ago.to_date } - let(:due_date) { 50.day.from_now.to_date } - let(:done_ratio) { 90 } - - it_behaves_like 'in schedule' - end - - context 'not started' do - let(:start_date) { 1.day.ago.to_date } - let(:due_date) { 1.day.from_now.to_date } - let(:done_ratio) { 0 } - - it_behaves_like 'behind schedule' - end - - context "more done than it's calendar time" do - let(:start_date) { 100.day.ago.to_date } - let(:due_date) { Date.today } - let(:done_ratio) { 90 } - - it_behaves_like 'behind schedule' - end - end end diff --git a/spec_legacy/unit/version_spec.rb b/spec_legacy/unit/version_spec.rb index 8666afe35d..d1d8345879 100644 --- a/spec_legacy/unit/version_spec.rb +++ b/spec_legacy/unit/version_spec.rb @@ -145,58 +145,6 @@ describe Version, type: :model do assert_progress_equal 25.0 / 100.0 * 100, v.closed_percent end - context '#behind_schedule?' do - before do - ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests - @project = create(:project, identifier: 'test0') - @project.types << create(:type) - - (@version = Version.new.tap do |v| - v.attributes = { project: @project, effective_date: nil, name: 'test' } - end).save! - end - - it 'should be false if there are no issues assigned' do - @version.update_attribute(:effective_date, Date.yesterday) - assert_equal false, @version.behind_schedule? - end - - it 'should be false if there is no effective_date' do - assert_equal false, @version.behind_schedule? - end - - it 'should be false if all of the issues are ahead of schedule' do - @version.update_attribute(:effective_date, 7.days.from_now.to_date) - @version.work_packages = [ - create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 60), # 14 day span, 60% done, 50% time left - create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 60) # 14 day span, 60% done, 50% time left - ] - assert_equal 60, @version.completed_percent - assert_equal false, @version.behind_schedule? - end - - it 'should be true if any of the issues are behind schedule' do - @version.update_attribute(:start_date, 7.days.ago.to_date) - @version.update_attribute(:effective_date, 7.days.from_now.to_date) - @version.work_packages = [ - create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 60), # 14 day span, 60% done, 50% time left - create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 20) # 14 day span, 20% done, 50% time left - ] - assert_equal 40, @version.completed_percent - assert_equal true, @version.behind_schedule? - end - - it 'should be false if all of the issues are complete' do - @version.update_attribute(:effective_date, 7.days.from_now.to_date) - @version.work_packages = [ - create(:work_package, project: @project, start_date: 14.days.ago, done_ratio: 100, status: Status.find(5)), # 7 day span - create(:work_package, project: @project, start_date: 14.days.ago, done_ratio: 100, status: Status.find(5)) # 7 day span - ] - assert_equal 100, @version.completed_percent - assert_equal false, @version.behind_schedule? - end - end - context '#estimated_hours' do before do (@version = Version.new.tap do |v|