summaryrefslogtreecommitdiffstats
path: root/app/models/version.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-05-20 17:46:02 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-05-20 17:46:02 +0000
commitd34ea9a56986a524382641de987f818bbd0131e4 (patch)
treec9a09706ca3ac5e3b650faed3192c7418bd2a348 /app/models/version.rb
parentbb1fccb7b7202ec065fdc39646067054580d278f (diff)
downloadredmine-d34ea9a56986a524382641de987f818bbd0131e4.tar.gz
redmine-d34ea9a56986a524382641de987f818bbd0131e4.zip
Versions can now be created with no date.
Versions with no date appear at the end of the roadmap, sorted by name. git-svn-id: http://redmine.rubyforge.org/svn/trunk@536 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/version.rb')
-rw-r--r--app/models/version.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/version.rb b/app/models/version.rb
index 463ca3354..a4e93118e 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -23,7 +23,7 @@ class Version < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id]
- validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date
+ validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date, :allow_nil => true
def start_date
effective_date
@@ -37,6 +37,16 @@ class Version < ActiveRecord::Base
effective_date && effective_date <= Date.today
end
+ # Versions are sorted by effective_date
+ # Those with no effective_date are at the end, sorted by name
+ def <=>(version)
+ if self.effective_date
+ version.effective_date ? (self.effective_date <=> version.effective_date) : -1
+ else
+ version.effective_date ? 1 : (self.name <=> version.name)
+ end
+ end
+
private
def check_integrity
raise "Can't delete version" if self.fixed_issues.find(:first)