Commit b43715c4 authored by jplang's avatar jplang

Don't validate start date when updating an issue without changing it (#14086).

git-svn-id: https://svn.redmine.org/redmine/trunk@11931 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 26e405a3
...@@ -548,11 +548,11 @@ class Issue < ActiveRecord::Base ...@@ -548,11 +548,11 @@ class Issue < ActiveRecord::Base
end end
def validate_issue 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 errors.add :due_date, :greater_than_start_date
end 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) errors.add :start_date, :earlier_than_minimum_start_date, :date => format_date(soonest_start)
end end
......
...@@ -65,13 +65,20 @@ module ObjectHelpers ...@@ -65,13 +65,20 @@ module ObjectHelpers
role role
end end
def Issue.generate!(attributes={}) # Generates an unsaved Issue
def Issue.generate(attributes={})
issue = Issue.new(attributes) issue = Issue.new(attributes)
issue.project ||= Project.find(1) issue.project ||= Project.find(1)
issue.tracker ||= issue.project.trackers.first issue.tracker ||= issue.project.trackers.first
issue.subject = 'Generated' if issue.subject.blank? issue.subject = 'Generated' if issue.subject.blank?
issue.author ||= User.find(2) issue.author ||= User.find(2)
yield issue if block_given? yield issue if block_given?
issue
end
# Generates a saved Issue
def Issue.generate!(attributes={}, &block)
issue = Issue.generate(attributes, &block)
issue.save! issue.save!
issue issue
end end
......
...@@ -92,6 +92,27 @@ class IssueTest < ActiveSupport::TestCase ...@@ -92,6 +92,27 @@ class IssueTest < ActiveSupport::TestCase
assert_include 'Due date must be greater than start date', issue.errors.full_messages assert_include 'Due date must be greater than start date', issue.errors.full_messages
end 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 def test_estimated_hours_should_be_validated
set_language_if_valid 'en' set_language_if_valid 'en'
['-2'].each do |invalid| ['-2'].each do |invalid|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment