Merge pull request #10635 from opf/fix/remove_unused_behind_schedule_code

remove behind_schedule methods since they are unused
fix/42397-project-filter-is-not-applied-in-embedded-table
ulferts 3 years ago committed by GitHub
commit 59a54f61c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/version.rb
  2. 8
      app/models/work_package.rb
  3. 61
      spec/models/work_package/work_package_scheduling_spec.rb
  4. 52
      spec_legacy/unit/version_spec.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

@ -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)

@ -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

@ -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|

Loading…
Cancel
Save