##// END OF EJS Templates
Fixed version date validation (#12359)....
Jean-Philippe Lang -
r10583:8b527ce24783
parent child
Show More
@@ -33,6 +33,7 class Version < ActiveRecord::Base
33 33 validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true
34 34 validates_inclusion_of :status, :in => VERSION_STATUSES
35 35 validates_inclusion_of :sharing, :in => VERSION_SHARINGS
36 validate :validate_version
36 37
37 38 scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
38 39 scope :open, :conditions => {:status => 'open'}
@@ -275,4 +276,10 class Version < ActiveRecord::Base
275 276 progress
276 277 end
277 278 end
279
280 def validate_version
281 if effective_date.nil? && @attributes['effective_date'].present?
282 errors.add :effective_date, :not_a_date
283 end
284 end
278 285 end
@@ -32,7 +32,13 class VersionTest < ActiveSupport::TestCase
32 32
33 33 def test_invalid_effective_date_validation
34 34 v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01')
35 assert !v.save
35 assert !v.valid?
36 v.effective_date = '2012-11-33'
37 assert !v.valid?
38 v.effective_date = '2012-31-11'
39 assert !v.valid?
40 v.effective_date = 'ABC'
41 assert !v.valid?
36 42 assert_include I18n.translate('activerecord.errors.messages.not_a_date'),
37 43 v.errors[:effective_date]
38 44 end
General Comments 0
You need to be logged in to leave comments. Login now