ref: master
plugins/volunteers/test/unit/split_datetime_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
require File.dirname(__FILE__) + '/../../../../test/test_helper' class ModelWithDate def initialize @delivery = DateTime.now end attr_accessor :delivery extend SplitDatetime::SplitMethods split_datetime :delivery end class SplitDatetimeTest < ActiveSupport::TestCase def setup @m = ModelWithDate.new @m.delivery = (Time.mktime(2011) + 2.hours + 2.minutes + 2.seconds).to_datetime end should 'return get splitted times' do assert_equal @m.delivery_date, '2011-01-01' assert_equal @m.delivery_time, '02:02' end should 'return set splitted times by Date' do @m.delivery_date = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime assert_equal @m.delivery_date, '2011-03-05' assert_equal @m.delivery_time, '02:02' end should 'return set splitted times by Time' do @m.delivery_time = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime assert_equal @m.delivery_date, '2011-01-01' assert_equal @m.delivery_time, '03:03' end should 'return set splitted times by Date String' do @m.delivery_date = "2011-11-11" assert_equal @m.delivery_date, '2011-11-11' assert_equal @m.delivery_time, '02:02' end should 'return set splitted times by Time String' do @m.delivery_time = "15:43" assert_equal @m.delivery_date, '2011-01-01' assert_equal @m.delivery_time, '15:43' end end |