fix show_from not being clear when a todo comes from tickler

This commit is contained in:
Reinier Balt 2013-09-05 12:21:43 +02:00
parent 6e654c5d03
commit cb46a8461e
3 changed files with 47 additions and 12 deletions

View file

@ -73,7 +73,7 @@ class Todo < ActiveRecord::Base
state :active
state :project_hidden
state :completed, :before_enter => Proc.new { |t| t.completed_at = Time.zone.now }, :before_exit => Proc.new { |t| t.completed_at = nil}
state :deferred, :after_exit => Proc.new { |t| t[:show_from] = nil }
state :deferred, :before_exit => Proc.new { |t| t[:show_from] = nil }
state :pending
event :defer do

View file

@ -406,6 +406,10 @@ class TodosControllerTest < ActionController::TestCase
assert_equal context.id, todo.reload.context.id, 'context of todo should be changed'
end
#######
# defer
#######
def test_update_clearing_show_from_makes_todo_active
t = Todo.find(1)
t.show_from = "01/01/2030"
@ -427,6 +431,31 @@ class TodosControllerTest < ActionController::TestCase
assert_not_nil t.show_from
end
def test_find_and_activate_ready
login_as(:admin_user)
# given a todo in the tickler that should be activated
Timecop.travel(2.weeks.ago) do
create_todo(
description: "tickler",
show_from: 1.week.from_now.
in_time_zone(users(:admin_user).prefs.time_zone).
strftime("#{users(:admin_user).prefs.date_format}"))
end
todos = Todo.where(description: "tickler").where('show_from < ?', Time.zone.now)
assert_equal 1, todos.count, "there should be one todo in tickler"
todo = todos.first
assert todo.deferred?, "todo should be in deferred state"
# index page calls find_and_activate_ready
get :index
todo.reload
assert todo.active?, "todo should have been activated"
assert todo.show_from.nil?, "show_from date should have been cleared"
end
#######
# feeds
@ -954,7 +983,7 @@ class TodosControllerTest < ActionController::TestCase
put :create, _source_view: params[:_source_view],
context_name: params[:context_name], project_name: params[:project_name], tag_list: params[:tag_list],
todo: {notes: params[:notes], description: params[:description], due: params[:due]}
todo: {notes: params[:notes], description: params[:description], due: params[:due], show_from: params[:show_from]}
end
end

View file

@ -160,17 +160,23 @@ class TodoTest < ActiveSupport::TestCase
end
def test_activate_also_clears_show_from
# setup test case
t = @not_completed1
t.show_from = 1.week.from_now
t.save!
assert t.deferred?
t.reload
dates = [1.week.from_now, 1.week.ago]
# activate and check show_from
t.activate!
assert t.active?
assert t.show_from.nil?
dates.each do |show_from_date|
# setup test case
t = @not_completed1
Timecop.travel(show_from_date - 1.day) do
t.show_from = show_from_date
t.save!
assert t.deferred?
t.reload
end
# activate and check show_from
t.activate!
assert t.active?
assert t.show_from.nil?
end
end
def test_clearing_show_from_activates_todo