diff options
author | Eric Chapweske <eric@chapweske.com> | 2009-10-17 12:37:15 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-10-17 12:37:15 -0500 |
commit | f936a1f100e75082081e782e5cceb272885c2df7 (patch) | |
tree | 6c5091faa38f15765b3be153141b81d693b02d18 /activerecord/test/cases/types/time_with_zone_test.rb | |
parent | e13d232150921cdf0ec3d713caefa628d235152e (diff) | |
download | rails-f936a1f100e75082081e782e5cceb272885c2df7.tar.gz rails-f936a1f100e75082081e782e5cceb272885c2df7.tar.bz2 rails-f936a1f100e75082081e782e5cceb272885c2df7.zip |
Refactoring attributes/types [#3348 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activerecord/test/cases/types/time_with_zone_test.rb')
-rw-r--r-- | activerecord/test/cases/types/time_with_zone_test.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/activerecord/test/cases/types/time_with_zone_test.rb b/activerecord/test/cases/types/time_with_zone_test.rb new file mode 100644 index 0000000000..b3de79a6c8 --- /dev/null +++ b/activerecord/test/cases/types/time_with_zone_test.rb @@ -0,0 +1,42 @@ +require "cases/helper" + +class TimeWithZoneTest < ActiveRecord::TestCase + + def setup + @column = ActiveRecord::ConnectionAdapters::Column.new('created_at', 0, 'datetime') + @time_with_zone = ActiveRecord::Type::TimeWithZone.new(@column) + end + + test "typecast" do + Time.use_zone("Pacific Time (US & Canada)") do + time_string = "2009-10-07 21:29:10" + time = Time.zone.parse(time_string) + + # assert_equal time, @time_with_zone.cast(time_string) + assert_equal nil, @time_with_zone.cast('') + assert_equal nil, @time_with_zone.cast(nil) + + assert_equal time, @time_with_zone.precast(time) + assert_equal time, @time_with_zone.precast(time_string) + assert_equal time, @time_with_zone.precast(time.to_time) + # assert_equal "#{time.to_date.to_s} 00:00:00 -0700", @time_with_zone.precast(time.to_date).to_s + end + end + + test "cast as boolean" do + Time.use_zone('Central Time (US & Canada)') do + time = Time.zone.now + + assert_equal true, @time_with_zone.boolean(time) + assert_equal true, @time_with_zone.boolean(time.to_date) + assert_equal true, @time_with_zone.boolean(time.to_time) + + assert_equal true, @time_with_zone.boolean(time.to_s) + assert_equal true, @time_with_zone.boolean(time.to_date.to_s) + assert_equal true, @time_with_zone.boolean(time.to_time.to_s) + + assert_equal false, @time_with_zone.boolean('') + end + end + +end |