From 49a413a912a8f2c069c6c5e2445de9cd844ff87d Mon Sep 17 00:00:00 2001 From: Philipp Tessenow Date: Tue, 7 May 2013 15:31:03 +0200 Subject: [PATCH] Fix bug in Version#start_date. On an unsaved version, it returned a start_date even when none was set --- app/models/version.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/version.rb b/app/models/version.rb index b94f8c0726..4dac9d9d85 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -59,7 +59,10 @@ class Version < ActiveRecord::Base # 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 - read_attribute(:start_date) || fixed_issues.minimum('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(Issue.arel_table[:fixed_version_id].not_eq(nil)).minimum('start_date') end def due_date