Fixed version date validation (#12359).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10810 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e9e5d2e072
commit
8b527ce247
|
@ -33,6 +33,7 @@ class Version < ActiveRecord::Base
|
|||
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true
|
||||
validates_inclusion_of :status, :in => VERSION_STATUSES
|
||||
validates_inclusion_of :sharing, :in => VERSION_SHARINGS
|
||||
validate :validate_version
|
||||
|
||||
scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
||||
scope :open, :conditions => {:status => 'open'}
|
||||
|
@ -275,4 +276,10 @@ class Version < ActiveRecord::Base
|
|||
progress
|
||||
end
|
||||
end
|
||||
|
||||
def validate_version
|
||||
if effective_date.nil? && @attributes['effective_date'].present?
|
||||
errors.add :effective_date, :not_a_date
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,7 +32,13 @@ class VersionTest < ActiveSupport::TestCase
|
|||
|
||||
def test_invalid_effective_date_validation
|
||||
v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01')
|
||||
assert !v.save
|
||||
assert !v.valid?
|
||||
v.effective_date = '2012-11-33'
|
||||
assert !v.valid?
|
||||
v.effective_date = '2012-31-11'
|
||||
assert !v.valid?
|
||||
v.effective_date = 'ABC'
|
||||
assert !v.valid?
|
||||
assert_include I18n.translate('activerecord.errors.messages.not_a_date'),
|
||||
v.errors[:effective_date]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue