mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-29 21:38:49 +01:00
Merge branch 'master' into new-gui
This commit is contained in:
commit
b0b39433d5
8 changed files with 57 additions and 21 deletions
|
|
@ -48,7 +48,6 @@ class RecurringTodo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def validate_weekly
|
||||
puts "@@@ validate_weekly [#{self.weekly_every_x_week}]"
|
||||
if weekly_every_x_week.blank?
|
||||
errors[:base] << "Every other nth week may not be empty for recurrence setting"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ require 'active_support/all'
|
|||
|
||||
class Staleness
|
||||
SECONDS_PER_DAY = 86400
|
||||
|
||||
def self.days_stale(item, current_user)
|
||||
return 0 if cannot_be_stale(item, current_user)
|
||||
(UserTime.new(current_user).time - item.created_at).to_i / SECONDS_PER_DAY
|
||||
(UserTime.new(current_user).time.utc - item.created_at.utc).to_i / SECONDS_PER_DAY
|
||||
end
|
||||
|
||||
def self.cannot_be_stale(item, current_user)
|
||||
|
|
|
|||
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class PreferenceTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_parse_date
|
||||
date = Time.new(2007, 05, 20).in_time_zone(@admin_user.preference.time_zone).at_midnight
|
||||
date = UserTime.new(@admin_user).midnight(Time.new(2007, 05, 20, 0, 0, 0))
|
||||
assert_equal date.to_s, @admin_user.preference.parse_date('20/5/2007').to_s
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
require_relative '../minimal_test_helper'
|
||||
require_relative '../../lib/staleness'
|
||||
|
||||
require_relative '../../lib/user_time'
|
||||
require 'timecop'
|
||||
|
||||
class StalenessTest < Test::Unit::TestCase
|
||||
FakePrefs = Struct.new(:time_zone)
|
||||
|
|
@ -35,7 +36,7 @@ class StalenessTest < Test::Unit::TestCase
|
|||
|
||||
def setup
|
||||
@current_user = FakeUser.new(now)
|
||||
Timecop.freeze(Time.local(2013,02,28))
|
||||
Timecop.freeze(Time.utc(2013,02,28))
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
|
|
|||
|
|
@ -51,18 +51,18 @@ class TodoTest < ActiveSupport::TestCase
|
|||
|
||||
def test_validate_length_of_description
|
||||
assert_equal "Call dinosaur exterminator", @not_completed2.description
|
||||
@not_completed2.description = generate_random_string(101)
|
||||
@not_completed2.description = generate_random_string(Todo::MAX_DESCRIPTION_LENGTH+1)
|
||||
assert !@not_completed2.save
|
||||
assert_equal 1, @not_completed2.errors.count
|
||||
assert_equal "is too long (maximum is 100 characters)", @not_completed2.errors[:description][0]
|
||||
assert_equal "is too long (maximum is #{Todo::MAX_DESCRIPTION_LENGTH} characters)", @not_completed2.errors[:description][0]
|
||||
end
|
||||
|
||||
def test_validate_length_of_notes
|
||||
assert_equal "Ask him if I need to hire a skip for the corpses.", @not_completed2.notes
|
||||
@not_completed2.notes = generate_random_string(60001)
|
||||
@not_completed2.notes = generate_random_string(Todo::MAX_NOTES_LENGTH+1)
|
||||
assert !@not_completed2.save
|
||||
assert_equal 1, @not_completed2.errors.count
|
||||
assert_equal "is too long (maximum is 60000 characters)", @not_completed2.errors[:notes][0]
|
||||
assert_equal "is too long (maximum is #{Todo::MAX_NOTES_LENGTH} characters)", @not_completed2.errors[:notes][0]
|
||||
end
|
||||
|
||||
def test_validate_show_from_must_be_a_date_in_the_future
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue