require 'test/unit' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper' class DateHelperTest < Test::Unit::TestCase include ActionView::Helpers::DateHelper def test_distance_in_words from = Time.mktime(2004, 3, 6, 21, 41, 18) assert_equal "less than a minute", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 25)) assert_equal "5 minutes", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 46, 25)) assert_equal "about 1 hour", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 22, 47, 25)) assert_equal "about 3 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 0, 41)) assert_equal "about 4 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 1, 20)) assert_equal "2 days", distance_of_time_in_words(from, Time.mktime(2004, 3, 9, 15, 40)) end def test_select_day expected = %(\n" assert_equal expected, select_day(Time.mktime(2003, 8, 16)) assert_equal expected, select_day(16) end def test_select_day_with_blank expected = %(\n" assert_equal expected, select_day(Time.mktime(2003, 8, 16), :include_blank => true) assert_equal expected, select_day(16, :include_blank => true) end def test_select_month expected = %(\n" assert_equal expected, select_month(Time.mktime(2003, 8, 16)) assert_equal expected, select_month(8) end def test_select_month_with_numbers expected = %(\n" assert_equal expected, select_month(Time.mktime(2003, 8, 16), :use_month_numbers => true) assert_equal expected, select_month(8, :use_month_numbers => true) end def test_select_month_with_numbers_and_names expected = %(\n" assert_equal expected, select_month(Time.mktime(2003, 8, 16), :add_month_numbers => true) assert_equal expected, select_month(8, :add_month_numbers => true) end def test_select_year expected = %(\n" assert_equal expected, select_year(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005) assert_equal expected, select_year(2003, :start_year => 2003, :end_year => 2005) end def test_select_year_with_type_discarding expected = %(\n" assert_equal expected, select_year( Time.mktime(2003, 8, 16), :prefix => "date_year", :discard_type => true, :start_year => 2003, :end_year => 2005) assert_equal expected, select_year( 2003, :prefix => "date_year", :discard_type => true, :start_year => 2003, :end_year => 2005) end def test_select_hour expected = %(\n" assert_equal expected, select_hour(Time.mktime(2003, 8, 16, 8, 4, 18)) end def test_select_minute expected = %(\n" assert_equal expected, select_minute(Time.mktime(2003, 8, 16, 8, 4, 18)) end def test_select_second expected = %(\n" assert_equal expected, select_second(Time.mktime(2003, 8, 16, 8, 4, 18)) end def test_select_date expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date( Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]" ) end def test_select_date_with_no_start_year expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date( Time.mktime(Date.today.year, 8, 16), :end_year => Date.today.year+1, :prefix => "date[first]" ) end def test_select_date_with_no_end_year expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date( Time.mktime(2003, 8, 16), :start_year => 2003, :prefix => "date[first]" ) end def test_select_date_with_no_start_or_end_year expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date( Time.mktime(Date.today.year, 8, 16), :prefix => "date[first]" ) end def test_select_time_with_seconds expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_time(Time.mktime(2003, 8, 16, 8, 4, 18), :include_seconds => true) end def test_select_time_without_seconds expected = %(\n" expected << %(\n" assert_equal expected, select_time(Time.mktime(2003, 8, 16, 8, 4, 18)) assert_equal expected, select_time(Time.mktime(2003, 8, 16, 8, 4, 18), :include_seconds => false) end def test_date_select_with_zero_value expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date(0, :start_year => 2003, :end_year => 2005, :prefix => "date[first]") end def test_date_select_with_zero_value_and_no_start_year expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date(0, :end_year => Date.today.year+1, :prefix => "date[first]") end def test_date_select_with_zero_value_and_no_end_year expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date(0, :start_year => 2003, :prefix => "date[first]") end def test_date_select_with_zero_value_and_no_start_and_end_year expected = %(\n" expected << %(\n" expected << %(\n" assert_equal expected, select_date(0, :prefix => "date[first]") end end