2011-06-06 14:17:44 -04:00
|
|
|
require "cases/helper"
|
2008-01-18 02:31:37 -05:00
|
|
|
require 'models/topic'
|
|
|
|
require 'models/task'
|
2006-05-07 03:52:08 -04:00
|
|
|
|
2008-01-21 12:20:51 -05:00
|
|
|
class DateTimeTest < ActiveRecord::TestCase
|
2007-05-28 01:55:27 -04:00
|
|
|
def test_saves_both_date_and_time
|
2010-09-20 15:15:18 -04:00
|
|
|
with_env_tz 'America/New_York' do
|
2013-10-24 15:26:23 -04:00
|
|
|
with_timezone_config default: :utc do
|
2010-09-20 15:15:18 -04:00
|
|
|
time_values = [1807, 2, 10, 15, 30, 45]
|
|
|
|
# create DateTime value with local time zone offset
|
2012-12-11 08:57:05 -05:00
|
|
|
local_offset = Rational(Time.local(*time_values).utc_offset, 86400)
|
2010-09-20 15:15:18 -04:00
|
|
|
now = DateTime.civil(*(time_values + [local_offset]))
|
2007-05-29 04:29:33 -04:00
|
|
|
|
2010-09-20 15:15:18 -04:00
|
|
|
task = Task.new
|
|
|
|
task.starting = now
|
|
|
|
task.save!
|
2008-01-18 02:30:42 -05:00
|
|
|
|
2012-12-11 08:57:05 -05:00
|
|
|
# check against Time.local, since some platforms will return a Time instead of a DateTime
|
|
|
|
assert_equal Time.local(*time_values), Task.find(task.id).starting
|
2010-09-20 15:15:18 -04:00
|
|
|
end
|
|
|
|
end
|
2007-05-28 01:55:27 -04:00
|
|
|
end
|
|
|
|
|
2006-05-07 03:52:08 -04:00
|
|
|
def test_assign_empty_date_time
|
|
|
|
task = Task.new
|
|
|
|
task.starting = ''
|
|
|
|
task.ending = nil
|
|
|
|
assert_nil task.starting
|
|
|
|
assert_nil task.ending
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_empty_date
|
|
|
|
topic = Topic.new
|
|
|
|
topic.last_read = ''
|
|
|
|
assert_nil topic.last_read
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_empty_time
|
|
|
|
topic = Topic.new
|
|
|
|
topic.bonus_time = ''
|
|
|
|
assert_nil topic.bonus_time
|
|
|
|
end
|
|
|
|
end
|