Make activated todo in hidden project stay hidden

Fixes #1417
This commit is contained in:
Dan Rice 2014-09-08 22:50:07 -04:00
parent 1d97d3cd46
commit a450e09681
2 changed files with 29 additions and 1 deletions

View file

@ -76,9 +76,10 @@ class Todo < ActiveRecord::Base
aasm.event :activate do
transitions :to => :active, :from => [:project_hidden, :deferred]
transitions :to => :active, :from => [:completed], :guard => :no_uncompleted_predecessors?
transitions :to => :active, :from => [:pending], :guard => :no_uncompleted_predecessors_or_deferral?
transitions :to => :active, :from => [:pending], :guard => :guard_for_transition_from_pending_to_active
transitions :to => :pending, :from => [:completed], :guard => :uncompleted_predecessors?
transitions :to => :deferred, :from => [:pending], :guard => :guard_for_transition_from_pending_to_deferred
transitions :to => :project_hidden, :from => [:pending], :guard => :guard_for_transition_from_pending_to_project_hidden
end
aasm.event :hide do
@ -142,10 +143,18 @@ class Todo < ActiveRecord::Base
return !uncompleted_predecessors.all.empty?
end
def guard_for_transition_from_pending_to_active
no_uncompleted_predecessors_or_deferral? && not_part_of_hidden_container?
end
def guard_for_transition_from_pending_to_deferred
no_uncompleted_predecessors? && not_part_of_hidden_container?
end
def guard_for_transition_from_pending_to_project_hidden
no_uncompleted_predecessors? && part_of_hidden_container?
end
def part_of_hidden_container?
(self.project && self.project.hidden?) || self.context.hidden?
end

View file

@ -244,6 +244,25 @@ class TodoTest < ActiveSupport::TestCase
assert todo.reload.hidden?, "todo should be put back in hidden state"
end
def test_dependent_todo_in_hidden_project_remains_hidden
todo = todos(:call_bill)
project=todo.project
project.hide!
assert todo.reload.hidden?, "todo in hidden project should be hidden"
todo2 = todos(:call_dino_ext)
todo.add_predecessor(todo2)
todo.block!
assert todo.pending?, "todo with predecessor should be blocked"
todo2.toggle_completion!
todo.activate!
assert todo.reload.hidden?, "todo should be put back in hidden state"
end
def test_todo_specification_handles_null_project
# @not_completed1 has a project
todo_desc = @not_completed1.description