summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-06-05 19:56:59 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-06-05 19:56:59 +0000
commit8cea7d8cf213174d282db85ef5e16832c9845501 (patch)
tree25729db612b245df31ea14a6abc2f6ada419327c
parent6327bdc6f871e9fa931a61615ec62c086d93dbbe (diff)
downloadredmine-8cea7d8cf213174d282db85ef5e16832c9845501.tar.gz
redmine-8cea7d8cf213174d282db85ef5e16832c9845501.zip
Don't validate start date when updating an issue without changing it (#14086).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11931 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue.rb4
-rw-r--r--test/object_helpers.rb9
-rw-r--r--test/unit/issue_test.rb21
3 files changed, 31 insertions, 3 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index c4183b016..b5e76176f 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -548,11 +548,11 @@ class Issue < ActiveRecord::Base
end
def validate_issue
- if due_date && start_date && due_date < start_date
+ if due_date && start_date && (start_date_changed? || due_date_changed?) && due_date < start_date
errors.add :due_date, :greater_than_start_date
end
- if start_date && soonest_start && start_date < soonest_start
+ if start_date && start_date_changed? && soonest_start && start_date < soonest_start
errors.add :start_date, :earlier_than_minimum_start_date, :date => format_date(soonest_start)
end
diff --git a/test/object_helpers.rb b/test/object_helpers.rb
index 2f29793f2..2f7559249 100644
--- a/test/object_helpers.rb
+++ b/test/object_helpers.rb
@@ -65,13 +65,20 @@ module ObjectHelpers
role
end
- def Issue.generate!(attributes={})
+ # Generates an unsaved Issue
+ def Issue.generate(attributes={})
issue = Issue.new(attributes)
issue.project ||= Project.find(1)
issue.tracker ||= issue.project.trackers.first
issue.subject = 'Generated' if issue.subject.blank?
issue.author ||= User.find(2)
yield issue if block_given?
+ issue
+ end
+
+ # Generates a saved Issue
+ def Issue.generate!(attributes={}, &block)
+ issue = Issue.generate(attributes, &block)
issue.save!
issue
end
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 0fa880809..c7d134074 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -92,6 +92,27 @@ class IssueTest < ActiveSupport::TestCase
assert_include 'Due date must be greater than start date', issue.errors.full_messages
end
+ def test_start_date_lesser_than_soonest_start_should_not_validate_on_create
+ issue = Issue.generate(:start_date => '2013-06-04')
+ issue.stubs(:soonest_start).returns(Date.parse('2013-06-10'))
+ assert !issue.valid?
+ assert_include "Start date cannot be earlier than 06/10/2013 because of preceding issues", issue.errors.full_messages
+ end
+
+ def test_start_date_lesser_than_soonest_start_should_not_validate_on_update_if_changed
+ issue = Issue.generate!(:start_date => '2013-06-04')
+ issue.stubs(:soonest_start).returns(Date.parse('2013-06-10'))
+ issue.start_date = '2013-06-07'
+ assert !issue.valid?
+ assert_include "Start date cannot be earlier than 06/10/2013 because of preceding issues", issue.errors.full_messages
+ end
+
+ def test_start_date_lesser_than_soonest_start_should_validate_on_update_if_unchanged
+ issue = Issue.generate!(:start_date => '2013-06-04')
+ issue.stubs(:soonest_start).returns(Date.parse('2013-06-10'))
+ assert issue.valid?
+ end
+
def test_estimated_hours_should_be_validated
set_language_if_valid 'en'
['-2'].each do |invalid|