Merge pull request #8043 from opf/fix/version-start-date-magic

Remove magic start_date applied to version, but not saved to DB
pull/8046/head
Oliver Günther 5 years ago committed by GitHub
commit b619251f49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/version.rb
  2. 14
      spec_legacy/unit/version_spec.rb

@ -72,17 +72,6 @@ class Version < ActiveRecord::Base
user.allowed_to?(:view_work_packages, project)
end
# When a version started.
#
# Can either be a set date stored in the database or a dynamic one
# based on the earlist start_date of the fixed_issues
def start_date
# when self.id is nil (e.g. when self is a new_record),
# minimum('start_date') works on all issues with fixed_version: nil
# but we expect only issues belonging to this version
read_attribute(:start_date) || fixed_issues.where(WorkPackage.arel_table[:fixed_version_id].not_eq(nil)).minimum('start_date')
end
def due_date
effective_date
end

@ -49,19 +49,6 @@ describe Version, type: :model do
end
context '#start_date' do
context 'with no value saved' do
it 'should be the date of the earlist issue' do
project = Project.find(1)
(v = Version.new.tap do |v|
v.attributes = { project: project, name: 'Progress' }
end).save!
add_work_package(v, estimated_hours: 10, start_date: '2010-03-01')
FactoryBot.create(:work_package, project: project, subject: 'not assigned', start_date: '2010-01-01')
assert_equal '2010-03-01', v.start_date.to_s
end
end
context 'with a value saved' do
it 'should be the value' do
project = Project.find(1)
@ -191,6 +178,7 @@ describe Version, type: :model do
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.fixed_issues = [
FactoryBot.create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 60), # 14 day span, 60% done, 50% time left

Loading…
Cancel
Save