diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-11-17 08:52:51 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-11-17 08:52:51 +0000 |
commit | 3ad82e46658a1d792270a7e046257f2939b24f5e (patch) | |
tree | cb06f14c4f765ee8c61fb7407cc3712d53b43db0 | |
parent | eef3b5b5ca9a4db263a8d178203d62578fd2e744 (diff) | |
download | redmine-3ad82e46658a1d792270a7e046257f2939b24f5e.tar.gz redmine-3ad82e46658a1d792270a7e046257f2939b24f5e.zip |
Merged r10810 from trunk (#12359).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.1-stable@10821 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/version.rb | 7 | ||||
-rw-r--r-- | test/unit/version_test.rb | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/app/models/version.rb b/app/models/version.rb index cd32da91e..d6332897f 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -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 diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index d80c3d10f..83fb3f909 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -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 |