mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
fix show_from not being clear when a todo comes from tickler
This commit is contained in:
parent
6e654c5d03
commit
cb46a8461e
3 changed files with 47 additions and 12 deletions
|
|
@ -73,7 +73,7 @@ class Todo < ActiveRecord::Base
|
||||||
state :active
|
state :active
|
||||||
state :project_hidden
|
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 :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
|
state :pending
|
||||||
|
|
||||||
event :defer do
|
event :defer do
|
||||||
|
|
|
||||||
|
|
@ -406,6 +406,10 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
assert_equal context.id, todo.reload.context.id, 'context of todo should be changed'
|
assert_equal context.id, todo.reload.context.id, 'context of todo should be changed'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#######
|
||||||
|
# defer
|
||||||
|
#######
|
||||||
|
|
||||||
def test_update_clearing_show_from_makes_todo_active
|
def test_update_clearing_show_from_makes_todo_active
|
||||||
t = Todo.find(1)
|
t = Todo.find(1)
|
||||||
t.show_from = "01/01/2030"
|
t.show_from = "01/01/2030"
|
||||||
|
|
@ -427,6 +431,31 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
assert_not_nil t.show_from
|
assert_not_nil t.show_from
|
||||||
end
|
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
|
# feeds
|
||||||
|
|
@ -954,7 +983,7 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
put :create, _source_view: params[:_source_view],
|
put :create, _source_view: params[:_source_view],
|
||||||
context_name: params[:context_name], project_name: params[:project_name], tag_list: params[:tag_list],
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -160,17 +160,23 @@ class TodoTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_activate_also_clears_show_from
|
def test_activate_also_clears_show_from
|
||||||
# setup test case
|
dates = [1.week.from_now, 1.week.ago]
|
||||||
t = @not_completed1
|
|
||||||
t.show_from = 1.week.from_now
|
|
||||||
t.save!
|
|
||||||
assert t.deferred?
|
|
||||||
t.reload
|
|
||||||
|
|
||||||
# activate and check show_from
|
dates.each do |show_from_date|
|
||||||
t.activate!
|
# setup test case
|
||||||
assert t.active?
|
t = @not_completed1
|
||||||
assert t.show_from.nil?
|
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
|
end
|
||||||
|
|
||||||
def test_clearing_show_from_activates_todo
|
def test_clearing_show_from_activates_todo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue