Fixes 'follows' relation validation.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3191 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
beb20e7c6e
commit
77aeca5d55
@ -33,14 +33,12 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
validates_presence_of :issue_from, :issue_to, :relation_type
|
validates_presence_of :issue_from, :issue_to, :relation_type
|
||||||
validates_inclusion_of :relation_type, :in => [TYPE_RELATES, TYPE_DUPLICATES, TYPE_BLOCKS, TYPE_PRECEDES]
|
validates_inclusion_of :relation_type, :in => TYPES.keys
|
||||||
validates_numericality_of :delay, :allow_nil => true
|
validates_numericality_of :delay, :allow_nil => true
|
||||||
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
|
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
|
||||||
|
|
||||||
attr_protected :issue_from_id, :issue_to_id
|
attr_protected :issue_from_id, :issue_to_id
|
||||||
|
|
||||||
before_validation :reverse_if_needed
|
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
if issue_from && issue_to
|
if issue_from && issue_to
|
||||||
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
|
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
|
||||||
@ -58,6 +56,8 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def before_save
|
def before_save
|
||||||
|
reverse_if_needed
|
||||||
|
|
||||||
if TYPE_PRECEDES == relation_type
|
if TYPE_PRECEDES == relation_type
|
||||||
self.delay ||= 0
|
self.delay ||= 0
|
||||||
else
|
else
|
||||||
|
@ -43,4 +43,15 @@ class IssueRelationTest < ActiveSupport::TestCase
|
|||||||
assert_equal to, relation.issue_from
|
assert_equal to, relation.issue_from
|
||||||
assert_equal from, relation.issue_to
|
assert_equal from, relation.issue_to
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_follows_relation_should_not_be_reversed_if_validation_fails
|
||||||
|
from = Issue.find(1)
|
||||||
|
to = Issue.find(2)
|
||||||
|
|
||||||
|
relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS, :delay => 'xx'
|
||||||
|
assert !relation.save
|
||||||
|
assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
|
||||||
|
assert_equal from, relation.issue_from
|
||||||
|
assert_equal to, relation.issue_to
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user