mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-21 21:40:48 +02:00
This fixes failing tests when the timezone is different than utc
There were several problems: * Time.now returns the systems time, not the users time * fixtures do not translate dates from timezone to utc, but stores the date verbatim * calling a controller will set the timezone to the preference of the current_user. So it could be changed while you do not realize this. I fixed the failing test, but problems could be elsewhere
This commit is contained in:
parent
0b44fe3f08
commit
e58379e81f
27 changed files with 221 additions and 214 deletions
|
@ -1071,10 +1071,10 @@ end
|
|||
if recurring_todo.todos.active.count == 0
|
||||
|
||||
# check for next todo either from the due date or the show_from date
|
||||
date_to_check = todo.due.nil? ? todo.show_from : todo.due
|
||||
date_to_check = todo.due || todo.show_from
|
||||
|
||||
# if both due and show_from are nil, check for a next todo from now
|
||||
date_to_check = Time.zone.now if date_to_check.nil?
|
||||
date_to_check ||= Time.zone.now
|
||||
|
||||
if recurring_todo.active? && recurring_todo.continues_recurring?(date_to_check)
|
||||
|
||||
|
@ -1087,7 +1087,7 @@ end
|
|||
# for tomorrow.
|
||||
date = date_to_check.at_midnight >= Time.zone.now.at_midnight ? date_to_check : Time.zone.now-1.day
|
||||
|
||||
new_recurring_todo = TodoFromRecurringTodo.new(current_user, recurring_todo).create(date.at_midnight)
|
||||
new_recurring_todo = TodoFromRecurringTodo.new(current_user, recurring_todo).create(date)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module StatsHelper
|
|||
end
|
||||
|
||||
def month_and_year_label(i)
|
||||
t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]+ " " + (Time.now - i.months).year.to_s
|
||||
t('date.month_names')[ (Time.zone.now.mon - i -1 ) % 12 + 1 ]+ " " + (Time.zone.now - i.months).year.to_s
|
||||
end
|
||||
|
||||
def array_of_month_and_year_labels(count)
|
||||
|
@ -13,7 +13,7 @@ module StatsHelper
|
|||
end
|
||||
|
||||
def month_label(i)
|
||||
t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]
|
||||
t('date.month_names')[ (Time.zone.now.mon - i -1 ) % 12 + 1 ]
|
||||
end
|
||||
|
||||
def array_of_month_labels(count)
|
||||
|
|
|
@ -151,7 +151,7 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def get_next_date(previous)
|
||||
raise "Should not call AbstractRecurrencePattern.get_next_date directly. Overwrite in subclass"
|
||||
raise "Should not call AbstractRecurrencePattern.get_next_date directly. Override in subclass"
|
||||
end
|
||||
|
||||
def continues_recurring?(previous)
|
||||
|
@ -174,13 +174,13 @@ module RecurringTodos
|
|||
# same day as the previous
|
||||
def determine_start(previous, offset=0.day)
|
||||
start = self.start_from || NullTime.new
|
||||
now = Time.zone.now
|
||||
if previous
|
||||
# check if the start_from date is later than previous. If so, use
|
||||
# start_from as start to search for next date
|
||||
start > previous ? start : previous + offset
|
||||
else
|
||||
# skip to present
|
||||
now = Time.zone.now
|
||||
start > now ? start : now
|
||||
end
|
||||
end
|
||||
|
@ -199,32 +199,24 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def find_last_day_x_of_month(weekday, month, year)
|
||||
# count backwards. use UTC to avoid strange timezone oddities
|
||||
# where last_day -= 1.day seems to shift tz+0100 to tz+0000
|
||||
last_day = Time.utc(year, month, Time.days_in_month(month))
|
||||
last_day = Time.zone.local(year, month, Time.days_in_month(month))
|
||||
while last_day.wday != weekday
|
||||
last_day -= 1.day
|
||||
end
|
||||
# convert back to local timezone
|
||||
Time.zone.local(last_day.year, last_day.month, last_day.day)
|
||||
last_day
|
||||
end
|
||||
|
||||
def find_xth_day_of_month(x, weekday, month, year)
|
||||
# 1-4th -> count upwards last -> count backwards. use UTC to avoid strange
|
||||
# timezone oddities where last_day -= 1.day seems to shift tz+0100 to
|
||||
# tz+0000
|
||||
start = Time.utc(year,month,1)
|
||||
start = Time.zone.local(year,month,1)
|
||||
n = x
|
||||
while n > 0
|
||||
while start.wday() != weekday
|
||||
start+= 1.day
|
||||
start += 1.day
|
||||
end
|
||||
n -= 1
|
||||
start+= 1.day unless n==0
|
||||
start += 1.day unless n==0
|
||||
end
|
||||
# convert back to local timezone
|
||||
Time.zone.local(start.year, start.month, start.day)
|
||||
start
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,18 +82,9 @@ module RecurringTodos
|
|||
def find_specific_day_of_month(previous, start, n)
|
||||
if (previous && start.mday >= every_x_day) || (previous.nil? && start.mday > every_x_day)
|
||||
# there is no next day n in this month, search in next month
|
||||
#
|
||||
# start += n.months
|
||||
#
|
||||
# The above seems to not work. Fiddle with timezone. Looks like we hit a
|
||||
# bug in rails here where 2008-12-01 +0100 plus 1.month becomes
|
||||
# 2008-12-31 +0100. For now, just calculate in UTC and convert back to
|
||||
# local timezone.
|
||||
#
|
||||
# TODO: recheck if future rails versions have this problem too
|
||||
start = Time.utc(start.year, start.month, start.day)+n.months
|
||||
start += n.months
|
||||
end
|
||||
Time.zone.local(start.year, start.month, every_x_day)
|
||||
start.in_time_zone.change(day: every_x_day)
|
||||
end
|
||||
|
||||
def find_relative_day_of_month(start, n)
|
||||
|
@ -101,13 +92,7 @@ module RecurringTodos
|
|||
if the_next.nil? || the_next <= start
|
||||
# the nth day is already passed in this month, go to next month and try
|
||||
# again
|
||||
|
||||
# fiddle with timezone. Looks like we hit a bug in rails here where
|
||||
# 2008-12-01 +0100 plus 1.month becomes 2008-12-31 +0100. For now, just
|
||||
# calculate in UTC and convert back to local timezone.
|
||||
# TODO: recheck if future rails versions have this problem too
|
||||
the_next = Time.utc(the_next.year, the_next.month, the_next.day)+n.months
|
||||
the_next = Time.zone.local(the_next.year, the_next.month, the_next.day)
|
||||
the_next += n.months
|
||||
|
||||
# TODO: if there is still no match, start will be set to nil. if we ever
|
||||
# support 5th day of the month, we need to handle this case
|
||||
|
@ -136,7 +121,5 @@ module RecurringTodos
|
|||
day: day_of_week_as_text(day_of_week),
|
||||
n_months: n_months)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ module Stats
|
|||
end
|
||||
|
||||
def first_action_at
|
||||
first_action.created_at if first_action
|
||||
first_action.try(:created_at)
|
||||
end
|
||||
|
||||
def projects
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<% if @count -%>
|
||||
<span id="badge_count" class="badge"><%= @count %></span>
|
||||
<% end -%>
|
||||
<%= l(Date.today, :format => current_user.prefs.title_date_format) %>
|
||||
<%= l(Time.zone.today, :format => current_user.prefs.title_date_format) %>
|
||||
</h1>
|
||||
</div>
|
||||
<div id="minilinks">
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
</head><body>
|
||||
<% if current_user && !current_user.prefs.nil? -%>
|
||||
<div id="topbar"><h1><% if @down_count -%><span class="count" id="badge_count"><%= @down_count %></span><% end -%> <%=
|
||||
l(Date.today, :format => current_user.prefs.title_date_format) -%></h1>
|
||||
l(Time.zone.today, :format => current_user.prefs.title_date_format) -%></h1>
|
||||
<ul class="nav">
|
||||
<li class="link"><%= (link_to(t('layouts.mobile_navigation.new_action'), new_todo_path(new_todo_params))) -%></li>
|
||||
<li class="link"><%= (link_to(t('layouts.mobile_navigation.home'), todos_path(:format => 'm'))) -%></li>
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
<%= pref_with_text_field('prefs', 'date_format') %>
|
||||
|
||||
<div class='prefs_example'>This will result in: <span id='prefs.date_format'><%= l(Date.today, :format => current_user.prefs.date_format) %></span></div>
|
||||
<div class='prefs_example'>This will result in: <span id='prefs.date_format'><%= l(Time.zone.today, :format => current_user.prefs.date_format) %></span></div>
|
||||
<br/>
|
||||
Or pick one of the following:<br/>
|
||||
<% %w{default short long longer}.each do |format| %>
|
||||
<%= radio_button_tag("date_picker1", t("date.formats.#{format}")) %> <%= l(Date.today, :format => format.to_sym) %> <br/>
|
||||
<%= radio_button_tag("date_picker1", t("date.formats.#{format}")) %> <%= l(Time.zone.today, :format => format.to_sym) %> <br/>
|
||||
<% end %>
|
||||
<br/>
|
||||
|
||||
<%= pref_with_text_field('prefs', 'title_date_format') %>
|
||||
<div class='prefs_example'>This will result in: <span id='prefs.title_date_format'><%= l(Date.today, :format => current_user.prefs.title_date_format) %></span></div>
|
||||
<div class='prefs_example'>This will result in: <span id='prefs.title_date_format'><%= l(Time.zone.today, :format => current_user.prefs.title_date_format) %></span></div>
|
||||
<br/>
|
||||
Or pick one of the following:<br/>
|
||||
<% %w{default short long longer}.each do |format| %>
|
||||
<%= radio_button_tag("date_picker2", t("date.formats.#{format}")) %> <%= l(Date.today, :format => format.to_sym) %> <br/>
|
||||
<%= radio_button_tag("date_picker2", t("date.formats.#{format}")) %> <%= l(Time.zone.today, :format => format.to_sym) %> <br/>
|
||||
<% end %>
|
||||
<br/>
|
||||
|
||||
<%= pref('prefs', 'time_zone') { time_zone_select('prefs','time_zone') } %>
|
||||
|
||||
<%= pref_with_select_field('prefs', "week_starts", (0..6).to_a.map {|num| [t('date.day_names')[num], num] }) %>
|
||||
|
||||
|
|
|
@ -34,8 +34,6 @@ Rails.application.configure do
|
|||
# Print deprecation notices to the stderr.
|
||||
config.active_support.deprecation = :stderr
|
||||
|
||||
config.time_zone = 'UTC'
|
||||
|
||||
# Raises error for missing translations
|
||||
# config.action_view.raise_on_missing_translations = true
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ class TodoFromRecurringTodo
|
|||
end
|
||||
|
||||
def end_date
|
||||
todo.due ? todo.due : todo.show_from
|
||||
todo.due || todo.show_from
|
||||
end
|
||||
|
||||
def attributes
|
||||
|
|
|
@ -203,7 +203,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
|
||||
# change due date in four days from now and show from 10 days before, i.e. 6
|
||||
# days ago
|
||||
target_date = Time.now.utc + 4.days
|
||||
target_date = Time.zone.now + 4.days
|
||||
@yearly.every_other1 = target_date.day
|
||||
@yearly.every_other2 = target_date.month
|
||||
@yearly.show_from_delta = 10
|
||||
|
|
|
@ -45,11 +45,14 @@ class StatsControllerTest < ActionController::TestCase
|
|||
def test_totals
|
||||
login_as(:admin_user)
|
||||
get :index
|
||||
|
||||
assert_response :success
|
||||
totals = assigns['stats'].totals
|
||||
assert_equal 4, totals.tags
|
||||
assert_equal 2, totals.unique_tags
|
||||
assert_equal 2.week.ago.utc.at_midnight, totals.first_action_at.utc.at_midnight
|
||||
|
||||
Time.zone = users(:admin_user).prefs.time_zone # calculations are done in users timezone
|
||||
assert_equal 2.weeks.ago.at_midnight, totals.first_action_at.at_midnight
|
||||
end
|
||||
|
||||
def test_downdrill
|
||||
|
|
|
@ -715,17 +715,25 @@ class TodosControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
def test_toggle_check_on_rec_todo_show_from_today
|
||||
# warning: the Time.zone set in site.yml will be overwritten by
|
||||
# :admin_user.prefs.time_zone in ApplicationController. This messes with
|
||||
# the calculation. So set time_zone to admin_user's time_zone setting
|
||||
Time.zone = users(:admin_user).prefs.time_zone
|
||||
|
||||
travel_to Time.zone.local(2014, 1, 15) do
|
||||
today = Time.zone.now.at_midnight
|
||||
|
||||
login_as(:admin_user)
|
||||
|
||||
# link todo_1 and recurring_todo_1
|
||||
recurring_todo_1 = RecurringTodo.find(1)
|
||||
todo_1 = Todo.where(:recurring_todo_id => 1).first
|
||||
today = Time.zone.now.at_midnight
|
||||
todo_1.due = today
|
||||
assert todo_1.save
|
||||
|
||||
# change recurrence pattern to monthly and set show_from to today
|
||||
# change recurrence pattern to monthly on a specific
|
||||
# day (recurrence_selector=0) and set show_from
|
||||
# (every_other2=1) to today
|
||||
recurring_todo_1.target = 'show_from_date'
|
||||
recurring_todo_1.recurring_period = 'monthly'
|
||||
recurring_todo_1.recurrence_selector = 0
|
||||
|
@ -746,15 +754,13 @@ class TodosControllerTest < ActionController::TestCase
|
|||
assert_not_equal todo_1.id, new_todo.id, "check that the new todo is not the same as todo_1"
|
||||
assert !new_todo.show_from.nil?, "check that the new_todo is in the tickler to show next month"
|
||||
|
||||
# do not use today here. It somehow gets messed up with the timezone calculation.
|
||||
next_month = (Time.zone.now + 1.month).at_midnight
|
||||
|
||||
assert_equal next_month.utc.to_date.to_s(:db), new_todo.show_from.utc.to_date.to_s(:db)
|
||||
assert_equal today + 1.month, new_todo.show_from
|
||||
end
|
||||
end
|
||||
|
||||
def test_check_for_next_todo
|
||||
login_as :admin_user
|
||||
Time.zone = users(:admin_user).prefs.time_zone
|
||||
|
||||
tomorrow = Time.zone.now + 1.day
|
||||
|
||||
|
@ -791,6 +797,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
|
||||
def test_check_for_next_todo_monthly
|
||||
login_as :admin_user
|
||||
Time.zone = users(:admin_user).prefs.time_zone
|
||||
|
||||
tomorrow = Time.zone.now + 1.day
|
||||
|
||||
|
|
5
test/fixtures/contexts.yml
vendored
5
test/fixtures/contexts.yml
vendored
|
@ -1,8 +1,11 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# Please note that dates in yml are not converted to utc timezone like
|
||||
# rails does automatically in models or controllers! Convert to utc manually!
|
||||
<%
|
||||
|
||||
def today
|
||||
Time.now.utc.to_s(:db)
|
||||
Time.zone.now.utc.to_s(:db)
|
||||
end
|
||||
|
||||
%>
|
||||
|
|
5
test/fixtures/notes.yml
vendored
5
test/fixtures/notes.yml
vendored
|
@ -1,7 +1,10 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# Please note that dates in yml are not converted to utc timezone like
|
||||
# rails does automatically in models or controllers! Convert to utc manually!
|
||||
<%
|
||||
def today
|
||||
Time.now.utc.to_s(:db)
|
||||
Time.zone.now.utc.to_s(:db)
|
||||
end
|
||||
|
||||
def next_week
|
||||
|
|
5
test/fixtures/projects.yml
vendored
5
test/fixtures/projects.yml
vendored
|
@ -1,7 +1,10 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# Please note that dates in yml are not converted to utc timezone like
|
||||
# rails does automatically in models or controllers! Convert to utc manually!
|
||||
<%
|
||||
def today
|
||||
Time.zone.now.beginning_of_day.to_s(:db)
|
||||
Time.zone.now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
%>
|
||||
|
||||
|
|
15
test/fixtures/recurring_todos.yml
vendored
15
test/fixtures/recurring_todos.yml
vendored
|
@ -1,26 +1,29 @@
|
|||
# Please note that dates in yml are not converted to utc timezone like
|
||||
# rails does automatically in models or controllers! Convert to utc manually!
|
||||
|
||||
<%
|
||||
def today
|
||||
Time.zone.now.beginning_of_day.to_s(:db)
|
||||
Time.zone.now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def next_week
|
||||
1.week.from_now.beginning_of_day.to_s(:db)
|
||||
1.week.from_now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def last_week
|
||||
1.week.ago.beginning_of_day.to_s(:db)
|
||||
1.week.ago.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def two_weeks_ago
|
||||
2.weeks.ago.beginning_of_day.to_s(:db)
|
||||
2.weeks.ago.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def two_weeks_hence
|
||||
2.weeks.from_now.beginning_of_day.to_s(:db)
|
||||
2.weeks.from_now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def way_back
|
||||
Time.zone.local(2008,1,1).to_s(:db)
|
||||
Time.zone.local(2008,1,1).utc.to_s(:db)
|
||||
end
|
||||
|
||||
%>
|
||||
|
|
22
test/fixtures/tags.yml
vendored
22
test/fixtures/tags.yml
vendored
|
@ -1,17 +1,27 @@
|
|||
# please note that dates in yml are not converted to utc timezone like
|
||||
# rails does automatically in models or controllers! Convert to utc manually!
|
||||
|
||||
<%
|
||||
def today
|
||||
Time.zone.now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
%>
|
||||
|
||||
foo:
|
||||
id: 1
|
||||
name: foo
|
||||
created_at: <%= Time.now.utc.to_s(:db) %>
|
||||
updated_at: <%= Time.now.utc.to_s(:db) %>
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
bar:
|
||||
id: 2
|
||||
name: bar
|
||||
created_at: <%= Time.now.utc.to_s(:db) %>
|
||||
updated_at: <%= Time.now.utc.to_s(:db) %>
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
baz:
|
||||
id: 3
|
||||
name: baz
|
||||
created_at: <%= Time.now.utc.to_s(:db) %>
|
||||
updated_at: <%= Time.now.utc.to_s(:db) %>
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
|
|
18
test/fixtures/todos.yml
vendored
18
test/fixtures/todos.yml
vendored
|
@ -1,26 +1,27 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# Please note that dates in yml are not converted to utc timezone like
|
||||
# rails does automatically in models or controllers! Convert to utc manually!
|
||||
|
||||
<%
|
||||
|
||||
Time.zone = SITE_CONFIG['time_zone']
|
||||
|
||||
def today
|
||||
Time.zone.now.beginning_of_day.to_s(:db)
|
||||
Time.zone.now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def next_week
|
||||
1.week.from_now.beginning_of_day.to_s(:db)
|
||||
1.week.from_now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def last_week
|
||||
1.week.ago.beginning_of_day.to_s(:db)
|
||||
1.week.ago.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def two_weeks_ago
|
||||
2.weeks.ago.beginning_of_day.to_s(:db)
|
||||
2.weeks.ago.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def two_weeks_hence
|
||||
2.weeks.from_now.beginning_of_day.to_s(:db)
|
||||
2.weeks.from_now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
%>
|
||||
|
@ -254,4 +255,3 @@ email_broker:
|
|||
description: Ask about better stocks
|
||||
notes: ~
|
||||
state: pending
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
assert_equal :completed, @timemachine.aasm.current_state
|
||||
assert @timemachine.completed?
|
||||
assert_not_nil @timemachine.completed_at, "completed_at not expected to be nil"
|
||||
assert_in_delta Time.now, @timemachine.completed_at, 1
|
||||
assert_in_delta Time.zone.now, @timemachine.completed_at, 1
|
||||
end
|
||||
|
||||
def test_delete_project_deletes_todos_within_it
|
||||
|
@ -254,5 +254,4 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
p.reload
|
||||
assert_equal 4, p.running_time
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class RecurringTodoTest < ActiveSupport::TestCase
|
|||
@every_month = @monthly_every_last_friday
|
||||
@yearly = recurring_todos(:birthday_reinier)
|
||||
|
||||
@today = Time.now.utc
|
||||
@today = Time.zone.now
|
||||
@tomorrow = @today + 1.day
|
||||
@in_three_days = @today + 3.days
|
||||
@in_four_days = @in_three_days + 1.day # need a day after start_from
|
||||
|
@ -63,19 +63,19 @@ class RecurringTodoTest < ActiveSupport::TestCase
|
|||
#
|
||||
# start_from is way_back
|
||||
due_date1 = @yearly.get_due_date(nil)
|
||||
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
|
||||
due_date2 = @yearly.get_due_date(Time.zone.now + 1.day)
|
||||
assert_equal due_date1, due_date2
|
||||
|
||||
# start_from is in the future
|
||||
@yearly.start_from = Time.now.utc + 1.week
|
||||
@yearly.start_from = Time.zone.now + 1.week
|
||||
due_date1 = @yearly.get_due_date(nil)
|
||||
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
|
||||
due_date2 = @yearly.get_due_date(Time.zone.now + 1.day)
|
||||
assert_equal due_date1, due_date2
|
||||
|
||||
# start_from is nil
|
||||
@yearly.start_from = nil
|
||||
due_date1 = @yearly.get_due_date(nil)
|
||||
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
|
||||
due_date2 = @yearly.get_due_date(Time.zone.now + 1.day)
|
||||
assert_equal due_date1, due_date2
|
||||
end
|
||||
|
||||
|
@ -117,7 +117,7 @@ class RecurringTodoTest < ActiveSupport::TestCase
|
|||
assert_equal Time.zone.local(2021,6,8), @yearly.get_due_date(Time.zone.local(2019,6,1)) # also next year
|
||||
assert_equal Time.zone.local(2021,6,8), @yearly.get_due_date(Time.zone.local(2020,6,15)) # also next year
|
||||
|
||||
this_year = Time.now.utc.year
|
||||
this_year = Time.zone.now.utc.year
|
||||
@yearly.start_from = Time.zone.local(this_year+1,6,12)
|
||||
due_date = @yearly.get_due_date(nil)
|
||||
assert_equal due_date.year, this_year+2
|
||||
|
|
|
@ -121,9 +121,9 @@ module RecurringTodos
|
|||
def test_determine_start
|
||||
travel_to Time.zone.local(2013,1,1) do
|
||||
rt = create_recurring_todo
|
||||
assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil).to_s(:db), "no previous date, use today"
|
||||
assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil, 1.day).to_s(:db), "no previous date, use today without offset"
|
||||
assert_equal "2013-01-02 00:00:00", rt.send(:determine_start, Time.zone.now, 1.day).to_s(:db), "use previous date and offset"
|
||||
assert_equal Time.zone.parse("2013-01-01 00:00:00"), rt.send(:determine_start, nil), "no previous date, use today"
|
||||
assert_equal Time.zone.parse("2013-01-01 00:00:00"), rt.send(:determine_start, nil, 1.day).to_s(:db), "no previous date, use today without offset"
|
||||
assert_equal Time.zone.parse("2013-01-02 00:00:00"), rt.send(:determine_start, Time.zone.now, 1.day).to_s(:db), "use previous date and offset"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -131,14 +131,14 @@ module RecurringTodos
|
|||
rt = create_recurring_todo
|
||||
|
||||
# march 2014 has 5 saturdays, the last will return the 5th
|
||||
assert_equal "2014-03-01 00:00:00", rt.send(:get_xth_day_of_month, 1, 6, 3, 2014).to_s(:db)
|
||||
assert_equal "2014-03-22 00:00:00", rt.send(:get_xth_day_of_month, 4, 6, 3, 2014).to_s(:db)
|
||||
assert_equal "2014-03-29 00:00:00", rt.send(:get_xth_day_of_month, 5, 6, 3, 2014).to_s(:db)
|
||||
assert_equal Time.zone.parse("2014-03-01 00:00:00"), rt.send(:get_xth_day_of_month, 1, 6, 3, 2014).to_s(:db)
|
||||
assert_equal Time.zone.parse("2014-03-22 00:00:00"), rt.send(:get_xth_day_of_month, 4, 6, 3, 2014).to_s(:db)
|
||||
assert_equal Time.zone.parse("2014-03-29 00:00:00"), rt.send(:get_xth_day_of_month, 5, 6, 3, 2014).to_s(:db)
|
||||
|
||||
# march 2014 has 4 fridays, the last will return the 4th
|
||||
assert_equal "2014-03-07 00:00:00", rt.send(:get_xth_day_of_month, 1, 5, 3, 2014).to_s(:db)
|
||||
assert_equal "2014-03-28 00:00:00", rt.send(:get_xth_day_of_month, 4, 5, 3, 2014).to_s(:db)
|
||||
assert_equal "2014-03-28 00:00:00", rt.send(:get_xth_day_of_month, 5, 5, 3, 2014).to_s(:db)
|
||||
assert_equal Time.zone.parse("2014-03-07 00:00:00"), rt.send(:get_xth_day_of_month, 1, 5, 3, 2014).to_s(:db)
|
||||
assert_equal Time.zone.parse("2014-03-28 00:00:00"), rt.send(:get_xth_day_of_month, 4, 5, 3, 2014).to_s(:db)
|
||||
assert_equal Time.zone.parse("2014-03-28 00:00:00"), rt.send(:get_xth_day_of_month, 5, 5, 3, 2014).to_s(:db)
|
||||
|
||||
assert_raise(RuntimeError, "should check on valid weekdays"){ rt.send(:get_xth_day_of_month, 5, 9, 3, 2014) }
|
||||
assert_raise(RuntimeError, "should check on valid count x"){ rt.send(:get_xth_day_of_month, 6, 5, 3, 2014) }
|
||||
|
|
|
@ -16,14 +16,14 @@ class TodoCreateParamsHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_show_from_accessor
|
||||
expected_date = Time.now
|
||||
expected_date = Time.zone.now
|
||||
params = ActionController::Parameters.new({ 'todo' => { 'show_from' => expected_date}})
|
||||
params_helper = Todos::TodoCreateParamsHelper.new(params, users(:admin_user))
|
||||
assert_equal(expected_date, params_helper.show_from)
|
||||
end
|
||||
|
||||
def test_due_accessor
|
||||
expected_date = Time.now
|
||||
expected_date = Time.zone.now
|
||||
params = ActionController::Parameters.new({ 'todo' => { 'due' => expected_date}})
|
||||
params_helper = Todos::TodoCreateParamsHelper.new(params, users(:admin_user))
|
||||
assert_equal(expected_date, params_helper.due)
|
||||
|
@ -119,5 +119,4 @@ class TodoCreateParamsHelperTest < ActiveSupport::TestCase
|
|||
params_helper = Todos::TodoCreateParamsHelper.new(params, users(:admin_user))
|
||||
assert_equal false, params_helper.context_specified_by_name?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -22,8 +22,8 @@ class TodoTest < ActiveSupport::TestCase
|
|||
assert_equal "Call Bill Gates to find out how much he makes per day", @not_completed1.description
|
||||
assert_nil @not_completed1.notes
|
||||
assert @not_completed1.completed? == false
|
||||
assert_equal 1.week.ago.beginning_of_day.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.beginning_of_day.strftime("%Y-%m-%d %H:%M")
|
||||
assert_equal 2.week.from_now.beginning_of_day.strftime("%Y-%m-%d"), @not_completed1.due.strftime("%Y-%m-%d")
|
||||
assert_equal 1.week.ago.utc.beginning_of_day, @not_completed1.created_at.utc
|
||||
assert_equal 2.week.from_now.utc.beginning_of_day, @not_completed1.due.utc
|
||||
assert_nil @not_completed1.completed_at
|
||||
assert_equal 1, @not_completed1.user_id
|
||||
end
|
||||
|
|
|
@ -206,7 +206,7 @@ class UserTest < ActiveSupport::TestCase
|
|||
|
||||
def test_find_and_activate_deferred_todos_that_are_ready
|
||||
assert_equal 1, @admin_user.deferred_todos.count
|
||||
@admin_user.deferred_todos[0].show_from = Time.now.utc - 5.seconds
|
||||
@admin_user.deferred_todos[0].show_from = Time.zone.now - 5.seconds
|
||||
@admin_user.deferred_todos[0].save(:validate => false)
|
||||
@admin_user.deferred_todos.reload
|
||||
@admin_user.deferred_todos.find_and_activate_ready
|
||||
|
|
|
@ -3,7 +3,12 @@ require File.expand_path('../../config/environment', __FILE__)
|
|||
require 'rails/test_help'
|
||||
|
||||
# set config for tests. Overwrite those read from config/site.yml. Use inject to avoid warning about changing CONSTANT
|
||||
{ "authentication_schemes" => ["database"], "prefered_auth" => "database", "email_dispatch" => nil}.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h }
|
||||
{
|
||||
"authentication_schemes" => ["database"],
|
||||
"prefered_auth" => "database",
|
||||
"email_dispatch" => nil,
|
||||
"time_zone" => "Amsterdam" # force UTC+1 so Travis triggers time zone failures
|
||||
}.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h }
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue