mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-20 17:20:12 +01:00
fix #1754
This commit is contained in:
parent
5718eac5c3
commit
0edc263c7e
3 changed files with 11 additions and 13 deletions
|
|
@ -5,5 +5,13 @@ class Dependency < ActiveRecord::Base
|
||||||
belongs_to :predecessor, :foreign_key => 'predecessor_id', :class_name => 'Todo', :touch => true
|
belongs_to :predecessor, :foreign_key => 'predecessor_id', :class_name => 'Todo', :touch => true
|
||||||
belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true
|
belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true
|
||||||
|
|
||||||
|
validate :check_circular_dependencies
|
||||||
|
|
||||||
|
def check_circular_dependencies
|
||||||
|
unless predecessor.nil? or successor.nil?
|
||||||
|
errors.add("Depends on:", "Adding '#{successor.specification}' would create a circular dependency") if successor.is_successor?(predecessor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,6 @@ class Todo < ActiveRecord::Base
|
||||||
validates_presence_of :show_from, :if => :deferred?
|
validates_presence_of :show_from, :if => :deferred?
|
||||||
validates_presence_of :context
|
validates_presence_of :context
|
||||||
validate :check_show_from_in_future
|
validate :check_show_from_in_future
|
||||||
validate :check_circular_dependencies
|
|
||||||
|
|
||||||
def check_show_from_in_future
|
def check_show_from_in_future
|
||||||
if show_from_changed? # only check on change of show_from
|
if show_from_changed? # only check on change of show_from
|
||||||
|
|
@ -125,14 +124,6 @@ class Todo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_circular_dependencies
|
|
||||||
unless @predecessor_array.nil? # Only validate predecessors if they changed
|
|
||||||
@predecessor_array.each do |todo|
|
|
||||||
errors.add("Depends on:", "Adding '#{todo.specification}' would create a circular dependency") if is_successor?(todo)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super(*args)
|
super(*args)
|
||||||
@predecessor_array = nil # Used for deferred save of predecessors
|
@predecessor_array = nil # Used for deferred save of predecessors
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,9 @@ class TodoTest < ActiveSupport::TestCase
|
||||||
assert_equal 1, @not_completed3.successors.count
|
assert_equal 1, @not_completed3.successors.count
|
||||||
|
|
||||||
# 1 -> 3 -> 2 -> 1 == circle
|
# 1 -> 3 -> 2 -> 1 == circle
|
||||||
@not_completed3.add_predecessor(@not_completed1)
|
assert_raises ActiveRecord::RecordInvalid do
|
||||||
assert !@not_completed3.valid?
|
@not_completed3.add_predecessor(@not_completed1)
|
||||||
error_msg = "Adding ''Call Bill Gates to find out how much he makes per day' <'agenda'; 'Make more money than Billy Gates'>' would create a circular dependency"
|
end
|
||||||
assert_equal error_msg, @not_completed3.errors["Depends on:"][0]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_defer_an_existing_todo
|
def test_defer_an_existing_todo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue