From d25471deab03710b0ad3cafc00b45bb66c256860 Mon Sep 17 00:00:00 2001 From: Jerome Stonebridge Date: Mon, 11 Oct 2010 21:05:56 -0700 Subject: [PATCH 1/2] Test for time datatype in activerecord --- activerecord/test/cases/time_test.rb | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) create mode 100644 activerecord/test/cases/time_test.rb diff --git a/activerecord/test/cases/time_test.rb b/activerecord/test/cases/time_test.rb new file mode 100644 index 0000000..69f54d4 --- /dev/null +++ b/activerecord/test/cases/time_test.rb @@ -0,0 +1,21 @@ +require "cases/helper" +require 'models/topic' +require 'models/task' + +class TimeTest < ActiveRecord::TestCase + + def test_saves_time + topic = Topic.new + topic.bonus_time = "00:00:00" + topic.save! + + assert_equal "00:00:00", Topic.find(topic.id).bonus_time + end + + def test_assign_empty_time + topic = Topic.new + topic.bonus_time = '' + assert_nil topic.bonus_time + end + +end -- 1.7.0 From 3e6ad3f0880dee3d6b86f35c16986929e2a6e64c Mon Sep 17 00:00:00 2001 From: Jerome Stonebridge Date: Tue, 12 Oct 2010 07:28:17 -0700 Subject: [PATCH 2/2] test with time over 24 hours --- activerecord/test/cases/time_test.rb | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/time_test.rb b/activerecord/test/cases/time_test.rb index 69f54d4..418cf36 100644 --- a/activerecord/test/cases/time_test.rb +++ b/activerecord/test/cases/time_test.rb @@ -4,12 +4,20 @@ require 'models/task' class TimeTest < ActiveRecord::TestCase + def test_saves_time_over_24_hrs + topic = Topic.new + topic.bonus_time = "25:00:00" + topic.save! + + assert_equal "25:00:00", Topic.find(topic.id).bonus_time.strftime("%H:%M:%S") + end + def test_saves_time topic = Topic.new - topic.bonus_time = "00:00:00" + topic.bonus_time = "23:00:00" topic.save! - assert_equal "00:00:00", Topic.find(topic.id).bonus_time + assert_equal "23:00:00", Topic.find(topic.id).bonus_time.strftime("%H:%M:%S") end def test_assign_empty_time -- 1.7.0